| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bfdd32f commit c15afda
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,8 +11,7 @@ const { | |||
| 11 | 11 | ||
| 12 | 12 | const { | |
| 13 | 13 | getOptionValue, | |
| 14 | - noGlobalSearchPaths, | ||
| 15 | - shouldNotRegisterESMLoader, | ||
| 14 | + getEmbedderOptions, | ||
| 16 | 15 | } = require('internal/options'); | |
| 17 | 16 | const { reconnectZeroFillToggle } = require('internal/buffer'); | |
| 18 | 17 | ||
@@ -421,7 +420,7 @@ function initializeWASI() { | |||
| 421 | 420 | ||
| 422 | 421 | function initializeCJSLoader() { | |
| 423 | 422 | const CJSLoader = require('internal/modules/cjs/loader'); | |
| 424 | - if (!noGlobalSearchPaths) { | ||
| 423 | + if (!getEmbedderOptions().noGlobalSearchPaths) { | ||
| 425 | 424 | CJSLoader.Module._initPaths(); | |
| 426 | 425 | } | |
| 427 | 426 | // TODO(joyeecheung): deprecate this in favor of a proper hook? | |
@@ -433,7 +432,7 @@ function initializeESMLoader() { | |||
| 433 | 432 | // Create this WeakMap in js-land because V8 has no C++ API for WeakMap. | |
| 434 | 433 | internalBinding('module_wrap').callbackMap = new SafeWeakMap(); | |
| 435 | 434 | ||
| 436 | - if (shouldNotRegisterESMLoader) return; | ||
| 435 | + if (getEmbedderOptions().shouldNotRegisterESMLoader) return; | ||
| 437 | 436 | ||
| 438 | 437 | const { | |
| 439 | 438 | setImportModuleDynamicallyCallback, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,36 +1,43 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | 3 | const { | |
| 4 | - getOptions, | ||
| 5 | - noGlobalSearchPaths, | ||
| 6 | - shouldNotRegisterESMLoader, | ||
| 4 | + getCLIOptions, | ||
| 5 | + getEmbedderOptions: getEmbedderOptionsFromBinding, | ||
| 7 | 6 | } = internalBinding('options'); | |
| 8 | 7 | ||
| 9 | 8 | let warnOnAllowUnauthorized = true; | |
| 10 | 9 | ||
| 11 | 10 | let optionsMap; | |
| 12 | 11 | let aliasesMap; | |
| 12 | + let embedderOptions; | ||
| 13 | 13 | ||
| 14 | - // getOptions() would serialize the option values from C++ land. | ||
| 14 | + // getCLIOptions() would serialize the option values from C++ land. | ||
| 15 | 15 | // It would error if the values are queried before bootstrap is | |
| 16 | 16 | // complete so that we don't accidentally include runtime-dependent | |
| 17 | 17 | // states into a runtime-independent snapshot. | |
| 18 | - function getOptionsFromBinding() { | ||
| 18 | + function getCLIOptionsFromBinding() { | ||
| 19 | 19 | if (!optionsMap) { | |
| 20 | - ({ options: optionsMap } = getOptions()); | ||
| 20 | + ({ options: optionsMap } = getCLIOptions()); | ||
| 21 | 21 | } | |
| 22 | 22 | return optionsMap; | |
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | function getAliasesFromBinding() { | |
| 26 | 26 | if (!aliasesMap) { | |
| 27 | - ({ aliases: aliasesMap } = getOptions()); | ||
| 27 | + ({ aliases: aliasesMap } = getCLIOptions()); | ||
| 28 | 28 | } | |
| 29 | 29 | return aliasesMap; | |
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | + function getEmbedderOptions() { | ||
| 33 | + if (!embedderOptions) { | ||
| 34 | + embedderOptions = getEmbedderOptionsFromBinding(); | ||
| 35 | + } | ||
| 36 | + return embedderOptions; | ||
| 37 | + } | ||
| 38 | + | ||
| 32 | 39 | function getOptionValue(optionName) { | |
| 33 | - const options = getOptionsFromBinding(); | ||
| 40 | + const options = getCLIOptionsFromBinding(); | ||
| 34 | 41 | if (optionName.startsWith('--no-')) { | |
| 35 | 42 | const option = options.get('--' + optionName.slice(5)); | |
| 36 | 43 | return option && !option.value; | |
@@ -54,13 +61,12 @@ function getAllowUnauthorized() { | |||
| 54 | 61 | ||
| 55 | 62 | module.exports = { | |
| 56 | 63 | get options() { | |
| 57 | - return getOptionsFromBinding(); | ||
| 64 | + return getCLIOptionsFromBinding(); | ||
| 58 | 65 | }, | |
| 59 | 66 | get aliases() { | |
| 60 | 67 | return getAliasesFromBinding(); | |
| 61 | 68 | }, | |
| 62 | 69 | getOptionValue, | |
| 63 | 70 | getAllowUnauthorized, | |
| 64 | - noGlobalSearchPaths, | ||
| 65 | - shouldNotRegisterESMLoader, | ||
| 71 | + getEmbedderOptions | ||
| 66 | 72 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -915,7 +915,7 @@ std::string GetBashCompletion() { | |||
| 915 | 915 | ||
| 916 | 916 | // Return a map containing all the options and their metadata as well | |
| 917 | 917 | // as the aliases | |
| 918 | - void GetOptions(const FunctionCallbackInfo<Value>& args) { | ||
| 918 | + void GetCLIOptions(const FunctionCallbackInfo<Value>& args) { | ||
| 919 | 919 | Mutex::ScopedLock lock(per_process::cli_options_mutex); | |
| 920 | 920 | Environment* env = Environment::GetCurrent(args); | |
| 921 | 921 | if (!env->has_run_bootstrapping_code()) { | |
@@ -1056,13 +1056,38 @@ void GetOptions(const FunctionCallbackInfo<Value>& args) { | |||
| 1056 | 1056 | args.GetReturnValue().Set(ret); | |
| 1057 | 1057 | } | |
| 1058 | 1058 | ||
| 1059 | + void GetEmbedderOptions(const FunctionCallbackInfo<Value>& args) { | ||
| 1060 | + Environment* env = Environment::GetCurrent(args); | ||
| 1061 | + if (!env->has_run_bootstrapping_code()) { | ||
| 1062 | + // No code because this is an assertion. | ||
| 1063 | + return env->ThrowError( | ||
| 1064 | + "Should not query options before bootstrapping is done"); | ||
| 1065 | + } | ||
| 1066 | + Isolate* isolate = args.GetIsolate(); | ||
| 1067 | + Local<Context> context = env->context(); | ||
| 1068 | + Local<Object> ret = Object::New(isolate); | ||
| 1069 | + | ||
| 1070 | + if (ret->Set(context, | ||
| 1071 | + FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), | ||
| 1072 | + Boolean::New(isolate, env->should_not_register_esm_loader())) | ||
| 1073 | + .IsNothing()) return; | ||
| 1074 | + | ||
| 1075 | + if (ret->Set(context, | ||
| 1076 | + FIXED_ONE_BYTE_STRING(env->isolate(), "noGlobalSearchPaths"), | ||
| 1077 | + Boolean::New(isolate, env->no_global_search_paths())) | ||
| 1078 | + .IsNothing()) return; | ||
| 1079 | + | ||
| 1080 | + args.GetReturnValue().Set(ret); | ||
| 1081 | + } | ||
| 1082 | + | ||
| 1059 | 1083 | void Initialize(Local<Object> target, | |
| 1060 | 1084 | Local<Value> unused, | |
| 1061 | 1085 | Local<Context> context, | |
| 1062 | 1086 | void* priv) { | |
| 1063 | 1087 | Environment* env = Environment::GetCurrent(context); | |
| 1064 | 1088 | Isolate* isolate = env->isolate(); | |
| 1065 | - env->SetMethodNoSideEffect(target, "getOptions", GetOptions); | ||
| 1089 | + env->SetMethodNoSideEffect(target, "getCLIOptions", GetCLIOptions); | ||
| 1090 | + env->SetMethodNoSideEffect(target, "getEmbedderOptions", GetEmbedderOptions); | ||
| 1066 | 1091 | ||
| 1067 | 1092 | Local<Object> env_settings = Object::New(isolate); | |
| 1068 | 1093 | NODE_DEFINE_CONSTANT(env_settings, kAllowedInEnvironment); | |
@@ -1072,18 +1097,6 @@ void Initialize(Local<Object> target, | |||
| 1072 | 1097 | context, FIXED_ONE_BYTE_STRING(isolate, "envSettings"), env_settings) | |
| 1073 | 1098 | .Check(); | |
| 1074 | 1099 | ||
| 1075 | - target | ||
| 1076 | - ->Set(context, | ||
| 1077 | - FIXED_ONE_BYTE_STRING(env->isolate(), "shouldNotRegisterESMLoader"), | ||
| 1078 | - Boolean::New(isolate, env->should_not_register_esm_loader())) | ||
| 1079 | - .Check(); | ||
| 1080 | - | ||
| 1081 | - target | ||
| 1082 | - ->Set(context, | ||
| 1083 | - FIXED_ONE_BYTE_STRING(env->isolate(), "noGlobalSearchPaths"), | ||
| 1084 | - Boolean::New(isolate, env->no_global_search_paths())) | ||
| 1085 | - .Check(); | ||
| 1086 | - | ||
| 1087 | 1100 | Local<Object> types = Object::New(isolate); | |
| 1088 | 1101 | NODE_DEFINE_CONSTANT(types, kNoOp); | |
| 1089 | 1102 | NODE_DEFINE_CONSTANT(types, kV8Option); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -461,7 +461,7 @@ class OptionsParser { | |||
| 461 | 461 | template <typename OtherOptions> | |
| 462 | 462 | friend class OptionsParser; | |
| 463 | 463 | ||
| 464 | - friend void GetOptions(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 464 | + friend void GetCLIOptions(const v8::FunctionCallbackInfo<v8::Value>& args); | ||
| 465 | 465 | friend std::string GetBashCompletion(); | |
| 466 | 466 | }; | |
| 467 | 467 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments