@@ -78,7 +78,7 @@ function prepareExecution(options) {
7878 setupTraceCategoryState ( ) ;
7979 setupInspectorHooks ( ) ;
8080 setupWarningHandler ( ) ;
81- setupFetch ( ) ;
81+ setupUndici ( ) ;
8282 setupWebCrypto ( ) ;
8383 setupCustomEvent ( ) ;
8484 setupCodeCoverage ( ) ;
@@ -262,9 +262,9 @@ function setupWarningHandler() {
262262}
263263
264264// 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 ) {
268268 return ;
269269 }
270270
@@ -278,12 +278,6 @@ function setupFetch() {
278278 return undici ;
279279 }
280280
281- async function fetch ( input , init = undefined ) {
282- return lazyUndici ( ) . fetch ( input , init ) ;
283- }
284-
285- defineOperation ( globalThis , 'fetch' , fetch ) ;
286-
287281 function lazyInterface ( name ) {
288282 return {
289283 configurable : true ,
@@ -297,17 +291,31 @@ function setupFetch() {
297291 } ;
298292 }
299293
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+ }
306298
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+ }
311319}
312320
313321// TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is
0 commit comments