Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
src: add fetch to bootstrap/browser.js
Fixes: #41816
Signed-off-by: Darshan Sen <raisinten@gmail.com>
  • Loading branch information
RaisinTen committed Feb 13, 2022
commit 2ece79a64c13d3f8e1bb1e734d861c64adf4ca55
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)