0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

experiment(ext/web): Don't expose event classes during the bootstrap phase (#16213)

This commit is contained in:
Andreu Botella 2022-10-24 16:14:17 +02:00 committed by GitHub
parent 5828ce7675
commit dbcbf53ab5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 74 additions and 49 deletions

View file

@ -8,7 +8,9 @@
const core = window.Deno.core; const core = window.Deno.core;
const ops = core.ops; const ops = core.ops;
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { defineEventHandler, setTarget } = window.__bootstrap.event; const { MessageEvent, defineEventHandler, setTarget } =
window.__bootstrap.event;
const { EventTarget } = window.__bootstrap.eventTarget;
const { DOMException } = window.__bootstrap.domException; const { DOMException } = window.__bootstrap.domException;
const { const {
ArrayPrototypeIndexOf, ArrayPrototypeIndexOf,

View file

@ -7,6 +7,7 @@
const { fromFlashRequest, toInnerResponse, _flash } = const { fromFlashRequest, toInnerResponse, _flash } =
window.__bootstrap.fetch; window.__bootstrap.fetch;
const core = window.Deno.core; const core = window.Deno.core;
const { Event } = window.__bootstrap.event;
const { const {
ReadableStream, ReadableStream,
ReadableStreamPrototype, ReadableStreamPrototype,

View file

@ -4,6 +4,7 @@
((window) => { ((window) => {
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { InnerBody } = window.__bootstrap.fetchBody; const { InnerBody } = window.__bootstrap.fetchBody;
const { Event } = window.__bootstrap.event;
const { setEventTargetData } = window.__bootstrap.eventTarget; const { setEventTargetData } = window.__bootstrap.eventTarget;
const { BlobPrototype } = window.__bootstrap.file; const { BlobPrototype } = window.__bootstrap.file;
const { const {

View file

@ -1471,19 +1471,6 @@
reportException(error); reportException(error);
} }
window[webidl.brand] = webidl.brand;
window.Event = Event;
window.EventTarget = EventTarget;
window.ErrorEvent = ErrorEvent;
window.CloseEvent = CloseEvent;
window.MessageEvent = MessageEvent;
window.CustomEvent = CustomEvent;
window.ProgressEvent = ProgressEvent;
window.PromiseRejectionEvent = PromiseRejectionEvent;
window.dispatchEvent = EventTarget.prototype.dispatchEvent;
window.addEventListener = EventTarget.prototype.addEventListener;
window.removeEventListener = EventTarget.prototype.removeEventListener;
window.reportError = reportError;
window.__bootstrap.eventTarget = { window.__bootstrap.eventTarget = {
EventTarget, EventTarget,
setEventTargetData, setEventTargetData,
@ -1494,5 +1481,13 @@
setIsTrusted, setIsTrusted,
setTarget, setTarget,
defineEventHandler, defineEventHandler,
Event,
ErrorEvent,
CloseEvent,
MessageEvent,
CustomEvent,
ProgressEvent,
PromiseRejectionEvent,
reportError,
}; };
})(this); })(this);

View file

@ -6,8 +6,8 @@
((window) => { ((window) => {
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { setIsTrusted, defineEventHandler } = window.__bootstrap.event; const { Event, setIsTrusted, defineEventHandler } = window.__bootstrap.event;
const { listenerCount } = window.__bootstrap.eventTarget; const { EventTarget, listenerCount } = window.__bootstrap.eventTarget;
const { const {
Set, Set,
SetPrototypeAdd, SetPrototypeAdd,
@ -185,9 +185,9 @@
} }
} }
window.AbortSignal = AbortSignal;
window.AbortController = AbortController;
window.__bootstrap.abortSignal = { window.__bootstrap.abortSignal = {
AbortSignal,
AbortController,
AbortSignalPrototype, AbortSignalPrototype,
add, add,
signalAbort, signalAbort,

View file

@ -5,7 +5,7 @@
/// <reference path="../../core/internal.d.ts" /> /// <reference path="../../core/internal.d.ts" />
((window) => { ((window) => {
const { EventTarget } = window; const { EventTarget } = window.__bootstrap.eventTarget;
const { const {
Symbol, Symbol,
SymbolToStringTag, SymbolToStringTag,

View file

@ -15,6 +15,8 @@
((window) => { ((window) => {
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { forgivingBase64Encode } = window.__bootstrap.infra; const { forgivingBase64Encode } = window.__bootstrap.infra;
const { ProgressEvent } = window.__bootstrap.event;
const { EventTarget } = window.__bootstrap.eventTarget;
const { decode, TextDecoder } = window.__bootstrap.encoding; const { decode, TextDecoder } = window.__bootstrap.encoding;
const { parseMimeType } = window.__bootstrap.mimesniff; const { parseMimeType } = window.__bootstrap.mimesniff;
const { DOMException } = window.__bootstrap.domException; const { DOMException } = window.__bootstrap.domException;

View file

@ -12,8 +12,8 @@
const core = window.Deno.core; const core = window.Deno.core;
const { InterruptedPrototype, ops } = core; const { InterruptedPrototype, ops } = core;
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { setEventTargetData } = window.__bootstrap.eventTarget; const { EventTarget, setEventTargetData } = window.__bootstrap.eventTarget;
const { defineEventHandler } = window.__bootstrap.event; const { MessageEvent, defineEventHandler } = window.__bootstrap.event;
const { DOMException } = window.__bootstrap.domException; const { DOMException } = window.__bootstrap.domException;
const { const {
ArrayBufferPrototype, ArrayBufferPrototype,

View file

@ -18,6 +18,7 @@
const { webidl, structuredClone } = window.__bootstrap; const { webidl, structuredClone } = window.__bootstrap;
const consoleInternal = window.__bootstrap.console; const consoleInternal = window.__bootstrap.console;
const { EventTarget } = window.__bootstrap.eventTarget;
const { opNow } = window.__bootstrap.timers; const { opNow } = window.__bootstrap.timers;
const { DOMException } = window.__bootstrap.domException; const { DOMException } = window.__bootstrap.domException;

11
ext/web/internal.d.ts vendored
View file

@ -70,6 +70,17 @@ declare namespace globalThis {
EventTarget: typeof EventTarget; EventTarget: typeof EventTarget;
}; };
declare var event: {
Event: typeof event;
ErrorEvent: typeof ErrorEvent;
CloseEvent: typeof CloseEvent;
MessageEvent: typeof MessageEvent;
CustomEvent: typeof CustomEvent;
ProgressEvent: typeof ProgressEvent;
PromiseRejectionEvent: typeof PromiseRejectionEvent;
reportError: typeof reportError;
};
declare var location: { declare var location: {
getLocationHref(): string | undefined; getLocationHref(): string | undefined;
}; };

View file

@ -10,7 +10,9 @@
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const { HTTP_TOKEN_CODE_POINT_RE } = window.__bootstrap.infra; const { HTTP_TOKEN_CODE_POINT_RE } = window.__bootstrap.infra;
const { DOMException } = window.__bootstrap.domException; const { DOMException } = window.__bootstrap.domException;
const { defineEventHandler } = window.__bootstrap.event; const { Event, ErrorEvent, CloseEvent, MessageEvent, defineEventHandler } =
window.__bootstrap.event;
const { EventTarget } = window.__bootstrap.eventTarget;
const { Blob, BlobPrototype } = globalThis.__bootstrap.file; const { Blob, BlobPrototype } = globalThis.__bootstrap.file;
const { const {
ArrayBufferPrototype, ArrayBufferPrototype,

View file

@ -2,13 +2,11 @@
"use strict"; "use strict";
((window) => { ((window) => {
const { const { ops } = Deno.core;
Event, const { Event } = window.__bootstrap.event;
EventTarget, const { EventTarget } = window.__bootstrap.eventTarget;
Deno: { core: { ops } },
__bootstrap: { webUtil: { illegalConstructorKey } },
} = window;
const { pathFromURL } = window.__bootstrap.util; const { pathFromURL } = window.__bootstrap.util;
const { illegalConstructorKey } = window.__bootstrap.webUtil;
const { const {
ArrayIsArray, ArrayIsArray,
ArrayPrototypeIncludes, ArrayPrototypeIncludes,

View file

@ -17,7 +17,9 @@
const { getLocationHref } = window.__bootstrap.location; const { getLocationHref } = window.__bootstrap.location;
const { serializePermissions } = window.__bootstrap.permissions; const { serializePermissions } = window.__bootstrap.permissions;
const { log } = window.__bootstrap.util; const { log } = window.__bootstrap.util;
const { defineEventHandler } = window.__bootstrap.event; const { ErrorEvent, MessageEvent, defineEventHandler } =
window.__bootstrap.event;
const { EventTarget } = window.__bootstrap.eventTarget;
const { const {
deserializeJsMessageData, deserializeJsMessageData,
serializeJsMessageData, serializeJsMessageData,

View file

@ -4,12 +4,14 @@
((window) => { ((window) => {
const core = window.Deno.core; const core = window.Deno.core;
const ops = core.ops; const ops = core.ops;
const { Event } = window.__bootstrap.event;
const { EventTarget } = window.__bootstrap.eventTarget;
const { const {
Error, Error,
SymbolFor, SymbolFor,
} = window.__bootstrap.primordials; } = window.__bootstrap.primordials;
const windowDispatchEvent = window.dispatchEvent.bind(window); const windowDispatchEvent = EventTarget.prototype.dispatchEvent.bind(window);
function loadavg() { function loadavg() {
return ops.op_loadavg(); return ops.op_loadavg();

View file

@ -39,6 +39,7 @@ delete Intl.v8BreakIterator;
WeakMapPrototypeSet, WeakMapPrototypeSet,
} = window.__bootstrap.primordials; } = window.__bootstrap.primordials;
const util = window.__bootstrap.util; const util = window.__bootstrap.util;
const event = window.__bootstrap.event;
const eventTarget = window.__bootstrap.eventTarget; const eventTarget = window.__bootstrap.eventTarget;
const globalInterfaces = window.__bootstrap.globalInterfaces; const globalInterfaces = window.__bootstrap.globalInterfaces;
const location = window.__bootstrap.location; const location = window.__bootstrap.location;
@ -78,6 +79,7 @@ delete Intl.v8BreakIterator;
const errors = window.__bootstrap.errors.errors; const errors = window.__bootstrap.errors.errors;
const webidl = window.__bootstrap.webidl; const webidl = window.__bootstrap.webidl;
const domException = window.__bootstrap.domException; const domException = window.__bootstrap.domException;
const abortSignal = window.__bootstrap.abortSignal;
const { defineEventHandler, reportException } = window.__bootstrap.event; const { defineEventHandler, reportException } = window.__bootstrap.event;
const { deserializeJsMessageData, serializeJsMessageData } = const { deserializeJsMessageData, serializeJsMessageData } =
window.__bootstrap.messagePort; window.__bootstrap.messagePort;
@ -156,7 +158,7 @@ delete Intl.v8BreakIterator;
const message = v[0]; const message = v[0];
const transferables = v[1]; const transferables = v[1];
const msgEvent = new MessageEvent("message", { const msgEvent = new event.MessageEvent("message", {
cancelable: false, cancelable: false,
data: message, data: message,
ports: transferables.filter((t) => ports: transferables.filter((t) =>
@ -167,7 +169,7 @@ delete Intl.v8BreakIterator;
try { try {
globalDispatchEvent(msgEvent); globalDispatchEvent(msgEvent);
} catch (e) { } catch (e) {
const errorEvent = new ErrorEvent("error", { const errorEvent = new event.ErrorEvent("error", {
cancelable: true, cancelable: true,
message: e.message, message: e.message,
lineno: e.lineNumber ? e.lineNumber + 1 : undefined, lineno: e.lineNumber ? e.lineNumber + 1 : undefined,
@ -432,33 +434,35 @@ delete Intl.v8BreakIterator;
// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope // https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope
const windowOrWorkerGlobalScope = { const windowOrWorkerGlobalScope = {
AbortController: util.nonEnumerable(abortSignal.AbortController),
AbortSignal: util.nonEnumerable(abortSignal.AbortSignal),
Blob: util.nonEnumerable(file.Blob), Blob: util.nonEnumerable(file.Blob),
ByteLengthQueuingStrategy: util.nonEnumerable( ByteLengthQueuingStrategy: util.nonEnumerable(
streams.ByteLengthQueuingStrategy, streams.ByteLengthQueuingStrategy,
), ),
CloseEvent: util.nonEnumerable(CloseEvent), CloseEvent: util.nonEnumerable(event.CloseEvent),
CompressionStream: util.nonEnumerable(compression.CompressionStream), CompressionStream: util.nonEnumerable(compression.CompressionStream),
CountQueuingStrategy: util.nonEnumerable( CountQueuingStrategy: util.nonEnumerable(
streams.CountQueuingStrategy, streams.CountQueuingStrategy,
), ),
CryptoKey: util.nonEnumerable(crypto.CryptoKey), CryptoKey: util.nonEnumerable(crypto.CryptoKey),
CustomEvent: util.nonEnumerable(CustomEvent), CustomEvent: util.nonEnumerable(event.CustomEvent),
DecompressionStream: util.nonEnumerable(compression.DecompressionStream), DecompressionStream: util.nonEnumerable(compression.DecompressionStream),
DOMException: util.nonEnumerable(domException.DOMException), DOMException: util.nonEnumerable(domException.DOMException),
ErrorEvent: util.nonEnumerable(ErrorEvent), ErrorEvent: util.nonEnumerable(event.ErrorEvent),
Event: util.nonEnumerable(Event), Event: util.nonEnumerable(event.Event),
EventTarget: util.nonEnumerable(EventTarget), EventTarget: util.nonEnumerable(eventTarget.EventTarget),
File: util.nonEnumerable(file.File), File: util.nonEnumerable(file.File),
FileReader: util.nonEnumerable(fileReader.FileReader), FileReader: util.nonEnumerable(fileReader.FileReader),
FormData: util.nonEnumerable(formData.FormData), FormData: util.nonEnumerable(formData.FormData),
Headers: util.nonEnumerable(headers.Headers), Headers: util.nonEnumerable(headers.Headers),
MessageEvent: util.nonEnumerable(MessageEvent), MessageEvent: util.nonEnumerable(event.MessageEvent),
Performance: util.nonEnumerable(performance.Performance), Performance: util.nonEnumerable(performance.Performance),
PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry), PerformanceEntry: util.nonEnumerable(performance.PerformanceEntry),
PerformanceMark: util.nonEnumerable(performance.PerformanceMark), PerformanceMark: util.nonEnumerable(performance.PerformanceMark),
PerformanceMeasure: util.nonEnumerable(performance.PerformanceMeasure), PerformanceMeasure: util.nonEnumerable(performance.PerformanceMeasure),
PromiseRejectionEvent: util.nonEnumerable(PromiseRejectionEvent), PromiseRejectionEvent: util.nonEnumerable(event.PromiseRejectionEvent),
ProgressEvent: util.nonEnumerable(ProgressEvent), ProgressEvent: util.nonEnumerable(event.ProgressEvent),
ReadableStream: util.nonEnumerable(streams.ReadableStream), ReadableStream: util.nonEnumerable(streams.ReadableStream),
ReadableStreamDefaultReader: util.nonEnumerable( ReadableStreamDefaultReader: util.nonEnumerable(
streams.ReadableStreamDefaultReader, streams.ReadableStreamDefaultReader,
@ -518,9 +522,12 @@ delete Intl.v8BreakIterator;
SubtleCrypto: util.nonEnumerable(crypto.SubtleCrypto), SubtleCrypto: util.nonEnumerable(crypto.SubtleCrypto),
fetch: util.writable(fetch.fetch), fetch: util.writable(fetch.fetch),
performance: util.writable(performance.performance), performance: util.writable(performance.performance),
reportError: util.writable(event.reportError),
setInterval: util.writable(timers.setInterval), setInterval: util.writable(timers.setInterval),
setTimeout: util.writable(timers.setTimeout), setTimeout: util.writable(timers.setTimeout),
structuredClone: util.writable(messagePort.structuredClone), structuredClone: util.writable(messagePort.structuredClone),
// Branding as a WebIDL object
[webidl.brand]: util.nonEnumerable(webidl.brand),
}; };
const unstableWindowOrWorkerGlobalScope = { const unstableWindowOrWorkerGlobalScope = {
@ -648,11 +655,14 @@ delete Intl.v8BreakIterator;
continue; continue;
} }
const event = new PromiseRejectionEvent("unhandledrejection", { const rejectionEvent = new event.PromiseRejectionEvent(
cancelable: true, "unhandledrejection",
promise, {
reason, cancelable: true,
}); promise,
reason,
},
);
const errorEventCb = (event) => { const errorEventCb = (event) => {
if (event.error === reason) { if (event.error === reason) {
@ -663,12 +673,12 @@ delete Intl.v8BreakIterator;
// if error is thrown during dispatch of "unhandledrejection" // if error is thrown during dispatch of "unhandledrejection"
// event. // event.
globalThis.addEventListener("error", errorEventCb); globalThis.addEventListener("error", errorEventCb);
globalThis.dispatchEvent(event); globalThis.dispatchEvent(rejectionEvent);
globalThis.removeEventListener("error", errorEventCb); globalThis.removeEventListener("error", errorEventCb);
// If event was not prevented (or "unhandledrejection" listeners didn't // If event was not prevented (or "unhandledrejection" listeners didn't
// throw) we will let Rust side handle it. // throw) we will let Rust side handle it.
if (event.defaultPrevented) { if (rejectionEvent.defaultPrevented) {
ops.op_remove_pending_promise_exception(promise); ops.op_remove_pending_promise_exception(promise);
} }
} }

View file

@ -1132,9 +1132,7 @@
"Event interface: calling initEvent(DOMString, optional boolean, optional boolean) on new CustomEvent(\"foo\") with too few arguments must throw TypeError", "Event interface: calling initEvent(DOMString, optional boolean, optional boolean) on new CustomEvent(\"foo\") with too few arguments must throw TypeError",
"EventTarget interface: operation addEventListener(DOMString, EventListener?, optional (AddEventListenerOptions or boolean))", "EventTarget interface: operation addEventListener(DOMString, EventListener?, optional (AddEventListenerOptions or boolean))",
"EventTarget interface: operation removeEventListener(DOMString, EventListener?, optional (EventListenerOptions or boolean))", "EventTarget interface: operation removeEventListener(DOMString, EventListener?, optional (EventListenerOptions or boolean))",
"AbortController interface: existence and properties of interface object",
"AbortController interface: operation abort(optional any)", "AbortController interface: operation abort(optional any)",
"AbortSignal interface: existence and properties of interface object",
"AbortSignal interface: operation abort(optional any)", "AbortSignal interface: operation abort(optional any)",
"AbortSignal interface: operation timeout(unsigned long long)", "AbortSignal interface: operation timeout(unsigned long long)",
"AbortSignal interface: attribute onabort" "AbortSignal interface: attribute onabort"