src: create Environment properties in Environment::CreateProperties()
Move creation of `env->as_callback_data()`, `env->primordials()` and `env->process()` into `Environment::CreateProperties()` and call it in the `Environment` constructor - this can be replaced with deserialization when we snapshot the per-environment properties after the instantiation of `Environment`. PR-URL: https://github.com/nodejs/node/pull/27539 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
bda7da34c6
commit
a1a690e07c
40
src/env.cc
40
src/env.cc
@ -235,6 +235,32 @@ uint64_t Environment::AllocateThreadId() {
|
|||||||
return next_thread_id++;
|
return next_thread_id++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Environment::CreateProperties() {
|
||||||
|
HandleScope handle_scope(isolate_);
|
||||||
|
Local<Context> ctx = context();
|
||||||
|
Local<FunctionTemplate> templ = FunctionTemplate::New(isolate());
|
||||||
|
templ->InstanceTemplate()->SetInternalFieldCount(1);
|
||||||
|
Local<Object> obj = templ->GetFunction(ctx)
|
||||||
|
.ToLocalChecked()
|
||||||
|
->NewInstance(ctx)
|
||||||
|
.ToLocalChecked();
|
||||||
|
obj->SetAlignedPointerInInternalField(0, this);
|
||||||
|
set_as_callback_data(obj);
|
||||||
|
set_as_callback_data_template(templ);
|
||||||
|
|
||||||
|
// Store primordials setup by the per-context script in the environment.
|
||||||
|
Local<Object> per_context_bindings =
|
||||||
|
GetPerContextExports(ctx).ToLocalChecked();
|
||||||
|
Local<Value> primordials =
|
||||||
|
per_context_bindings->Get(ctx, primordials_string()).ToLocalChecked();
|
||||||
|
CHECK(primordials->IsObject());
|
||||||
|
set_primordials(primordials.As<Object>());
|
||||||
|
|
||||||
|
Local<Object> process_object =
|
||||||
|
node::CreateProcessObject(this).FromMaybe(Local<Object>());
|
||||||
|
set_process_object(process_object);
|
||||||
|
}
|
||||||
|
|
||||||
Environment::Environment(IsolateData* isolate_data,
|
Environment::Environment(IsolateData* isolate_data,
|
||||||
Local<Context> context,
|
Local<Context> context,
|
||||||
const std::vector<std::string>& args,
|
const std::vector<std::string>& args,
|
||||||
@ -258,16 +284,6 @@ Environment::Environment(IsolateData* isolate_data,
|
|||||||
// We'll be creating new objects so make sure we've entered the context.
|
// We'll be creating new objects so make sure we've entered the context.
|
||||||
HandleScope handle_scope(isolate());
|
HandleScope handle_scope(isolate());
|
||||||
Context::Scope context_scope(context);
|
Context::Scope context_scope(context);
|
||||||
{
|
|
||||||
Local<FunctionTemplate> templ = FunctionTemplate::New(isolate());
|
|
||||||
templ->InstanceTemplate()->SetInternalFieldCount(1);
|
|
||||||
Local<Object> obj =
|
|
||||||
templ->GetFunction(context).ToLocalChecked()->NewInstance(
|
|
||||||
context).ToLocalChecked();
|
|
||||||
obj->SetAlignedPointerInInternalField(0, this);
|
|
||||||
set_as_callback_data(obj);
|
|
||||||
set_as_callback_data_template(templ);
|
|
||||||
}
|
|
||||||
|
|
||||||
set_env_vars(per_process::system_environment);
|
set_env_vars(per_process::system_environment);
|
||||||
|
|
||||||
@ -339,7 +355,9 @@ Environment::Environment(IsolateData* isolate_data,
|
|||||||
async_hooks_.no_force_checks();
|
async_hooks_.no_force_checks();
|
||||||
}
|
}
|
||||||
|
|
||||||
set_process_object(node::CreateProcessObject(this).ToLocalChecked());
|
// TODO(joyeecheung): deserialize when the snapshot covers the environment
|
||||||
|
// properties.
|
||||||
|
CreateProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
CompileFnEntry::CompileFnEntry(Environment* env, uint32_t id)
|
CompileFnEntry::CompileFnEntry(Environment* env, uint32_t id)
|
||||||
|
@ -796,6 +796,8 @@ class Environment : public MemoryRetainer {
|
|||||||
bool IsRootNode() const override { return true; }
|
bool IsRootNode() const override { return true; }
|
||||||
void MemoryInfo(MemoryTracker* tracker) const override;
|
void MemoryInfo(MemoryTracker* tracker) const override;
|
||||||
|
|
||||||
|
void CreateProperties();
|
||||||
|
|
||||||
inline size_t async_callback_scope_depth() const;
|
inline size_t async_callback_scope_depth() const;
|
||||||
inline void PushAsyncCallbackScope();
|
inline void PushAsyncCallbackScope();
|
||||||
inline void PopAsyncCallbackScope();
|
inline void PopAsyncCallbackScope();
|
||||||
|
11
src/node.cc
11
src/node.cc
@ -255,17 +255,6 @@ 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 setup by the per-context script in the environment.
|
|
||||||
Local<Object> per_context_bindings;
|
|
||||||
Local<Value> primordials;
|
|
||||||
if (!GetPerContextExports(context).ToLocal(&per_context_bindings) ||
|
|
||||||
!per_context_bindings->Get(context, env->primordials_string())
|
|
||||||
.ToLocal(&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) {
|
||||||
env->inspector_agent()->PauseOnNextJavascriptStatement(
|
env->inspector_agent()->PauseOnNextJavascriptStatement(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user