@@ -56,7 +56,11 @@ const {
5656} = primordials ;
5757const config = internalBinding ( 'config' ) ;
5858const internalTimers = require ( 'internal/timers' ) ;
59- const { deprecate, lazyDOMExceptionClass } = require ( 'internal/util' ) ;
59+ const {
60+ defineOperation,
61+ deprecate,
62+ exposeInterface,
63+ } = require ( 'internal/util' ) ;
6064
6165setupProcessObject ( ) ;
6266
@@ -205,79 +209,20 @@ const {
205209 queueMicrotask
206210} = require ( 'internal/process/task_queues' ) ;
207211
208- if ( ! config . noBrowserGlobals ) {
209- // Override global console from the one provided by the VM
210- // to the one implemented by Node.js
211- // https://console.spec.whatwg.org/#console-namespace
212- exposeNamespace ( globalThis , 'console' ,
213- createGlobalConsole ( globalThis . console ) ) ;
214-
215- const { URL , URLSearchParams } = require ( 'internal/url' ) ;
216- // https://url.spec.whatwg.org/#url
217- exposeInterface ( globalThis , 'URL' , URL ) ;
218- // https://url.spec.whatwg.org/#urlsearchparams
219- exposeInterface ( globalThis , 'URLSearchParams' , URLSearchParams ) ;
220- exposeGetterAndSetter ( globalThis ,
221- 'DOMException' ,
222- lazyDOMExceptionClass ,
223- ( value ) => {
224- exposeInterface ( globalThis , 'DOMException' , value ) ;
225- } ) ;
212+ // Non-standard extensions:
213+ const { BroadcastChannel } = require ( 'internal/worker/io' ) ;
214+ exposeInterface ( globalThis , 'BroadcastChannel' , BroadcastChannel ) ;
226215
227- const {
228- TextEncoder, TextDecoder
229- } = require ( 'internal/encoding' ) ;
230- // https://encoding.spec.whatwg.org/#textencoder
231- exposeInterface ( globalThis , 'TextEncoder' , TextEncoder ) ;
232- // https://encoding.spec.whatwg.org/#textdecoder
233- exposeInterface ( globalThis , 'TextDecoder' , TextDecoder ) ;
216+ defineOperation ( globalThis , 'queueMicrotask' , queueMicrotask ) ;
234217
235- const {
236- AbortController,
237- AbortSignal,
238- } = require ( 'internal/abort_controller' ) ;
239- exposeInterface ( globalThis , 'AbortController' , AbortController ) ;
240- exposeInterface ( globalThis , 'AbortSignal' , AbortSignal ) ;
218+ const timers = require ( 'timers' ) ;
219+ defineOperation ( globalThis , 'clearImmediate' , timers . clearImmediate ) ;
220+ defineOperation ( globalThis , 'setImmediate' , timers . setImmediate ) ;
241221
242- const {
243- EventTarget,
244- Event,
245- } = require ( 'internal/event_target' ) ;
246- exposeInterface ( globalThis , 'EventTarget' , EventTarget ) ;
247- exposeInterface ( globalThis , 'Event' , Event ) ;
248- const {
249- MessageChannel,
250- MessagePort,
251- MessageEvent,
252- BroadcastChannel,
253- } = require ( 'internal/worker/io' ) ;
254- exposeInterface ( globalThis , 'MessageChannel' , MessageChannel ) ;
255- exposeInterface ( globalThis , 'MessagePort' , MessagePort ) ;
256- exposeInterface ( globalThis , 'MessageEvent' , MessageEvent ) ;
257- exposeInterface ( globalThis , 'BroadcastChannel' , BroadcastChannel ) ;
258-
259- // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope
260- const timers = require ( 'timers' ) ;
261- defineOperation ( globalThis , 'clearInterval' , timers . clearInterval ) ;
262- defineOperation ( globalThis , 'clearTimeout' , timers . clearTimeout ) ;
263- defineOperation ( globalThis , 'setInterval' , timers . setInterval ) ;
264- defineOperation ( globalThis , 'setTimeout' , timers . setTimeout ) ;
265-
266- defineOperation ( globalThis , 'queueMicrotask' , queueMicrotask ) ;
267-
268- // https://www.w3.org/TR/hr-time-2/#the-performance-attribute
269- defineReplacableAttribute ( globalThis , 'performance' ,
270- require ( 'perf_hooks' ) . performance ) ;
271-
272- // Non-standard extensions:
273- defineOperation ( globalThis , 'clearImmediate' , timers . clearImmediate ) ;
274- defineOperation ( globalThis , 'setImmediate' , timers . setImmediate ) ;
275-
276- const {
277- structuredClone,
278- } = require ( 'internal/structured_clone' ) ;
279- defineOperation ( globalThis , 'structuredClone' , structuredClone ) ;
280- }
222+ const {
223+ structuredClone,
224+ } = require ( 'internal/structured_clone' ) ;
225+ defineOperation ( globalThis , 'structuredClone' , structuredClone ) ;
281226
282227// Set the per-Environment callback that will be called
283228// when the TrackingTraceStateObserver updates trace state.
@@ -483,69 +428,3 @@ function setupBuffer() {
483428 } ,
484429 } ) ;
485430}
486-
487- function createGlobalConsole ( consoleFromVM ) {
488- const consoleFromNode =
489- require ( 'internal/console/global' ) ;
490- if ( config . hasInspector ) {
491- const inspector = require ( 'internal/util/inspector' ) ;
492- // This will be exposed by `require('inspector').console` later.
493- inspector . consoleFromVM = consoleFromVM ;
494- // TODO(joyeecheung): postpone this until the first time inspector
495- // is activated.
496- inspector . wrapConsole ( consoleFromNode , consoleFromVM ) ;
497- const { setConsoleExtensionInstaller } = internalBinding ( 'inspector' ) ;
498- // Setup inspector command line API.
499- setConsoleExtensionInstaller ( inspector . installConsoleExtensions ) ;
500- }
501- return consoleFromNode ;
502- }
503-
504- // https://heycam.github.io/webidl/#es-namespaces
505- function exposeNamespace ( target , name , namespaceObject ) {
506- ObjectDefineProperty ( target , name , {
507- writable : true ,
508- enumerable : false ,
509- configurable : true ,
510- value : namespaceObject
511- } ) ;
512- }
513-
514- // https://heycam.github.io/webidl/#es-interfaces
515- function exposeInterface ( target , name , interfaceObject ) {
516- ObjectDefineProperty ( target , name , {
517- writable : true ,
518- enumerable : false ,
519- configurable : true ,
520- value : interfaceObject
521- } ) ;
522- }
523-
524- function exposeGetterAndSetter ( target , name , getter , setter = undefined ) {
525- ObjectDefineProperty ( target , name , {
526- enumerable : false ,
527- configurable : true ,
528- get : getter ,
529- set : setter ,
530- } ) ;
531- }
532-
533- // https://heycam.github.io/webidl/#define-the-operations
534- function defineOperation ( target , name , method ) {
535- ObjectDefineProperty ( target , name , {
536- writable : true ,
537- enumerable : true ,
538- configurable : true ,
539- value : method
540- } ) ;
541- }
542-
543- // https://heycam.github.io/webidl/#Replaceable
544- function defineReplacableAttribute ( target , name , value ) {
545- ObjectDefineProperty ( target , name , {
546- writable : true ,
547- enumerable : true ,
548- configurable : true ,
549- value,
550- } ) ;
551- }
0 commit comments