Skip to content

Commit

Permalink
src: add fetch to bootstrap/browser.js
Browse files Browse the repository at this point in the history
Fixes: nodejs#41816
Signed-off-by: Darshan Sen <[email protected]>
  • Loading branch information
RaisinTen committed Feb 13, 2022
1 parent a137eca commit 2ece79a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/internal/bootstrap/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class ExternalReferenceRegistry {
V(messaging) \
V(native_module) \
V(os) \
V(options) \
V(performance) \
V(process_methods) \
V(process_object) \
Expand Down
6 changes: 6 additions & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,11 @@ void Initialize(Local<Object> target,
.Check();
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(GetCLIOptions);
registry->Register(GetEmbedderOptions);
}

} // namespace options_parser

void HandleEnvOptions(std::shared_ptr<EnvironmentOptions> env_options) {
Expand Down Expand Up @@ -1194,3 +1199,4 @@ std::vector<std::string> ParseNodeOptionsEnvVar(
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(options, node::options_parser::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(options, node::options_parser::RegisterExternalReferences)

0 comments on commit 2ece79a

Please sign in to comment.