lib: create primordials in every context
This allows us to use primordials in other per-context scripts. PR-URL: https://github.com/nodejs/node/pull/27171 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
dfd7e99425
commit
3da36d0e94
2
node.gyp
2
node.gyp
@ -26,11 +26,11 @@
|
|||||||
'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/primordials.js',
|
|
||||||
'lib/internal/bootstrap/environment.js',
|
'lib/internal/bootstrap/environment.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/primordials.js',
|
||||||
'lib/internal/per_context/setup.js',
|
'lib/internal/per_context/setup.js',
|
||||||
'lib/internal/per_context/domexception.js',
|
'lib/internal/per_context/domexception.js',
|
||||||
'lib/async_hooks.js',
|
'lib/async_hooks.js',
|
||||||
|
@ -23,6 +23,7 @@ using v8::Local;
|
|||||||
using v8::MaybeLocal;
|
using v8::MaybeLocal;
|
||||||
using v8::Message;
|
using v8::Message;
|
||||||
using v8::MicrotasksPolicy;
|
using v8::MicrotasksPolicy;
|
||||||
|
using v8::Null;
|
||||||
using v8::Object;
|
using v8::Object;
|
||||||
using v8::ObjectTemplate;
|
using v8::ObjectTemplate;
|
||||||
using v8::Private;
|
using v8::Private;
|
||||||
@ -332,24 +333,29 @@ Local<Context> NewContext(Isolate* isolate,
|
|||||||
// Run per-context JS files.
|
// Run per-context JS files.
|
||||||
Context::Scope context_scope(context);
|
Context::Scope context_scope(context);
|
||||||
Local<Object> exports;
|
Local<Object> exports;
|
||||||
if (!GetPerContextExports(context).ToLocal(&exports))
|
|
||||||
return Local<Context>();
|
|
||||||
|
|
||||||
|
Local<String> primordials_string =
|
||||||
|
FIXED_ONE_BYTE_STRING(isolate, "primordials");
|
||||||
Local<String> global_string = FIXED_ONE_BYTE_STRING(isolate, "global");
|
Local<String> global_string = FIXED_ONE_BYTE_STRING(isolate, "global");
|
||||||
Local<String> exports_string = FIXED_ONE_BYTE_STRING(isolate, "exports");
|
Local<String> exports_string = FIXED_ONE_BYTE_STRING(isolate, "exports");
|
||||||
|
|
||||||
static const char* context_files[] = {
|
// Create primordials first and make it available to per-context scripts.
|
||||||
|
Local<Object> primordials = Object::New(isolate);
|
||||||
|
if (!primordials->SetPrototype(context, Null(isolate)).FromJust() ||
|
||||||
|
!GetPerContextExports(context).ToLocal(&exports) ||
|
||||||
|
!exports->Set(context, primordials_string, primordials).FromJust()) {
|
||||||
|
return Local<Context>();
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char* context_files[] = {"internal/per_context/primordials",
|
||||||
"internal/per_context/setup",
|
"internal/per_context/setup",
|
||||||
"internal/per_context/domexception",
|
"internal/per_context/domexception",
|
||||||
nullptr
|
nullptr};
|
||||||
};
|
|
||||||
|
|
||||||
for (const char** module = context_files; *module != nullptr; module++) {
|
for (const char** module = context_files; *module != nullptr; module++) {
|
||||||
std::vector<Local<String>> parameters = {
|
std::vector<Local<String>> parameters = {
|
||||||
global_string,
|
global_string, exports_string, primordials_string};
|
||||||
exports_string
|
Local<Value> arguments[] = {context->Global(), exports, primordials};
|
||||||
};
|
|
||||||
Local<Value> arguments[] = {context->Global(), exports};
|
|
||||||
MaybeLocal<Function> maybe_fn =
|
MaybeLocal<Function> maybe_fn =
|
||||||
native_module::NativeModuleEnv::LookupAndCompile(
|
native_module::NativeModuleEnv::LookupAndCompile(
|
||||||
context, *module, ¶meters, nullptr);
|
context, *module, ¶meters, nullptr);
|
||||||
|
26
src/node.cc
26
src/node.cc
@ -268,14 +268,16 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
|
|||||||
global->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global)
|
global->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global)
|
||||||
.Check();
|
.Check();
|
||||||
|
|
||||||
// Store primordials
|
// Store primordials setup by the per-context script in the environment.
|
||||||
env->set_primordials(Object::New(isolate));
|
Local<Object> per_context_bindings;
|
||||||
std::vector<Local<String>> primordials_params = {
|
Local<Value> primordials;
|
||||||
env->primordials_string()
|
if (!GetPerContextExports(context).ToLocal(&per_context_bindings) ||
|
||||||
};
|
!per_context_bindings->Get(context, env->primordials_string())
|
||||||
std::vector<Local<Value>> primordials_args = {
|
.ToLocal(&primordials) ||
|
||||||
env->primordials()
|
!primordials->IsObject()) {
|
||||||
};
|
return MaybeLocal<Value>();
|
||||||
|
}
|
||||||
|
env->set_primordials(primordials.As<Object>());
|
||||||
|
|
||||||
#if HAVE_INSPECTOR
|
#if HAVE_INSPECTOR
|
||||||
if (env->options()->debug_options().break_node_first_line) {
|
if (env->options()->debug_options().break_node_first_line) {
|
||||||
@ -283,14 +285,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) {
|
|||||||
"Break at bootstrap");
|
"Break at bootstrap");
|
||||||
}
|
}
|
||||||
#endif // HAVE_INSPECTOR
|
#endif // HAVE_INSPECTOR
|
||||||
MaybeLocal<Value> primordials_ret =
|
|
||||||
ExecuteBootstrapper(env,
|
|
||||||
"internal/bootstrap/primordials",
|
|
||||||
&primordials_params,
|
|
||||||
&primordials_args);
|
|
||||||
if (primordials_ret.IsEmpty()) {
|
|
||||||
return MaybeLocal<Value>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create binding loaders
|
// Create binding loaders
|
||||||
std::vector<Local<String>> loaders_params = {
|
std::vector<Local<String>> loaders_params = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user