-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: bootstrap Web [Exposed=*] APIs in the shadow realm
This is the initial work to bootstrap Web interfaces that are defined with extended attributes `[Exposed=*]`. The ShadowRealm instances are garbage-collected once it is unreachable. However, V8 can not infer the reference cycles between the per-realm strong persistent function handles and the realm's context handle. To allow the context to be gc-ed once it is not reachable, the per-realm persistent handles are attached to the context's global object and the persistent handles are set as weak.
- Loading branch information
1 parent
c2c61e0
commit b5bf1ac
Showing
26 changed files
with
669 additions
and
260 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict'; | ||
|
||
/** | ||
* This file exposes web interfaces that is defined with the WebIDL | ||
* [Exposed=*] extended attribute. | ||
* See more details at https://webidl.spec.whatwg.org/#Exposed. | ||
*/ | ||
|
||
const { | ||
globalThis, | ||
} = primordials; | ||
|
||
const { | ||
exposeInterface, | ||
lazyDOMExceptionClass, | ||
exposeLazyInterfaces, | ||
exposeGetterAndSetter, | ||
} = require('internal/util'); | ||
|
||
const { URL, URLSearchParams } = require('internal/url'); | ||
// https://url.spec.whatwg.org/#url | ||
exposeInterface(globalThis, 'URL', URL); | ||
// https://url.spec.whatwg.org/#urlsearchparams | ||
exposeInterface(globalThis, 'URLSearchParams', URLSearchParams); | ||
exposeGetterAndSetter(globalThis, | ||
'DOMException', | ||
lazyDOMExceptionClass, | ||
(value) => { | ||
exposeInterface(globalThis, 'DOMException', value); | ||
}); | ||
|
||
// https://dom.spec.whatwg.org/#interface-abortcontroller | ||
// Lazy ones. | ||
exposeLazyInterfaces(globalThis, 'internal/abort_controller', [ | ||
'AbortController', 'AbortSignal', | ||
]); | ||
// https://dom.spec.whatwg.org/#interface-eventtarget | ||
const { | ||
EventTarget, Event, | ||
} = require('internal/event_target'); | ||
exposeInterface(globalThis, 'Event', Event); | ||
exposeInterface(globalThis, 'EventTarget', EventTarget); | ||
|
||
// https://encoding.spec.whatwg.org/#textencoder | ||
// https://encoding.spec.whatwg.org/#textdecoder | ||
exposeLazyInterfaces(globalThis, | ||
'internal/encoding', | ||
['TextEncoder', 'TextDecoder']); | ||
|
||
// Web Streams API | ||
exposeLazyInterfaces( | ||
globalThis, | ||
'internal/webstreams/transformstream', | ||
['TransformStream', 'TransformStreamDefaultController']); | ||
|
||
exposeLazyInterfaces( | ||
globalThis, | ||
'internal/webstreams/writablestream', | ||
['WritableStream', 'WritableStreamDefaultController', 'WritableStreamDefaultWriter']); | ||
|
||
exposeLazyInterfaces( | ||
globalThis, | ||
'internal/webstreams/readablestream', | ||
[ | ||
'ReadableStream', 'ReadableStreamDefaultReader', | ||
'ReadableStreamBYOBReader', 'ReadableStreamBYOBRequest', | ||
'ReadableByteStreamController', 'ReadableStreamDefaultController', | ||
]); | ||
|
||
exposeLazyInterfaces( | ||
globalThis, | ||
'internal/webstreams/queuingstrategies', | ||
[ | ||
'ByteLengthQueuingStrategy', 'CountQueuingStrategy', | ||
]); | ||
|
||
exposeLazyInterfaces( | ||
globalThis, | ||
'internal/webstreams/encoding', | ||
[ | ||
'TextEncoderStream', 'TextDecoderStream', | ||
]); | ||
|
||
exposeLazyInterfaces( | ||
globalThis, | ||
'internal/webstreams/compression', | ||
[ | ||
'CompressionStream', 'DecompressionStream', | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
const { | ||
globalThis, | ||
} = primordials; | ||
|
||
const { | ||
defineOperation, | ||
defineLazyProperties, | ||
defineReplaceableLazyAttribute, | ||
exposeLazyInterfaces, | ||
exposeNamespace, | ||
} = require('internal/util'); | ||
const config = internalBinding('config'); | ||
|
||
// https://console.spec.whatwg.org/#console-namespace | ||
exposeNamespace(globalThis, 'console', | ||
createGlobalConsole()); | ||
|
||
// https://html.spec.whatwg.org/multipage/webappapis.html#windoworworkerglobalscope | ||
const timers = require('timers'); | ||
defineOperation(globalThis, 'clearInterval', timers.clearInterval); | ||
defineOperation(globalThis, 'clearTimeout', timers.clearTimeout); | ||
defineOperation(globalThis, 'setInterval', timers.setInterval); | ||
defineOperation(globalThis, 'setTimeout', timers.setTimeout); | ||
|
||
exposeLazyInterfaces(globalThis, 'internal/worker/io', [ | ||
'MessageChannel', 'MessagePort', 'MessageEvent', | ||
]); | ||
defineLazyProperties(globalThis, 'buffer', ['atob', 'btoa']); | ||
// https://www.w3.org/TR/FileAPI/#dfn-Blob | ||
exposeLazyInterfaces(globalThis, 'internal/blob', ['Blob']); | ||
// https://www.w3.org/TR/hr-time-2/#the-performance-attribute | ||
exposeLazyInterfaces(globalThis, 'perf_hooks', [ | ||
'Performance', 'PerformanceEntry', 'PerformanceMark', 'PerformanceMeasure', | ||
'PerformanceObserver', 'PerformanceObserverEntryList', 'PerformanceResourceTiming', | ||
]); | ||
|
||
defineReplaceableLazyAttribute(globalThis, 'perf_hooks', ['performance']); | ||
|
||
const { installObjectURLMethods } = require('internal/url'); | ||
installObjectURLMethods(); | ||
|
||
function createGlobalConsole() { | ||
const consoleFromNode = | ||
require('internal/console/global'); | ||
if (config.hasInspector) { | ||
const inspector = require('internal/util/inspector'); | ||
// TODO(joyeecheung): postpone this until the first time inspector | ||
// is activated. | ||
inspector.wrapConsole(consoleFromNode); | ||
const { setConsoleExtensionInstaller } = internalBinding('inspector'); | ||
// Setup inspector command line API. | ||
setConsoleExtensionInstaller(inspector.installConsoleExtensions); | ||
} | ||
return consoleFromNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.