Skip to content

Commit 7e2088f

Browse files
committed
src,lib: allow running multiple per-context files
Create an `lib/internal/per_context/` directory that can host multiple files which we execute for each context. PR-URL: #26497 Reviewed-By: James M Snell <[email protected]>
1 parent 0752a18 commit 7e2088f

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

lib/internal/bootstrap/cache.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ const cannotBeRequired = [
2020

2121
'internal/test/binding',
2222

23-
'internal/bootstrap/context',
2423
'internal/bootstrap/primordials',
2524
'internal/bootstrap/loaders',
26-
'internal/bootstrap/node'
25+
'internal/bootstrap/node',
26+
27+
'internal/per_context/setup',
2728
];
2829

2930
// Skip modules that cannot be required when they are not
File renamed without changes.

node.gyp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
'node_lib_target_name%': 'node_lib',
2727
'node_intermediate_lib_type%': 'static_library',
2828
'library_files': [
29-
'lib/internal/bootstrap/context.js',
3029
'lib/internal/bootstrap/primordials.js',
3130
'lib/internal/bootstrap/cache.js',
3231
'lib/internal/bootstrap/loaders.js',
3332
'lib/internal/bootstrap/node.js',
3433
'lib/internal/bootstrap/pre_execution.js',
34+
'lib/internal/per_context/setup.js',
3535
'lib/async_hooks.js',
3636
'lib/assert.js',
3737
'lib/buffer.js',

src/api/environment.cc

+25-17
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,33 @@ Local<Context> NewContext(Isolate* isolate,
289289
True(isolate));
290290

291291
{
292-
// Run lib/internal/bootstrap/context.js
292+
// Run per-context JS files.
293293
Context::Scope context_scope(context);
294294

295-
std::vector<Local<String>> parameters = {
296-
FIXED_ONE_BYTE_STRING(isolate, "global")};
297-
Local<Value> arguments[] = {context->Global()};
298-
MaybeLocal<Function> maybe_fn =
299-
per_process::native_module_loader.LookupAndCompile(
300-
context, "internal/bootstrap/context", &parameters, nullptr);
301-
if (maybe_fn.IsEmpty()) {
302-
return Local<Context>();
303-
}
304-
Local<Function> fn = maybe_fn.ToLocalChecked();
305-
MaybeLocal<Value> result =
306-
fn->Call(context, Undefined(isolate), arraysize(arguments), arguments);
307-
// Execution failed during context creation.
308-
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
309-
if (result.IsEmpty()) {
310-
return Local<Context>();
295+
static const char* context_files[] = {
296+
"internal/per_context/setup",
297+
nullptr
298+
};
299+
300+
for (const char** module = context_files; *module != nullptr; module++) {
301+
std::vector<Local<String>> parameters = {
302+
FIXED_ONE_BYTE_STRING(isolate, "global")};
303+
Local<Value> arguments[] = {context->Global()};
304+
MaybeLocal<Function> maybe_fn =
305+
per_process::native_module_loader.LookupAndCompile(
306+
context, *module, &parameters, nullptr);
307+
if (maybe_fn.IsEmpty()) {
308+
return Local<Context>();
309+
}
310+
Local<Function> fn = maybe_fn.ToLocalChecked();
311+
MaybeLocal<Value> result =
312+
fn->Call(context, Undefined(isolate),
313+
arraysize(arguments), arguments);
314+
// Execution failed during context creation.
315+
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
316+
if (result.IsEmpty()) {
317+
return Local<Context>();
318+
}
311319
}
312320
}
313321

0 commit comments

Comments
 (0)