src: use v8::LocalVector consistently with other minor cleanups · nodejs/node@29f5d70 · GitHub
Skip to content

Commit 29f5d70

Browse files
jasnelladuh95
authored andcommitted
src: use v8::LocalVector consistently with other minor cleanups
V8 introduced `v8::LocalVector` somewhat recently as an alternative to using `std::vector<v8::Local<T>>` to help ensure that Local handles are handled correctly. This updates most (but not all) of our uses of `std::vector<v8::Local<T>>` to use `v8::LocalVector<T>` with a few other minor cleanups encountered along the way. PR-URL: #56417 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 03df76c commit 29f5d70

19 files changed

Lines changed: 122 additions & 99 deletions

src/cares_wrap.cc

Lines changed: 4 additions & 2 deletions

src/crypto/crypto_cipher.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ using v8::HandleScope;
2020
using v8::Int32;
2121
using v8::Isolate;
2222
using v8::Local;
23+
using v8::LocalVector;
2324
using v8::Object;
2425
using v8::Uint32;
2526
using v8::Value;
@@ -222,7 +223,7 @@ void CipherBase::GetSSLCiphers(const FunctionCallbackInfo<Value>& args) {
222223
};
223224

224225
const int n = sk_SSL_CIPHER_num(ciphers);
225-
std::vector<Local<Value>> arr(n + arraysize(TLS13_CIPHERS));
226+
LocalVector<Value> arr(env->isolate(), n + arraysize(TLS13_CIPHERS));
226227

227228
for (int i = 0; i < n; ++i) {
228229
const SSL_CIPHER* cipher = sk_SSL_CIPHER_value(ciphers, i);

src/crypto/crypto_ec.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using v8::Int32;
2828
using v8::Isolate;
2929
using v8::JustVoid;
3030
using v8::Local;
31+
using v8::LocalVector;
3132
using v8::Maybe;
3233
using v8::MaybeLocal;
3334
using v8::Nothing;
@@ -95,7 +96,7 @@ void ECDH::GetCurves(const FunctionCallbackInfo<Value>& args) {
9596
std::vector<EC_builtin_curve> curves(num_curves);
9697
CHECK_EQ(EC_get_builtin_curves(curves.data(), num_curves), num_curves);
9798

98-
std::vector<Local<Value>> arr(num_curves);
99+
LocalVector<Value> arr(env->isolate(), num_curves);
99100
std::transform(curves.begin(), curves.end(), arr.begin(), [env](auto& curve) {
100101
return OneByteString(env->isolate(), OBJ_nid2sn(curve.nid));
101102
});

src/crypto/crypto_hash.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using v8::Isolate;
1919
using v8::Just;
2020
using v8::JustVoid;
2121
using v8::Local;
22+
using v8::LocalVector;
2223
using v8::Maybe;
2324
using v8::MaybeLocal;
2425
using v8::Name;
@@ -144,9 +145,9 @@ void Hash::GetCachedAliases(const FunctionCallbackInfo<Value>& args) {
144145
Isolate* isolate = args.GetIsolate();
145146
Local<Context> context = args.GetIsolate()->GetCurrentContext();
146147
Environment* env = Environment::GetCurrent(context);
147-
std::vector<Local<Name>> names;
148-
std::vector<Local<Value>> values;
149148
size_t size = env->alias_to_md_id_map.size();
149+
LocalVector<Name> names(isolate);
150+
LocalVector<Value> values(isolate);
150151
#if OPENSSL_VERSION_MAJOR >= 3
151152
names.reserve(size);
152153
values.reserve(size);

src/crypto/crypto_util.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using v8::HandleScope;
3636
using v8::Isolate;
3737
using v8::JustVoid;
3838
using v8::Local;
39+
using v8::LocalVector;
3940
using v8::Maybe;
4041
using v8::MaybeLocal;
4142
using v8::NewStringType;
@@ -236,7 +237,7 @@ MaybeLocal<Value> cryptoErrorListToException(
236237
if (errors.size() > 1) {
237238
CHECK(exception->IsObject());
238239
Local<Object> exception_obj = exception.As<Object>();
239-
std::vector<Local<Value>> stack(errors.size() - 1);
240+
LocalVector<Value> stack(env->isolate(), errors.size() - 1);
240241

241242
// Iterate over all but the last error in the list.
242243
auto current = errors.begin();
@@ -252,7 +253,7 @@ MaybeLocal<Value> cryptoErrorListToException(
252253
}
253254

254255
Local<v8::Array> stackArray =
255-
v8::Array::New(env->isolate(), &stack[0], stack.size());
256+
v8::Array::New(env->isolate(), stack.data(), stack.size());
256257

257258
if (!exception_obj
258259
->Set(env->context(), env->openssl_error_stack(), stackArray)

src/internal_only_v8.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ using v8::FunctionCallbackInfo;
1010
using v8::Global;
1111
using v8::Isolate;
1212
using v8::Local;
13+
using v8::LocalVector;
1314
using v8::Object;
1415
using v8::Value;
1516

@@ -56,7 +57,7 @@ void QueryObjects(const FunctionCallbackInfo<Value>& args) {
5657
PrototypeChainHas prototype_chain_has(context, proto.As<Object>());
5758
std::vector<Global<Object>> out;
5859
isolate->GetHeapProfiler()->QueryObjects(context, &prototype_chain_has, &out);
59-
std::vector<Local<Value>> result;
60+
LocalVector<Value> result(isolate);
6061
result.reserve(out.size());
6162
for (size_t i = 0; i < out.size(); ++i) {
6263
result.push_back(out[i].Get(isolate));

src/module_wrap.cc

Lines changed: 47 additions & 38 deletions

0 commit comments

Comments
 (0)