diff --git a/lib/internal/bootstrap/browser.js b/lib/internal/bootstrap/browser.js index 68dac3b1ca4b8c..35e65e65944324 100644 --- a/lib/internal/bootstrap/browser.js +++ b/lib/internal/bootstrap/browser.js @@ -7,9 +7,13 @@ const { const { defineOperation, + emitExperimentalWarning, exposeInterface, lazyDOMExceptionClass, } = require('internal/util'); + +const { getOptionValue } = require('internal/options'); + const config = internalBinding('config'); // Override global console from the one provided by the VM @@ -71,6 +75,17 @@ defineOperation(globalThis, 'setTimeout', timers.setTimeout); defineReplacableAttribute(globalThis, 'performance', require('perf_hooks').performance); +// https://fetch.spec.whatwg.org/ +if (getOptionValue('--experimental-fetch')) { + emitExperimentalWarning('Fetch'); + + const undici = require('internal/deps/undici/undici'); + defineOperation(globalThis, 'fetch', undici.fetch); + exposeInterface(globalThis, 'Headers', undici.Headers); + exposeInterface(globalThis, 'Request', undici.Request); + exposeInterface(globalThis, 'Response', undici.Response); +} + function createGlobalConsole(consoleFromVM) { const consoleFromNode = require('internal/console/global'); diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 1fe56478e0ab3f..f21ba048b48638 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -14,11 +14,6 @@ const { getEmbedderOptions, } = require('internal/options'); const { reconnectZeroFillToggle } = require('internal/buffer'); -const { - defineOperation, - emitExperimentalWarning, - exposeInterface, -} = require('internal/util'); const { Buffer } = require('buffer'); const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes; @@ -35,7 +30,6 @@ function prepareMainThreadExecution(expandArgv1 = false) { setupPerfHooks(); setupInspectorHooks(); setupWarningHandler(); - setupFetch(); // Resolve the coverage directory to an absolute path, and // overwrite process.env so that the original path gets passed @@ -147,21 +141,6 @@ function setupWarningHandler() { } } -// https://fetch.spec.whatwg.org/ -function setupFetch() { - if (!getOptionValue('--experimental-fetch')) { - return; - } - - emitExperimentalWarning('Fetch'); - - const undici = require('internal/deps/undici/undici'); - defineOperation(globalThis, 'fetch', undici.fetch); - exposeInterface(globalThis, 'Headers', undici.Headers); - exposeInterface(globalThis, 'Request', undici.Request); - exposeInterface(globalThis, 'Response', undici.Response); -} - // Setup User-facing NODE_V8_COVERAGE environment variable that writes // ScriptCoverage to a specified file. function setupCoverageHooks(dir) { @@ -502,7 +481,6 @@ module.exports = { patchProcessObject, setupCoverageHooks, setupWarningHandler, - setupFetch, setupDebugEnv, setupPerfHooks, prepareMainThreadExecution, diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 5e24b84e14c934..65827ecd593ffb 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -17,7 +17,6 @@ const { setupCoverageHooks, setupInspectorHooks, setupWarningHandler, - setupFetch, setupDebugEnv, setupPerfHooks, initializeDeprecations, @@ -68,7 +67,6 @@ setupInspectorHooks(); setupDebugEnv(); setupWarningHandler(); -setupFetch(); initializeSourceMapsHandlers(); // Since worker threads cannot switch cwd, we do not need to diff --git a/src/node_external_reference.h b/src/node_external_reference.h index 347945a7496d5f..efc7fcbdaa66ba 100644 --- a/src/node_external_reference.h +++ b/src/node_external_reference.h @@ -68,6 +68,7 @@ class ExternalReferenceRegistry { V(messaging) \ V(native_module) \ V(os) \ + V(options) \ V(performance) \ V(process_methods) \ V(process_object) \ diff --git a/src/node_options.cc b/src/node_options.cc index bac3de2404b5c3..4047085c783e2c 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -1128,6 +1128,11 @@ void Initialize(Local target, .Check(); } +void RegisterExternalReferences(ExternalReferenceRegistry* registry) { + registry->Register(GetCLIOptions); + registry->Register(GetEmbedderOptions); +} + } // namespace options_parser void HandleEnvOptions(std::shared_ptr env_options) { @@ -1194,3 +1199,5 @@ std::vector ParseNodeOptionsEnvVar( } // namespace node NODE_MODULE_CONTEXT_AWARE_INTERNAL(options, node::options_parser::Initialize) +NODE_MODULE_EXTERNAL_REFERENCE(options, + node::options_parser::RegisterExternalReferences)