11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst { 41cb0ef41Sopenharmony_ci ObjectDefineProperty, 51cb0ef41Sopenharmony_ci globalThis, 61cb0ef41Sopenharmony_ci} = primordials; 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst { 91cb0ef41Sopenharmony_ci defineOperation, 101cb0ef41Sopenharmony_ci exposeInterface, 111cb0ef41Sopenharmony_ci lazyDOMExceptionClass, 121cb0ef41Sopenharmony_ci defineLazyProperties, 131cb0ef41Sopenharmony_ci defineReplaceableLazyAttribute, 141cb0ef41Sopenharmony_ci exposeLazyInterfaces, 151cb0ef41Sopenharmony_ci} = require('internal/util'); 161cb0ef41Sopenharmony_ciconst config = internalBinding('config'); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci// https://console.spec.whatwg.org/#console-namespace 191cb0ef41Sopenharmony_ciexposeNamespace(globalThis, 'console', 201cb0ef41Sopenharmony_ci createGlobalConsole()); 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciconst { URL, URLSearchParams } = require('internal/url'); 231cb0ef41Sopenharmony_ci// https://url.spec.whatwg.org/#url 241cb0ef41Sopenharmony_ciexposeInterface(globalThis, 'URL', URL); 251cb0ef41Sopenharmony_ci// https://url.spec.whatwg.org/#urlsearchparams 261cb0ef41Sopenharmony_ciexposeInterface(globalThis, 'URLSearchParams', URLSearchParams); 271cb0ef41Sopenharmony_ciexposeGetterAndSetter(globalThis, 281cb0ef41Sopenharmony_ci 'DOMException', 291cb0ef41Sopenharmony_ci () => { 301cb0ef41Sopenharmony_ci const DOMException = lazyDOMExceptionClass(); 311cb0ef41Sopenharmony_ci exposeInterface(globalThis, 'DOMException', DOMException); 321cb0ef41Sopenharmony_ci return DOMException; 331cb0ef41Sopenharmony_ci }, 341cb0ef41Sopenharmony_ci (value) => { 351cb0ef41Sopenharmony_ci exposeInterface(globalThis, 'DOMException', value); 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope 391cb0ef41Sopenharmony_ciconst timers = require('timers'); 401cb0ef41Sopenharmony_cidefineOperation(globalThis, 'clearInterval', timers.clearInterval); 411cb0ef41Sopenharmony_cidefineOperation(globalThis, 'clearTimeout', timers.clearTimeout); 421cb0ef41Sopenharmony_cidefineOperation(globalThis, 'setInterval', timers.setInterval); 431cb0ef41Sopenharmony_cidefineOperation(globalThis, 'setTimeout', timers.setTimeout); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci// Lazy ones. 461cb0ef41Sopenharmony_ciexposeLazyInterfaces(globalThis, 'internal/worker/io', ['BroadcastChannel']); 471cb0ef41Sopenharmony_ciexposeLazyInterfaces(globalThis, 'internal/abort_controller', [ 481cb0ef41Sopenharmony_ci 'AbortController', 'AbortSignal', 491cb0ef41Sopenharmony_ci]); 501cb0ef41Sopenharmony_ciconst { 511cb0ef41Sopenharmony_ci EventTarget, Event, 521cb0ef41Sopenharmony_ci} = require('internal/event_target'); 531cb0ef41Sopenharmony_ciexposeInterface(globalThis, 'Event', Event); 541cb0ef41Sopenharmony_ciexposeInterface(globalThis, 'EventTarget', EventTarget); 551cb0ef41Sopenharmony_ciexposeLazyInterfaces(globalThis, 'internal/worker/io', [ 561cb0ef41Sopenharmony_ci 'MessageChannel', 'MessagePort', 'MessageEvent', 571cb0ef41Sopenharmony_ci]); 581cb0ef41Sopenharmony_cidefineLazyProperties(globalThis, 'buffer', ['atob', 'btoa']); 591cb0ef41Sopenharmony_ci// https://www.w3.org/TR/FileAPI/#dfn-Blob 601cb0ef41Sopenharmony_ciexposeLazyInterfaces(globalThis, 'internal/blob', ['Blob']); 611cb0ef41Sopenharmony_ci// https://www.w3.org/TR/hr-time-2/#the-performance-attribute 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ciexposeLazyInterfaces(globalThis, 'perf_hooks', [ 641cb0ef41Sopenharmony_ci 'Performance', 651cb0ef41Sopenharmony_ci]); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_cidefineReplaceableLazyAttribute(globalThis, 'perf_hooks', ['performance']); 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci// https://encoding.spec.whatwg.org/#textencoder 701cb0ef41Sopenharmony_ci// https://encoding.spec.whatwg.org/#textdecoder 711cb0ef41Sopenharmony_ciexposeLazyInterfaces(globalThis, 721cb0ef41Sopenharmony_ci 'internal/encoding', 731cb0ef41Sopenharmony_ci ['TextEncoder', 'TextDecoder']); 741cb0ef41Sopenharmony_ci 751cb0ef41Sopenharmony_cifunction createGlobalConsole() { 761cb0ef41Sopenharmony_ci const consoleFromNode = 771cb0ef41Sopenharmony_ci require('internal/console/global'); 781cb0ef41Sopenharmony_ci if (config.hasInspector) { 791cb0ef41Sopenharmony_ci const inspector = require('internal/util/inspector'); 801cb0ef41Sopenharmony_ci // TODO(joyeecheung): postpone this until the first time inspector 811cb0ef41Sopenharmony_ci // is activated. 821cb0ef41Sopenharmony_ci inspector.wrapConsole(consoleFromNode); 831cb0ef41Sopenharmony_ci const { setConsoleExtensionInstaller } = internalBinding('inspector'); 841cb0ef41Sopenharmony_ci // Setup inspector command line API. 851cb0ef41Sopenharmony_ci setConsoleExtensionInstaller(inspector.installConsoleExtensions); 861cb0ef41Sopenharmony_ci } 871cb0ef41Sopenharmony_ci return consoleFromNode; 881cb0ef41Sopenharmony_ci} 891cb0ef41Sopenharmony_ci 901cb0ef41Sopenharmony_ci// https://heycam.github.io/webidl/#es-namespaces 911cb0ef41Sopenharmony_cifunction exposeNamespace(target, name, namespaceObject) { 921cb0ef41Sopenharmony_ci ObjectDefineProperty(target, name, { 931cb0ef41Sopenharmony_ci __proto__: null, 941cb0ef41Sopenharmony_ci writable: true, 951cb0ef41Sopenharmony_ci enumerable: false, 961cb0ef41Sopenharmony_ci configurable: true, 971cb0ef41Sopenharmony_ci value: namespaceObject, 981cb0ef41Sopenharmony_ci }); 991cb0ef41Sopenharmony_ci} 1001cb0ef41Sopenharmony_ci 1011cb0ef41Sopenharmony_cifunction exposeGetterAndSetter(target, name, getter, setter = undefined) { 1021cb0ef41Sopenharmony_ci ObjectDefineProperty(target, name, { 1031cb0ef41Sopenharmony_ci __proto__: null, 1041cb0ef41Sopenharmony_ci enumerable: false, 1051cb0ef41Sopenharmony_ci configurable: true, 1061cb0ef41Sopenharmony_ci get: getter, 1071cb0ef41Sopenharmony_ci set: setter, 1081cb0ef41Sopenharmony_ci }); 1091cb0ef41Sopenharmony_ci} 1101cb0ef41Sopenharmony_ci 1111cb0ef41Sopenharmony_ci// Web Streams API 1121cb0ef41Sopenharmony_ciexposeLazyInterfaces( 1131cb0ef41Sopenharmony_ci globalThis, 1141cb0ef41Sopenharmony_ci 'internal/webstreams/transformstream', 1151cb0ef41Sopenharmony_ci ['TransformStream', 'TransformStreamDefaultController']); 1161cb0ef41Sopenharmony_ci 1171cb0ef41Sopenharmony_ciexposeLazyInterfaces( 1181cb0ef41Sopenharmony_ci globalThis, 1191cb0ef41Sopenharmony_ci 'internal/webstreams/writablestream', 1201cb0ef41Sopenharmony_ci ['WritableStream', 'WritableStreamDefaultController', 'WritableStreamDefaultWriter']); 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ciexposeLazyInterfaces( 1231cb0ef41Sopenharmony_ci globalThis, 1241cb0ef41Sopenharmony_ci 'internal/webstreams/readablestream', 1251cb0ef41Sopenharmony_ci [ 1261cb0ef41Sopenharmony_ci 'ReadableStream', 'ReadableStreamDefaultReader', 1271cb0ef41Sopenharmony_ci 'ReadableStreamBYOBReader', 'ReadableStreamBYOBRequest', 1281cb0ef41Sopenharmony_ci 'ReadableByteStreamController', 'ReadableStreamDefaultController', 1291cb0ef41Sopenharmony_ci ]); 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ciexposeLazyInterfaces( 1321cb0ef41Sopenharmony_ci globalThis, 1331cb0ef41Sopenharmony_ci 'internal/webstreams/queuingstrategies', 1341cb0ef41Sopenharmony_ci [ 1351cb0ef41Sopenharmony_ci 'ByteLengthQueuingStrategy', 'CountQueuingStrategy', 1361cb0ef41Sopenharmony_ci ]); 1371cb0ef41Sopenharmony_ci 1381cb0ef41Sopenharmony_ciexposeLazyInterfaces( 1391cb0ef41Sopenharmony_ci globalThis, 1401cb0ef41Sopenharmony_ci 'internal/webstreams/encoding', 1411cb0ef41Sopenharmony_ci [ 1421cb0ef41Sopenharmony_ci 'TextEncoderStream', 'TextDecoderStream', 1431cb0ef41Sopenharmony_ci ]); 1441cb0ef41Sopenharmony_ci 1451cb0ef41Sopenharmony_ciexposeLazyInterfaces( 1461cb0ef41Sopenharmony_ci globalThis, 1471cb0ef41Sopenharmony_ci 'internal/webstreams/compression', 1481cb0ef41Sopenharmony_ci [ 1491cb0ef41Sopenharmony_ci 'CompressionStream', 'DecompressionStream', 1501cb0ef41Sopenharmony_ci ]); 151