diff --git a/deps/undici/undici.js b/deps/undici/undici.js index 1a2312842a6925..c1d83ec00c2c94 100644 --- a/deps/undici/undici.js +++ b/deps/undici/undici.js @@ -1,3 +1,9 @@ +module.exports = function ({ // pull in primordials + WebAssembly, + globalThis, + AbortController, + URL +}) { "use strict"; var __defProp = Object.defineProperty; var __getOwnPropNames = Object.getOwnPropertyNames; @@ -13462,7 +13468,8 @@ var require_eventsource = __commonJS({ var { getGlobalDispatcher, setGlobalDispatcher } = require_global2(); var EnvHttpProxyAgent = require_env_http_proxy_agent(); var fetchImpl = require_fetch().fetch; -module.exports.fetch = /* @__PURE__ */ __name(function fetch(resource, init = void 0) { +var module_exports = {}; +module_exports.fetch = /* @__PURE__ */ __name(function fetch(resource, init = void 0) { return fetchImpl(resource, init).catch((err) => { if (err && typeof err === "object") { Error.captureStackTrace(err); @@ -13470,19 +13477,21 @@ module.exports.fetch = /* @__PURE__ */ __name(function fetch(resource, init = vo throw err; }); }, "fetch"); -module.exports.FormData = require_formdata().FormData; -module.exports.Headers = require_headers().Headers; -module.exports.Response = require_response().Response; -module.exports.Request = require_request2().Request; +module_exports.FormData = require_formdata().FormData; +module_exports.Headers = require_headers().Headers; +module_exports.Response = require_response().Response; +module_exports.Request = require_request2().Request; var { CloseEvent, ErrorEvent, MessageEvent, createFastMessageEvent } = require_events(); -module.exports.WebSocket = require_websocket().WebSocket; -module.exports.CloseEvent = CloseEvent; -module.exports.ErrorEvent = ErrorEvent; -module.exports.MessageEvent = MessageEvent; -module.exports.createFastMessageEvent = createFastMessageEvent; -module.exports.EventSource = require_eventsource().EventSource; -module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent; -module.exports.getGlobalDispatcher = getGlobalDispatcher; -module.exports.setGlobalDispatcher = setGlobalDispatcher; +module_exports.WebSocket = require_websocket().WebSocket; +module_exports.CloseEvent = CloseEvent; +module_exports.ErrorEvent = ErrorEvent; +module_exports.MessageEvent = MessageEvent; +module_exports.createFastMessageEvent = createFastMessageEvent; +module_exports.EventSource = require_eventsource().EventSource; +module_exports.EnvHttpProxyAgent = EnvHttpProxyAgent; +module_exports.getGlobalDispatcher = getGlobalDispatcher; +module_exports.setGlobalDispatcher = setGlobalDispatcher; /*! formdata-polyfill. MIT License. Jimmy Wärting */ /*! ws. MIT License. Einar Otto Stangvik */ +return module_exports; +}; diff --git a/lib/http.js b/lib/http.js index 96ea32cf1b1034..4e0ef3cffe9c26 100644 --- a/lib/http.js +++ b/lib/http.js @@ -120,7 +120,7 @@ function get(url, options, cb) { * @returns {object} An object containing WebSocket, CloseEvent, and MessageEvent classes. */ function lazyUndici() { - return undici ??= require('internal/deps/undici/undici'); + return undici ??= require('internal/deps/undici/undici')(primordials); } module.exports = { diff --git a/lib/internal/bootstrap/web/exposed-window-or-worker.js b/lib/internal/bootstrap/web/exposed-window-or-worker.js index d7d9b60b1c8e94..82dd08a0d83eda 100644 --- a/lib/internal/bootstrap/web/exposed-window-or-worker.js +++ b/lib/internal/bootstrap/web/exposed-window-or-worker.js @@ -75,7 +75,7 @@ ObjectDefineProperty(globalThis, 'fetch', { writable: true, value: function fetch(input, init = undefined) { // eslint-disable-line func-name-matching if (!fetchImpl) { // Implement lazy loading of undici module for fetch function - const undiciModule = require('internal/deps/undici/undici'); + const undiciModule = require('internal/deps/undici/undici')(primordials); fetchImpl = undiciModule.fetch; } return fetchImpl(input, init); @@ -86,13 +86,13 @@ ObjectDefineProperty(globalThis, 'fetch', { // https://fetch.spec.whatwg.org/#headers-class // https://fetch.spec.whatwg.org/#request-class // https://fetch.spec.whatwg.org/#response-class -exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [ +exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [ // TODO 'FormData', 'Headers', 'Request', 'Response', 'MessageEvent', 'CloseEvent', ]); // https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events.org/ // https://websockets.spec.whatwg.org/ -exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['EventSource', 'WebSocket']); +exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['EventSource', 'WebSocket']); // TODO // The WebAssembly Web API which relies on Response. // https:// webassembly.github.io/spec/web-api/#streaming-modules diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index 9851f3f64f6e56..1f6d5730bd4719 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -184,6 +184,7 @@ function copyPrototype(src, dest, prefix) { // Create copies of intrinsic objects [ + 'AbortController', 'AggregateError', 'Array', 'ArrayBuffer', @@ -218,9 +219,12 @@ function copyPrototype(src, dest, prefix) { 'Uint32Array', 'Uint8Array', 'Uint8ClampedArray', + 'URL', + 'URLSearchParams', 'WeakMap', 'WeakRef', 'WeakSet', + 'WebAssembly', ].forEach((name) => { // eslint-disable-next-line no-restricted-globals const original = globalThis[name]; diff --git a/lib/internal/wasm_web_api.js b/lib/internal/wasm_web_api.js index 9c21864fa56998..4738b2fd437933 100644 --- a/lib/internal/wasm_web_api.js +++ b/lib/internal/wasm_web_api.js @@ -10,7 +10,7 @@ const { let undici; function lazyUndici() { - return undici ??= require('internal/deps/undici/undici'); + return undici ??= require('internal/deps/undici/undici')(primordials); } // This is essentially an implementation of a v8::WasmStreamingCallback, except diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index 42b8845cec6711..573faae3bc9d7e 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -97,7 +97,7 @@ const messageTypes = { // passed are known to be valid. let fastCreateMessageEvent; function lazyMessageEvent(type, init) { - fastCreateMessageEvent ??= require('internal/deps/undici/undici').createFastMessageEvent; + fastCreateMessageEvent ??= require('internal/deps/undici/undici')(primordials).createFastMessageEvent; return fastCreateMessageEvent(type, init); }