From aab4adb34ecf8cddf009b34aba64fe055759984e Mon Sep 17 00:00:00 2001 From: Aditi <62544124+Aditi-1400@users.noreply.github.com> Date: Wed, 16 Apr 2025 22:28:44 +0530 Subject: [PATCH] src: update std::vector> to use v8::LocalVector According to V8's public API documentation, local handles (i.e., objects of type v8::Local) "should never be allocated on the heap". This replaces the usage of heap-allocated data structures containing instances of `v8::Local`, specifically the `std::vector>` with recently introduced `v8::LocalVector`. This is first of the series of commits to replace all `std::vector>` to use `v8::LocalVector`. PR-URL: https://github.com/nodejs/node/pull/57578 Reviewed-By: Chengzhong Wu Reviewed-By: Yagiz Nizipli Reviewed-By: Darshan Sen Reviewed-By: James M Snell --- src/node_builtins.cc | 7 ++++--- src/node_builtins.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/node_builtins.cc b/src/node_builtins.cc index 05b91aa7f9c..104c4ef0769 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -19,6 +19,7 @@ using v8::FunctionCallbackInfo; using v8::IntegrityLevel; using v8::Isolate; using v8::Local; +using v8::LocalVector; using v8::MaybeLocal; using v8::Name; using v8::NewStringType; @@ -262,7 +263,7 @@ void BuiltinLoader::AddExternalizedBuiltin(const char* id, MaybeLocal BuiltinLoader::LookupAndCompileInternal( Local context, const char* id, - std::vector>* parameters, + LocalVector* parameters, Realm* optional_realm) { Isolate* isolate = context->GetIsolate(); EscapableHandleScope scope(isolate); @@ -386,8 +387,8 @@ void BuiltinLoader::SaveCodeCache(const char* id, Local fun) { MaybeLocal BuiltinLoader::LookupAndCompile(Local context, const char* id, Realm* optional_realm) { - std::vector> parameters; Isolate* isolate = context->GetIsolate(); + LocalVector parameters(isolate); // Detects parameters of the scripts based on module ids. // internal/bootstrap/realm: process, getLinkedBinding, // getInternalBinding, primordials @@ -502,7 +503,7 @@ MaybeLocal BuiltinLoader::CompileAndCall(Local context, MaybeLocal BuiltinLoader::LookupAndCompile( Local context, const char* id, - std::vector>* parameters, + LocalVector* parameters, Realm* optional_realm) { return LookupAndCompileInternal(context, id, parameters, optional_realm); } diff --git a/src/node_builtins.h b/src/node_builtins.h index 196934b706b..83ddad21272 100644 --- a/src/node_builtins.h +++ b/src/node_builtins.h @@ -101,7 +101,7 @@ class NODE_EXTERN_PRIVATE BuiltinLoader { v8::MaybeLocal LookupAndCompile( v8::Local context, const char* id, - std::vector>* parameters, + v8::LocalVector* parameters, Realm* optional_realm); v8::MaybeLocal CompileAndCall(v8::Local context, @@ -159,7 +159,7 @@ class NODE_EXTERN_PRIVATE BuiltinLoader { v8::MaybeLocal LookupAndCompileInternal( v8::Local context, const char* id, - std::vector>* parameters, + v8::LocalVector* parameters, Realm* optional_realm); void SaveCodeCache(const char* id, v8::Local fn);