diff options
author | Michaƫl Zasso <targos@protonmail.com> | 2022-02-01 11:17:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 11:17:50 +0300 |
commit | 6ec225392675c92b102d3caad02ee3a157c9d1b7 (patch) | |
tree | 6836c71b09d64c848e0496eec6d94e0f28a46e6e /lib | |
parent | 7123a00b03a908621255dc35f8d75c112901a42c (diff) |
lib: add fetch
Fixes: https://github.com/nodejs/node/issues/19393
PR-URL: https://github.com/nodejs/node/pull/41749
Refs: https://github.com/nodejs/undici/pull/1183
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/bootstrap/pre_execution.js | 22 | ||||
-rw-r--r-- | lib/internal/main/worker_thread.js | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 71b0afd4e67..5bfa869158a 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -14,6 +14,11 @@ 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; @@ -30,6 +35,7 @@ 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 @@ -139,6 +145,21 @@ 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) { @@ -479,6 +500,7 @@ 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 71a07a63a36..d08afa955ac 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -17,6 +17,7 @@ const { setupCoverageHooks, setupInspectorHooks, setupWarningHandler, + setupFetch, setupDebugEnv, setupPerfHooks, initializeDeprecations, @@ -67,6 +68,7 @@ setupInspectorHooks(); setupDebugEnv(); setupWarningHandler(); +setupFetch(); initializeSourceMapsHandlers(); // Since worker threads cannot switch cwd, we do not need to |