Skip to content

Commit 57d35f7

Browse files
committed
src: update std::vector<v8::Local<T>> to use v8::LocalVector<T>
A follow up of nodejs#57578 to replace all replace all std::vector<v8::Local<T>> to use v8::LocalVector<T>
1 parent 4868ca4 commit 57d35f7

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

src/node_contextify.cc

+15-14
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ Maybe<void> StoreCodeCacheResult(
11661166
MaybeLocal<Function> CompileFunction(Local<Context> context,
11671167
Local<String> filename,
11681168
Local<String> content,
1169-
std::vector<Local<String>>* parameters) {
1169+
LocalVector<String>* parameters) {
11701170
ScriptOrigin script_origin(filename, 0, 0, true);
11711171
ScriptCompiler::Source script_source(content, script_origin);
11721172

@@ -1483,7 +1483,7 @@ void ContextifyContext::CompileFunction(
14831483
Context::Scope scope(parsing_context);
14841484

14851485
// Read context extensions from buffer
1486-
std::vector<Local<Object>> context_extensions;
1486+
LocalVector<Object> context_extensions(isolate);
14871487
if (!context_extensions_buf.IsEmpty()) {
14881488
for (uint32_t n = 0; n < context_extensions_buf->Length(); n++) {
14891489
Local<Value> val;
@@ -1494,7 +1494,7 @@ void ContextifyContext::CompileFunction(
14941494
}
14951495

14961496
// Read params from params buffer
1497-
std::vector<Local<String>> params;
1497+
LocalVector<String> params(isolate);
14981498
if (!params_buf.IsEmpty()) {
14991499
for (uint32_t n = 0; n < params_buf->Length(); n++) {
15001500
Local<Value> val;
@@ -1526,22 +1526,23 @@ void ContextifyContext::CompileFunction(
15261526
args.GetReturnValue().Set(result);
15271527
}
15281528

1529-
static std::vector<Local<String>> GetCJSParameters(IsolateData* data) {
1530-
return {
1531-
data->exports_string(),
1532-
data->require_string(),
1533-
data->module_string(),
1534-
data->__filename_string(),
1535-
data->__dirname_string(),
1536-
};
1529+
static LocalVector<String> GetCJSParameters(IsolateData* data) {
1530+
LocalVector<String> result(data->isolate(), {
1531+
data->exports_string(),
1532+
data->require_string(),
1533+
data->module_string(),
1534+
data->__filename_string(),
1535+
data->__dirname_string(),
1536+
});
1537+
return result;
15371538
}
15381539

15391540
Local<Object> ContextifyContext::CompileFunctionAndCacheResult(
15401541
Environment* env,
15411542
Local<Context> parsing_context,
15421543
ScriptCompiler::Source* source,
1543-
std::vector<Local<String>> params,
1544-
std::vector<Local<Object>> context_extensions,
1544+
LocalVector<String> params,
1545+
LocalVector<Object> context_extensions,
15451546
ScriptCompiler::CompileOptions options,
15461547
bool produce_cached_data,
15471548
Local<Symbol> id_symbol,
@@ -1677,7 +1678,7 @@ static MaybeLocal<Function> CompileFunctionForCJSLoader(
16771678
options = ScriptCompiler::kConsumeCodeCache;
16781679
}
16791680

1680-
std::vector<Local<String>> params;
1681+
LocalVector<String> params(isolate);
16811682
if (is_cjs_scope) {
16821683
params = GetCJSParameters(env->isolate_data());
16831684
}

src/node_contextify.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ class ContextifyContext final : CPPGC_MIXIN(ContextifyContext) {
149149
Environment* env,
150150
v8::Local<v8::Context> parsing_context,
151151
v8::ScriptCompiler::Source* source,
152-
std::vector<v8::Local<v8::String>> params,
153-
std::vector<v8::Local<v8::Object>> context_extensions,
152+
v8::LocalVector<v8::String> params,
153+
v8::LocalVector<v8::Object> context_extensions,
154154
v8::ScriptCompiler::CompileOptions options,
155155
bool produce_cached_data,
156156
v8::Local<v8::Symbol> id_symbol,
@@ -244,7 +244,7 @@ v8::MaybeLocal<v8::Function> CompileFunction(
244244
v8::Local<v8::Context> context,
245245
v8::Local<v8::String> filename,
246246
v8::Local<v8::String> content,
247-
std::vector<v8::Local<v8::String>>* parameters);
247+
v8::LocalVector<v8::String>* parameters);
248248

249249
} // namespace contextify
250250
} // namespace node

src/node_sea.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ using v8::FunctionCallbackInfo;
3636
using v8::HandleScope;
3737
using v8::Isolate;
3838
using v8::Local;
39+
using v8::LocalVector;
3940
using v8::MaybeLocal;
4041
using v8::NewStringType;
4142
using v8::Object;
@@ -450,13 +451,13 @@ std::optional<std::string> GenerateCodeCache(std::string_view main_path,
450451
return std::nullopt;
451452
}
452453

453-
std::vector<Local<String>> parameters = {
454+
LocalVector<String> parameters(isolate, {
454455
FIXED_ONE_BYTE_STRING(isolate, "exports"),
455456
FIXED_ONE_BYTE_STRING(isolate, "require"),
456457
FIXED_ONE_BYTE_STRING(isolate, "module"),
457458
FIXED_ONE_BYTE_STRING(isolate, "__filename"),
458459
FIXED_ONE_BYTE_STRING(isolate, "__dirname"),
459-
};
460+
});
460461

461462
// TODO(RaisinTen): Using the V8 code cache prevents us from using `import()`
462463
// in the SEA code. Support it.

src/node_snapshotable.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ using v8::FunctionCallbackInfo;
4141
using v8::HandleScope;
4242
using v8::Isolate;
4343
using v8::Local;
44+
using v8::LocalVector;
4445
using v8::Object;
4546
using v8::ObjectTemplate;
4647
using v8::SnapshotCreator;
@@ -1479,11 +1480,11 @@ void CompileSerializeMain(const FunctionCallbackInfo<Value>& args) {
14791480
Local<Context> context = isolate->GetCurrentContext();
14801481
// TODO(joyeecheung): do we need all of these? Maybe we would want a less
14811482
// internal version of them.
1482-
std::vector<Local<String>> parameters = {
1483+
LocalVector<String> parameters(isolate, {
14831484
FIXED_ONE_BYTE_STRING(isolate, "require"),
14841485
FIXED_ONE_BYTE_STRING(isolate, "__filename"),
14851486
FIXED_ONE_BYTE_STRING(isolate, "__dirname"),
1486-
};
1487+
});
14871488
Local<Function> fn;
14881489
if (contextify::CompileFunction(context, filename, source, &parameters)
14891490
.ToLocal(&fn)) {

0 commit comments

Comments
 (0)