@@ -78,7 +78,7 @@ function prepareExecution(options) {
78
78
setupTraceCategoryState ( ) ;
79
79
setupInspectorHooks ( ) ;
80
80
setupWarningHandler ( ) ;
81
- setupFetch ( ) ;
81
+ setupUndici ( ) ;
82
82
setupWebCrypto ( ) ;
83
83
setupCustomEvent ( ) ;
84
84
setupCodeCoverage ( ) ;
@@ -262,9 +262,9 @@ function setupWarningHandler() {
262
262
}
263
263
264
264
// https://fetch.spec.whatwg.org/
265
- function setupFetch ( ) {
266
- if ( getEmbedderOptions ( ) . noBrowserGlobals ||
267
- getOptionValue ( '--no-experimental-fetch' ) ) {
265
+ // https://websockets.spec.whatwg.org/
266
+ function setupUndici ( ) {
267
+ if ( getEmbedderOptions ( ) . noBrowserGlobals ) {
268
268
return ;
269
269
}
270
270
@@ -278,12 +278,6 @@ function setupFetch() {
278
278
return undici ;
279
279
}
280
280
281
- async function fetch ( input , init = undefined ) {
282
- return lazyUndici ( ) . fetch ( input , init ) ;
283
- }
284
-
285
- defineOperation ( globalThis , 'fetch' , fetch ) ;
286
-
287
281
function lazyInterface ( name ) {
288
282
return {
289
283
configurable : true ,
@@ -297,17 +291,31 @@ function setupFetch() {
297
291
} ;
298
292
}
299
293
300
- ObjectDefineProperties ( globalThis , {
301
- FormData : lazyInterface ( 'FormData' ) ,
302
- Headers : lazyInterface ( 'Headers' ) ,
303
- Request : lazyInterface ( 'Request' ) ,
304
- Response : lazyInterface ( 'Response' ) ,
305
- } ) ;
294
+ if ( ! getOptionValue ( '--no-experimental-fetch' ) ) {
295
+ async function fetch ( input , init = undefined ) {
296
+ return lazyUndici ( ) . fetch ( input , init ) ;
297
+ }
306
298
307
- // The WebAssembly Web API: https://webassembly.github.io/spec/web-api
308
- internalBinding ( 'wasm_web_api' ) . setImplementation ( ( streamState , source ) => {
309
- require ( 'internal/wasm_web_api' ) . wasmStreamingCallback ( streamState , source ) ;
310
- } ) ;
299
+ defineOperation ( globalThis , 'fetch' , fetch ) ;
300
+
301
+ ObjectDefineProperties ( globalThis , {
302
+ FormData : lazyInterface ( 'FormData' ) ,
303
+ Headers : lazyInterface ( 'Headers' ) ,
304
+ Request : lazyInterface ( 'Request' ) ,
305
+ Response : lazyInterface ( 'Response' ) ,
306
+ } ) ;
307
+
308
+ // The WebAssembly Web API: https://webassembly.github.io/spec/web-api
309
+ internalBinding ( 'wasm_web_api' ) . setImplementation ( ( streamState , source ) => {
310
+ require ( 'internal/wasm_web_api' ) . wasmStreamingCallback ( streamState , source ) ;
311
+ } ) ;
312
+ }
313
+
314
+ if ( getOptionValue ( '--experimental-websocket' ) ) {
315
+ ObjectDefineProperties ( globalThis , {
316
+ WebSocket : lazyInterface ( 'WebSocket' ) ,
317
+ } ) ;
318
+ }
311
319
}
312
320
313
321
// TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is
0 commit comments