| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8f63f6f commit 7f698f0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ | |||
| 10 | 10 | ||
| 11 | 11 | const { | |
| 12 | 12 | globalThis, | |
| 13 | + ObjectDefineProperty, | ||
| 13 | 14 | } = primordials; | |
| 14 | 15 | ||
| 15 | 16 | const { | |
@@ -55,3 +56,44 @@ defineReplaceableLazyAttribute(globalThis, 'perf_hooks', ['performance']); | |||
| 55 | 56 | // https://w3c.github.io/FileAPI/#creating-revoking | |
| 56 | 57 | const { installObjectURLMethods } = require('internal/url'); | |
| 57 | 58 | installObjectURLMethods(); | |
| 59 | + | ||
| 60 | + { | ||
| 61 | + // https://fetch.spec.whatwg.org/#fetch-method | ||
| 62 | + function set(value) { | ||
| 63 | + ObjectDefineProperty(globalThis, 'fetch', { | ||
| 64 | + __proto__: null, | ||
| 65 | + writable: true, | ||
| 66 | + value, | ||
| 67 | + }); | ||
| 68 | + } | ||
| 69 | + ObjectDefineProperty(globalThis, 'fetch', { | ||
| 70 | + __proto__: null, | ||
| 71 | + configurable: true, | ||
| 72 | + enumerable: true, | ||
| 73 | + set, | ||
| 74 | + get() { | ||
| 75 | + function fetch(input, init = undefined) { | ||
| 76 | + // Loading undici alone lead to promises which breaks lots of tests so we | ||
| 77 | + // have to load it really lazily for now. | ||
| 78 | + const { fetch: impl } = require('internal/deps/undici/undici'); | ||
| 79 | + return impl(input, init); | ||
| 80 | + } | ||
| 81 | + set(fetch); | ||
| 82 | + return fetch; | ||
| 83 | + }, | ||
| 84 | + }); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + // https://xhr.spec.whatwg.org/#interface-formdata | ||
| 88 | + // https://fetch.spec.whatwg.org/#headers-class | ||
| 89 | + // https://fetch.spec.whatwg.org/#request-class | ||
| 90 | + // https://fetch.spec.whatwg.org/#response-class | ||
| 91 | + exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', [ | ||
| 92 | + 'FormData', 'Headers', 'Request', 'Response', | ||
| 93 | + ]); | ||
| 94 | + | ||
| 95 | + // The WebAssembly Web API which relies on Response. | ||
| 96 | + // https:// webassembly.github.io/spec/web-api/#streaming-modules | ||
| 97 | + internalBinding('wasm_web_api').setImplementation((streamState, source) => { | ||
| 98 | + require('internal/wasm_web_api').wasmStreamingCallback(streamState, source); | ||
| 99 | + }); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,6 @@ const { | |||
| 10 | 10 | DatePrototypeGetMonth, | |
| 11 | 11 | DatePrototypeGetSeconds, | |
| 12 | 12 | NumberParseInt, | |
| 13 | - ObjectDefineProperties, | ||
| 14 | 13 | ObjectDefineProperty, | |
| 15 | 14 | ObjectFreeze, | |
| 16 | 15 | ObjectGetOwnPropertyDescriptor, | |
@@ -30,7 +29,6 @@ const { | |||
| 30 | 29 | } = require('internal/options'); | |
| 31 | 30 | const { reconnectZeroFillToggle } = require('internal/buffer'); | |
| 32 | 31 | const { | |
| 33 | - defineOperation, | ||
| 34 | 32 | exposeInterface, | |
| 35 | 33 | exposeLazyInterfaces, | |
| 36 | 34 | defineReplaceableLazyAttribute, | |
@@ -302,58 +300,16 @@ function setupWarningHandler() { | |||
| 302 | 300 | // https://fetch.spec.whatwg.org/ | |
| 303 | 301 | // https://websockets.spec.whatwg.org/ | |
| 304 | 302 | function setupUndici() { | |
| 305 | - if (getEmbedderOptions().noBrowserGlobals) { | ||
| 306 | - return; | ||
| 307 | - } | ||
| 308 | - | ||
| 309 | - let undici; | ||
| 310 | - function lazyUndici() { | ||
| 311 | - if (undici) { | ||
| 312 | - return undici; | ||
| 313 | - } | ||
| 314 | - | ||
| 315 | - undici = require('internal/deps/undici/undici'); | ||
| 316 | - return undici; | ||
| 317 | - } | ||
| 318 | - | ||
| 319 | - function lazyInterface(name) { | ||
| 320 | - return { | ||
| 321 | - configurable: true, | ||
| 322 | - enumerable: false, | ||
| 323 | - get() { | ||
| 324 | - return lazyUndici()[name]; | ||
| 325 | - }, | ||
| 326 | - set(value) { | ||
| 327 | - exposeInterface(globalThis, name, value); | ||
| 328 | - }, | ||
| 329 | - }; | ||
| 303 | + if (getOptionValue('--no-experimental-fetch')) { | ||
| 304 | + delete globalThis.fetch; | ||
| 305 | + delete globalThis.FormData; | ||
| 306 | + delete globalThis.Headers; | ||
| 307 | + delete globalThis.Request; | ||
| 308 | + delete globalThis.Response; | ||
| 330 | 309 | } | |
| 331 | 310 | ||
| 332 | - if (!getOptionValue('--no-experimental-fetch')) { | ||
| 333 | - // Fetch is meant to return a Promise, but not be async. | ||
| 334 | - function fetch(input, init = undefined) { | ||
| 335 | - return lazyUndici().fetch(input, init); | ||
| 336 | - } | ||
| 337 | - | ||
| 338 | - defineOperation(globalThis, 'fetch', fetch); | ||
| 339 | - | ||
| 340 | - ObjectDefineProperties(globalThis, { | ||
| 341 | - FormData: lazyInterface('FormData'), | ||
| 342 | - Headers: lazyInterface('Headers'), | ||
| 343 | - Request: lazyInterface('Request'), | ||
| 344 | - Response: lazyInterface('Response'), | ||
| 345 | - }); | ||
| 346 | - | ||
| 347 | - // The WebAssembly Web API: https://webassembly.github.io/spec/web-api | ||
| 348 | - internalBinding('wasm_web_api').setImplementation((streamState, source) => { | ||
| 349 | - require('internal/wasm_web_api').wasmStreamingCallback(streamState, source); | ||
| 350 | - }); | ||
| 351 | - } | ||
| 352 | - | ||
| 353 | - if (getOptionValue('--experimental-websocket')) { | ||
| 354 | - ObjectDefineProperties(globalThis, { | ||
| 355 | - WebSocket: lazyInterface('WebSocket'), | ||
| 356 | - }); | ||
| 311 | + if (!getEmbedderOptions().noBrowserGlobals && getOptionValue('--experimental-websocket')) { | ||
| 312 | + exposeLazyInterfaces(globalThis, 'internal/deps/undici/undici', ['WebSocket']); | ||
| 357 | 313 | } | |
| 358 | 314 | } | |
| 359 | 315 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,10 +98,10 @@ expected.beforePreExec = new Set([ | |||
| 98 | 98 | 'NativeModule internal/modules/package_json_reader', | |
| 99 | 99 | 'Internal Binding module_wrap', | |
| 100 | 100 | 'NativeModule internal/modules/cjs/loader', | |
| 101 | + 'Internal Binding wasm_web_api', | ||
| 101 | 102 | ]); | |
| 102 | 103 | ||
| 103 | 104 | expected.atRunTime = new Set([ | |
| 104 | - 'Internal Binding wasm_web_api', | ||
| 105 | 105 | 'Internal Binding worker', | |
| 106 | 106 | 'NativeModule internal/modules/run_main', | |
| 107 | 107 | 'NativeModule internal/net', | |
| Back | FazBrowse Home | New Git URL |
0 commit comments