diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-12-31 01:03:16 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-01-02 14:46:14 +0100 |
commit | 0ff1eb83d9c3416f9619c1ce2c3a7327efd9bee4 (patch) | |
tree | 088d1992c46b8074a1137b6643f9216d26dceb80 /src/node_crypto.cc | |
parent | 112ee2ab071da24390515b3a91588c1590872498 (diff) | |
download | android-node-v8-0ff1eb83d9c3416f9619c1ce2c3a7327efd9bee4.tar.gz android-node-v8-0ff1eb83d9c3416f9619c1ce2c3a7327efd9bee4.tar.bz2 android-node-v8-0ff1eb83d9c3416f9619c1ce2c3a7327efd9bee4.zip |
src: simplify JS Array creation
Use `ToV8Value()` where appropriate to reduce duplication
and avoid extra `Array::Set()` calls.
PR-URL: https://github.com/nodejs/node/pull/25288
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/node_crypto.cc')
-rw-r--r-- | src/node_crypto.cc | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/src/node_crypto.cc b/src/node_crypto.cc index c18432b620..ab35568888 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -250,22 +250,12 @@ struct CryptoErrorVector : public std::vector<std::string> { CHECK(!exception_v.IsEmpty()); if (!empty()) { - Local<Array> array = Array::New(env->isolate(), size()); - CHECK(!array.IsEmpty()); - - for (const std::string& string : *this) { - const size_t index = &string - &front(); - Local<String> value = - String::NewFromUtf8(env->isolate(), string.data(), - NewStringType::kNormal, string.size()) - .ToLocalChecked(); - array->Set(env->context(), index, value).FromJust(); - } - CHECK(exception_v->IsObject()); Local<Object> exception = exception_v.As<Object>(); exception->Set(env->context(), - env->openssl_error_stack(), array).FromJust(); + env->openssl_error_stack(), + ToV8Value(env->context(), *this).ToLocalChecked()) + .FromJust(); } return exception_v; |