diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2021-10-07 07:03:10 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2021-10-16 05:03:50 +0300 |
commit | 38aa7cc7c7ea644c8d60859880f69a98f7159ffa (patch) | |
tree | 8c3a575b5dc10afc3e5833bdae39ccfa10fd1abe /src/node_options.cc | |
parent | 6baea14506a4ebd2f29bc9bcd5fb3beccba5a301 (diff) |
src: get embedder options on-demand
Only query embedder options when they are needed so that the bootstrap
remains as stateless as possible so that the bootstrap snapshot is
controlled solely by configure options, and subsequent runtime changes
should be done in pre-execution.
PR-URL: https://github.com/nodejs/node/pull/40357
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com>
Diffstat (limited to 'src/node_options.cc')
-rw-r--r-- | src/node_options.cc | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/src/node_options.cc b/src/node_options.cc index c778de58dc8..00bdc6688a4 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -920,7 +920,7 @@ std::string GetBashCompletion() { // Return a map containing all the options and their metadata as well // as the aliases -void GetOptions(const FunctionCallbackInfo<Value>& args) { +void GetCLIOptions(const FunctionCallbackInfo<Value>& args) { Mutex::ScopedLock lock(per_process::cli_options_mutex); Environment* env = Environment::GetCurrent(args); if (!env->has_run_bootstrapping_code()) { @@ -1061,13 +1061,38 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) { args.GetReturnValue().Set(ret); } +void GetEmbedderOptions(const FunctionCallbackInfo<Value>& args) { + Environment* env = Environment::GetCurrent(args); + if (!env->has_run_bootstrapping_code()) { + // No code because this is an assertion. + return env->ThrowError( + "Should not query options before bootstrapping is done"); + } + Isolate* isolate = args.GetIsolate(); + Local<Context> context = env->context(); + Local<Object> ret = Object::New(isolate); + + if (ret->Set(context, + FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), + Boolean::New(isolate, env->should_not_register_esm_loader())) + .IsNothing()) return; + + if (ret->Set(context, + FIXED_ONE_BYTE_STRING(env->isolate(), "noGlobalSearchPaths"), + Boolean::New(isolate, env->no_global_search_paths())) + .IsNothing()) return; + + args.GetReturnValue().Set(ret); +} + void Initialize(Local<Object> target, Local<Value> unused, Local<Context> context, void* priv) { Environment* env = Environment::GetCurrent(context); Isolate* isolate = env->isolate(); - env->SetMethodNoSideEffect(target, "getOptions", GetOptions); + env->SetMethodNoSideEffect(target, "getCLIOptions", GetCLIOptions); + env->SetMethodNoSideEffect(target, "getEmbedderOptions", GetEmbedderOptions); Local<Object> env_settings = Object::New(isolate); NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment); @@ -1077,18 +1102,6 @@ void Initialize(Local<Object> target, context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings) .Check(); - target - ->Set(context, - FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), - Boolean::New(isolate, env->should_not_register_esm_loader())) - .Check(); - - target - ->Set(context, - FIXED_ONE_BYTE_STRING(env->isolate(), "noGlobalSearchPaths"), - Boolean::New(isolate, env->no_global_search_paths())) - .Check(); - Local<Object> types = Object::New(isolate); NODE_DEFINE_CONSTANT(types, kNoOp); NODE_DEFINE_CONSTANT(types, kV8Option); |