| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d0153ae commit 41b1867
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,21 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + /** | ||
| 4 | + * This file exposes web interfaces that is defined with the WebIDL | ||
| 5 | + * [Exposed=*] extended attribute. | ||
| 6 | + * See more details at https://webidl.spec.whatwg.org/#Exposed. | ||
| 7 | + */ | ||
| 8 | + | ||
| 3 | 9 | const { | |
| 4 | - ObjectDefineProperty, | ||
| 5 | 10 | globalThis, | |
| 6 | 11 | } = primordials; | |
| 7 | 12 | ||
| 8 | 13 | const { | |
| 9 | - defineOperation, | ||
| 10 | 14 | exposeInterface, | |
| 11 | 15 | lazyDOMExceptionClass, | |
| 12 | - defineLazyProperties, | ||
| 13 | - defineReplaceableLazyAttribute, | ||
| 14 | 16 | exposeLazyInterfaces, | |
| 17 | + exposeGetterAndSetter, | ||
| 18 | + exposeNamespace, | ||
| 15 | 19 | } = require('internal/util'); | |
| 16 | 20 | const config = internalBinding('config'); | |
| 17 | 21 | ||
@@ -35,36 +39,17 @@ exposeGetterAndSetter(globalThis, | |||
| 35 | 39 | exposeInterface(globalThis, 'DOMException', value); | |
| 36 | 40 | }); | |
| 37 | 41 | ||
| 38 | - // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope | ||
| 39 | - const timers = require('timers'); | ||
| 40 | - defineOperation(globalThis, 'clearInterval', timers.clearInterval); | ||
| 41 | - defineOperation(globalThis, 'clearTimeout', timers.clearTimeout); | ||
| 42 | - defineOperation(globalThis, 'setInterval', timers.setInterval); | ||
| 43 | - defineOperation(globalThis, 'setTimeout', timers.setTimeout); | ||
| 44 | - | ||
| 42 | + // https://dom.spec.whatwg.org/#interface-abortcontroller | ||
| 45 | 43 | // Lazy ones. | |
| 46 | - exposeLazyInterfaces(globalThis, 'internal/worker/io', ['BroadcastChannel']); | ||
| 47 | 44 | exposeLazyInterfaces(globalThis, 'internal/abort_controller', [ | |
| 48 | 45 | 'AbortController', 'AbortSignal', | |
| 49 | 46 | ]); | |
| 47 | + // https://dom.spec.whatwg.org/#interface-eventtarget | ||
| 50 | 48 | const { | |
| 51 | 49 | EventTarget, Event, | |
| 52 | 50 | } = require('internal/event_target'); | |
| 53 | 51 | exposeInterface(globalThis, 'Event', Event); | |
| 54 | 52 | exposeInterface(globalThis, 'EventTarget', EventTarget); | |
| 55 | - exposeLazyInterfaces(globalThis, 'internal/worker/io', [ | ||
| 56 | - 'MessageChannel', 'MessagePort', 'MessageEvent', | ||
| 57 | - ]); | ||
| 58 | - defineLazyProperties(globalThis, 'buffer', ['atob', 'btoa']); | ||
| 59 | - // https://www.w3.org/TR/FileAPI/#dfn-Blob | ||
| 60 | - exposeLazyInterfaces(globalThis, 'internal/blob', ['Blob']); | ||
| 61 | - // https://www.w3.org/TR/hr-time-2/#the-performance-attribute | ||
| 62 | - exposeLazyInterfaces(globalThis, 'perf_hooks', [ | ||
| 63 | - 'Performance', 'PerformanceEntry', 'PerformanceMark', 'PerformanceMeasure', | ||
| 64 | - 'PerformanceObserver', 'PerformanceObserverEntryList', 'PerformanceResourceTiming', | ||
| 65 | - ]); | ||
| 66 | - | ||
| 67 | - defineReplaceableLazyAttribute(globalThis, 'perf_hooks', ['performance']); | ||
| 68 | 53 | ||
| 69 | 54 | // https://encoding.spec.whatwg.org/#textencoder | |
| 70 | 55 | // https://encoding.spec.whatwg.org/#textdecoder | |
@@ -87,27 +72,6 @@ function createGlobalConsole() { | |||
| 87 | 72 | return consoleFromNode; | |
| 88 | 73 | } | |
| 89 | 74 | ||
| 90 | - // https://heycam.github.io/webidl/#es-namespaces | ||
| 91 | - function exposeNamespace(target, name, namespaceObject) { | ||
| 92 | - ObjectDefineProperty(target, name, { | ||
| 93 | - __proto__: null, | ||
| 94 | - writable: true, | ||
| 95 | - enumerable: false, | ||
| 96 | - configurable: true, | ||
| 97 | - value: namespaceObject, | ||
| 98 | - }); | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - function exposeGetterAndSetter(target, name, getter, setter = undefined) { | ||
| 102 | - ObjectDefineProperty(target, name, { | ||
| 103 | - __proto__: null, | ||
| 104 | - enumerable: false, | ||
| 105 | - configurable: true, | ||
| 106 | - get: getter, | ||
| 107 | - set: setter, | ||
| 108 | - }); | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | 75 | // Web Streams API | |
| 112 | 76 | exposeLazyInterfaces( | |
| 113 | 77 | globalThis, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,47 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + /** | ||
| 4 | + * This file exposes web interfaces that is defined with the WebIDL | ||
| 5 | + * Exposed=(Window,Worker) extended attribute or exposed in | ||
| 6 | + * WindowOrWorkerGlobalScope mixin. | ||
| 7 | + * See more details at https://webidl.spec.whatwg.org/#Exposed and | ||
| 8 | + * https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | + const { | ||
| 12 | + globalThis, | ||
| 13 | + } = primordials; | ||
| 14 | + | ||
| 15 | + const { | ||
| 16 | + defineOperation, | ||
| 17 | + defineLazyProperties, | ||
| 18 | + defineReplaceableLazyAttribute, | ||
| 19 | + exposeLazyInterfaces, | ||
| 20 | + } = require('internal/util'); | ||
| 21 | + | ||
| 22 | + // https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope | ||
| 23 | + const timers = require('timers'); | ||
| 24 | + defineOperation(globalThis, 'clearInterval', timers.clearInterval); | ||
| 25 | + defineOperation(globalThis, 'clearTimeout', timers.clearTimeout); | ||
| 26 | + defineOperation(globalThis, 'setInterval', timers.setInterval); | ||
| 27 | + defineOperation(globalThis, 'setTimeout', timers.setTimeout); | ||
| 28 | + | ||
| 29 | + // https://html.spec.whatwg.org/multipage/web-messaging.html#broadcasting-to-other-browsing-contexts | ||
| 30 | + exposeLazyInterfaces(globalThis, 'internal/worker/io', ['BroadcastChannel']); | ||
| 31 | + exposeLazyInterfaces(globalThis, 'internal/worker/io', [ | ||
| 32 | + 'MessageChannel', 'MessagePort', 'MessageEvent', | ||
| 33 | + ]); | ||
| 34 | + defineLazyProperties(globalThis, 'buffer', ['atob', 'btoa']); | ||
| 35 | + // https://www.w3.org/TR/FileAPI/#dfn-Blob | ||
| 36 | + exposeLazyInterfaces(globalThis, 'internal/blob', ['Blob']); | ||
| 37 | + // https://www.w3.org/TR/hr-time-2/#the-performance-attribute | ||
| 38 | + exposeLazyInterfaces(globalThis, 'perf_hooks', [ | ||
| 39 | + 'Performance', 'PerformanceEntry', 'PerformanceMark', 'PerformanceMeasure', | ||
| 40 | + 'PerformanceObserver', 'PerformanceObserverEntryList', 'PerformanceResourceTiming', | ||
| 41 | + ]); | ||
| 42 | + | ||
| 43 | + defineReplaceableLazyAttribute(globalThis, 'perf_hooks', ['performance']); | ||
| 44 | + | ||
| 45 | + // https://w3c.github.io/FileAPI/#creating-revoking | ||
| 46 | + const { installObjectURLMethods } = require('internal/url'); | ||
| 47 | + installObjectURLMethods(); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -268,7 +268,7 @@ function setupFetch() { | |||
| 268 | 268 | }); | |
| 269 | 269 | } | |
| 270 | 270 | ||
| 271 | - // TODO(aduh95): move this to internal/bootstrap/browser when the CLI flag is | ||
| 271 | + // TODO(aduh95): move this to internal/bootstrap/web/* when the CLI flag is | ||
| 272 | 272 | // removed. | |
| 273 | 273 | function setupWebCrypto() { | |
| 274 | 274 | if (process.config.variables.node_no_browser_globals || | |
@@ -316,7 +316,7 @@ function setupCodeCoverage() { | |||
| 316 | 316 | } | |
| 317 | 317 | } | |
| 318 | 318 | ||
| 319 | - // TODO(daeyeon): move this to internal/bootstrap/browser when the CLI flag is | ||
| 319 | + // TODO(daeyeon): move this to internal/bootstrap/web/* when the CLI flag is | ||
| 320 | 320 | // removed. | |
| 321 | 321 | function setupCustomEvent() { | |
| 322 | 322 | if (process.config.variables.node_no_browser_globals || | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -91,11 +91,6 @@ const { | |||
| 91 | 91 | updateUrl, | |
| 92 | 92 | } = internalBinding('url'); | |
| 93 | 93 | ||
| 94 | - const { | ||
| 95 | - storeDataObject, | ||
| 96 | - revokeDataObject, | ||
| 97 | - } = internalBinding('blob'); | ||
| 98 | - | ||
| 99 | 94 | const FORWARD_SLASH = /\//g; | |
| 100 | 95 | ||
| 101 | 96 | const context = Symbol('context'); | |
@@ -718,8 +713,33 @@ class URL { | |||
| 718 | 713 | toJSON() { | |
| 719 | 714 | return this.#context.href; | |
| 720 | 715 | } | |
| 716 | + } | ||
| 717 | + | ||
| 718 | + ObjectDefineProperties(URL.prototype, { | ||
| 719 | + [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URL' }, | ||
| 720 | + toString: kEnumerableProperty, | ||
| 721 | + href: kEnumerableProperty, | ||
| 722 | + origin: kEnumerableProperty, | ||
| 723 | + protocol: kEnumerableProperty, | ||
| 724 | + username: kEnumerableProperty, | ||
| 725 | + password: kEnumerableProperty, | ||
| 726 | + host: kEnumerableProperty, | ||
| 727 | + hostname: kEnumerableProperty, | ||
| 728 | + port: kEnumerableProperty, | ||
| 729 | + pathname: kEnumerableProperty, | ||
| 730 | + search: kEnumerableProperty, | ||
| 731 | + searchParams: kEnumerableProperty, | ||
| 732 | + hash: kEnumerableProperty, | ||
| 733 | + toJSON: kEnumerableProperty, | ||
| 734 | + }); | ||
| 735 | + | ||
| 736 | + function installObjectURLMethods() { | ||
| 737 | + const { | ||
| 738 | + storeDataObject, | ||
| 739 | + revokeDataObject, | ||
| 740 | + } = internalBinding('blob'); | ||
| 721 | 741 | ||
| 722 | - static createObjectURL(obj) { | ||
| 742 | + function createObjectURL(obj) { | ||
| 723 | 743 | const cryptoRandom = lazyCryptoRandom(); | |
| 724 | 744 | if (cryptoRandom === undefined) | |
| 725 | 745 | throw new ERR_NO_CRYPTO(); | |
@@ -735,7 +755,7 @@ class URL { | |||
| 735 | 755 | return `blob:nodedata:${id}`; | |
| 736 | 756 | } | |
| 737 | 757 | ||
| 738 | - static revokeObjectURL(url) { | ||
| 758 | + function revokeObjectURL(url) { | ||
| 739 | 759 | url = `${url}`; | |
| 740 | 760 | try { | |
| 741 | 761 | // TODO(@anonrig): Remove this try/catch by calling `parse` directly. | |
@@ -747,30 +767,24 @@ class URL { | |||
| 747 | 767 | // If there's an error, it's ignored. | |
| 748 | 768 | } | |
| 749 | 769 | } | |
| 750 | - } | ||
| 751 | - | ||
| 752 | - ObjectDefineProperties(URL.prototype, { | ||
| 753 | - [SymbolToStringTag]: { __proto__: null, configurable: true, value: 'URL' }, | ||
| 754 | - toString: kEnumerableProperty, | ||
| 755 | - href: kEnumerableProperty, | ||
| 756 | - origin: kEnumerableProperty, | ||
| 757 | - protocol: kEnumerableProperty, | ||
| 758 | - username: kEnumerableProperty, | ||
| 759 | - password: kEnumerableProperty, | ||
| 760 | - host: kEnumerableProperty, | ||
| 761 | - hostname: kEnumerableProperty, | ||
| 762 | - port: kEnumerableProperty, | ||
| 763 | - pathname: kEnumerableProperty, | ||
| 764 | - search: kEnumerableProperty, | ||
| 765 | - searchParams: kEnumerableProperty, | ||
| 766 | - hash: kEnumerableProperty, | ||
| 767 | - toJSON: kEnumerableProperty, | ||
| 768 | - }); | ||
| 769 | 770 | ||
| 770 | - ObjectDefineProperties(URL, { | ||
| 771 | - createObjectURL: kEnumerableProperty, | ||
| 772 | - revokeObjectURL: kEnumerableProperty, | ||
| 773 | - }); | ||
| 771 | + ObjectDefineProperties(URL, { | ||
| 772 | + createObjectURL: { | ||
| 773 | + __proto__: null, | ||
| 774 | + configurable: true, | ||
| 775 | + writable: true, | ||
| 776 | + enumerable: true, | ||
| 777 | + value: createObjectURL, | ||
| 778 | + }, | ||
| 779 | + revokeObjectURL: { | ||
| 780 | + __proto__: null, | ||
| 781 | + configurable: true, | ||
| 782 | + writable: true, | ||
| 783 | + enumerable: true, | ||
| 784 | + value: revokeObjectURL, | ||
| 785 | + }, | ||
| 786 | + }); | ||
| 787 | + } | ||
| 774 | 788 | ||
| 775 | 789 | // application/x-www-form-urlencoded parser | |
| 776 | 790 | // Ref: https://url.spec.whatwg.org/#concept-urlencoded-parser | |
@@ -1251,6 +1265,7 @@ module.exports = { | |||
| 1251 | 1265 | fileURLToPath, | |
| 1252 | 1266 | pathToFileURL, | |
| 1253 | 1267 | toPathIfFileURL, | |
| 1268 | + installObjectURLMethods, | ||
| 1254 | 1269 | URL, | |
| 1255 | 1270 | URLSearchParams, | |
| 1256 | 1271 | domainToASCII, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -511,6 +511,27 @@ function exposeInterface(target, name, interfaceObject) { | |||
| 511 | 511 | }); | |
| 512 | 512 | } | |
| 513 | 513 | ||
| 514 | + // https://heycam.github.io/webidl/#es-namespaces | ||
| 515 | + function exposeNamespace(target, name, namespaceObject) { | ||
| 516 | + ObjectDefineProperty(target, name, { | ||
| 517 | + __proto__: null, | ||
| 518 | + writable: true, | ||
| 519 | + enumerable: false, | ||
| 520 | + configurable: true, | ||
| 521 | + value: namespaceObject, | ||
| 522 | + }); | ||
| 523 | + } | ||
| 524 | + | ||
| 525 | + function exposeGetterAndSetter(target, name, getter, setter = undefined) { | ||
| 526 | + ObjectDefineProperty(target, name, { | ||
| 527 | + __proto__: null, | ||
| 528 | + enumerable: false, | ||
| 529 | + configurable: true, | ||
| 530 | + get: getter, | ||
| 531 | + set: setter, | ||
| 532 | + }); | ||
| 533 | + } | ||
| 534 | + | ||
| 514 | 535 | function defineLazyProperties(target, id, keys, enumerable = true) { | |
| 515 | 536 | const descriptors = { __proto__: null }; | |
| 516 | 537 | let mod; | |
@@ -750,6 +771,8 @@ module.exports = { | |||
| 750 | 771 | emitExperimentalWarning, | |
| 751 | 772 | exposeInterface, | |
| 752 | 773 | exposeLazyInterfaces, | |
| 774 | + exposeNamespace, | ||
| 775 | + exposeGetterAndSetter, | ||
| 753 | 776 | filterDuplicateStrings, | |
| 754 | 777 | filterOwnProperties, | |
| 755 | 778 | getConstructorOf, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -218,9 +218,10 @@ MaybeLocal<Value> Realm::BootstrapNode() { | |||
| 218 | 218 | } | |
| 219 | 219 | ||
| 220 | 220 | if (!env_->no_browser_globals()) { | |
| 221 | - result = ExecuteBootstrapper("internal/bootstrap/browser"); | ||
| 222 | - | ||
| 223 | - if (result.IsEmpty()) { | ||
| 221 | + if (ExecuteBootstrapper("internal/bootstrap/web/exposed-wildcard") | ||
| 222 | + .IsEmpty() || | ||
| 223 | + ExecuteBootstrapper("internal/bootstrap/web/exposed-window-or-worker") | ||
| 224 | + .IsEmpty()) { | ||
| 224 | 225 | return MaybeLocal<Value>(); | |
| 225 | 226 | } | |
| 226 | 227 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments