1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -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 ops = core.ops;
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 {
ArrayPrototypeIndexOf,

View file

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

View file

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

View file

@ -1471,19 +1471,6 @@
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 = {
EventTarget,
setEventTargetData,
@ -1494,5 +1481,13 @@
setIsTrusted,
setTarget,
defineEventHandler,
Event,
ErrorEvent,
CloseEvent,
MessageEvent,
CustomEvent,
ProgressEvent,
PromiseRejectionEvent,
reportError,
};
})(this);

View file

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

View file

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

View file

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

View file

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

View file

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

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

@ -70,6 +70,17 @@ declare namespace globalThis {
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: {
getLocationHref(): string | undefined;
};

View file

@ -10,7 +10,9 @@
const webidl = window.__bootstrap.webidl;
const { HTTP_TOKEN_CODE_POINT_RE } = window.__bootstrap.infra;
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 {
ArrayBufferPrototype,

View file

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

View file

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

View file

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

View file

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