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: https://github.com/nodejs/node/pull/26497 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
0752a18b88
commit
7e2088f773
@ -20,10 +20,11 @@ const cannotBeRequired = [
|
|||||||
|
|
||||||
'internal/test/binding',
|
'internal/test/binding',
|
||||||
|
|
||||||
'internal/bootstrap/context',
|
|
||||||
'internal/bootstrap/primordials',
|
'internal/bootstrap/primordials',
|
||||||
'internal/bootstrap/loaders',
|
'internal/bootstrap/loaders',
|
||||||
'internal/bootstrap/node'
|
'internal/bootstrap/node',
|
||||||
|
|
||||||
|
'internal/per_context/setup',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Skip modules that cannot be required when they are not
|
// Skip modules that cannot be required when they are not
|
||||||
|
2
node.gyp
2
node.gyp
@ -26,12 +26,12 @@
|
|||||||
'node_lib_target_name%': 'node_lib',
|
'node_lib_target_name%': 'node_lib',
|
||||||
'node_intermediate_lib_type%': 'static_library',
|
'node_intermediate_lib_type%': 'static_library',
|
||||||
'library_files': [
|
'library_files': [
|
||||||
'lib/internal/bootstrap/context.js',
|
|
||||||
'lib/internal/bootstrap/primordials.js',
|
'lib/internal/bootstrap/primordials.js',
|
||||||
'lib/internal/bootstrap/cache.js',
|
'lib/internal/bootstrap/cache.js',
|
||||||
'lib/internal/bootstrap/loaders.js',
|
'lib/internal/bootstrap/loaders.js',
|
||||||
'lib/internal/bootstrap/node.js',
|
'lib/internal/bootstrap/node.js',
|
||||||
'lib/internal/bootstrap/pre_execution.js',
|
'lib/internal/bootstrap/pre_execution.js',
|
||||||
|
'lib/internal/per_context/setup.js',
|
||||||
'lib/async_hooks.js',
|
'lib/async_hooks.js',
|
||||||
'lib/assert.js',
|
'lib/assert.js',
|
||||||
'lib/buffer.js',
|
'lib/buffer.js',
|
||||||
|
@ -289,25 +289,33 @@ Local<Context> NewContext(Isolate* isolate,
|
|||||||
True(isolate));
|
True(isolate));
|
||||||
|
|
||||||
{
|
{
|
||||||
// Run lib/internal/bootstrap/context.js
|
// Run per-context JS files.
|
||||||
Context::Scope context_scope(context);
|
Context::Scope context_scope(context);
|
||||||
|
|
||||||
std::vector<Local<String>> parameters = {
|
static const char* context_files[] = {
|
||||||
FIXED_ONE_BYTE_STRING(isolate, "global")};
|
"internal/per_context/setup",
|
||||||
Local<Value> arguments[] = {context->Global()};
|
nullptr
|
||||||
MaybeLocal<Function> maybe_fn =
|
};
|
||||||
per_process::native_module_loader.LookupAndCompile(
|
|
||||||
context, "internal/bootstrap/context", ¶meters, nullptr);
|
for (const char** module = context_files; *module != nullptr; module++) {
|
||||||
if (maybe_fn.IsEmpty()) {
|
std::vector<Local<String>> parameters = {
|
||||||
return Local<Context>();
|
FIXED_ONE_BYTE_STRING(isolate, "global")};
|
||||||
}
|
Local<Value> arguments[] = {context->Global()};
|
||||||
Local<Function> fn = maybe_fn.ToLocalChecked();
|
MaybeLocal<Function> maybe_fn =
|
||||||
MaybeLocal<Value> result =
|
per_process::native_module_loader.LookupAndCompile(
|
||||||
fn->Call(context, Undefined(isolate), arraysize(arguments), arguments);
|
context, *module, ¶meters, nullptr);
|
||||||
// Execution failed during context creation.
|
if (maybe_fn.IsEmpty()) {
|
||||||
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
|
return Local<Context>();
|
||||||
if (result.IsEmpty()) {
|
}
|
||||||
return Local<Context>();
|
Local<Function> fn = maybe_fn.ToLocalChecked();
|
||||||
|
MaybeLocal<Value> result =
|
||||||
|
fn->Call(context, Undefined(isolate),
|
||||||
|
arraysize(arguments), arguments);
|
||||||
|
// Execution failed during context creation.
|
||||||
|
// TODO(joyeecheung): deprecate this signature and return a MaybeLocal.
|
||||||
|
if (result.IsEmpty()) {
|
||||||
|
return Local<Context>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user