diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2023-11-19 17:13:38 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-19 09:13:38 +0100 |
commit | c806fbdabe144c865612bbbc9ef596c9611c8310 (patch) | |
tree | edb38d58720377580677ccbeffb693ffa1225cc4 /ext/web/02_event.js | |
parent | a7548afb58b9848e501a085455446f5de897ffaa (diff) |
fix(ext,runtime): add missing custom inspections (#21219)
Diffstat (limited to 'ext/web/02_event.js')
-rw-r--r-- | ext/web/02_event.js | 189 |
1 files changed, 114 insertions, 75 deletions
diff --git a/ext/web/02_event.js b/ext/web/02_event.js index 8831d37fb..3690f62b7 100644 --- a/ext/web/02_event.js +++ b/ext/web/02_event.js @@ -158,12 +158,15 @@ class Event { }; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf(Event.prototype, this), - keys: EVENT_PROPS, - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(EventPrototype, this), + keys: EVENT_PROPS, + }), + inspectOptions, + ); } get type() { @@ -385,6 +388,8 @@ class Event { } } +const EventPrototype = Event.prototype; + // Not spec compliant. The spec defines it as [LegacyUnforgeable] // but doing so has a big performance hit ReflectDefineProperty(Event.prototype, "isTrusted", { @@ -1042,6 +1047,10 @@ class EventTarget { getParent(_event) { return null; } + + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return `${this.constructor.name} ${inspect({}, inspectOptions)}`; + } } webidl.configureInterface(EventTarget); @@ -1102,25 +1111,30 @@ class ErrorEvent extends Event { this.#error = error; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf(ErrorEvent.prototype, this), - keys: [ - ...new SafeArrayIterator(EVENT_PROPS), - "message", - "filename", - "lineno", - "colno", - "error", - ], - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(ErrorEventPrototype, this), + keys: [ + ...new SafeArrayIterator(EVENT_PROPS), + "message", + "filename", + "lineno", + "colno", + "error", + ], + }), + inspectOptions, + ); } // TODO(lucacasonato): remove when this interface is spec aligned [SymbolToStringTag] = "ErrorEvent"; } +const ErrorEventPrototype = ErrorEvent.prototype; + defineEnumerableProps(ErrorEvent, [ "message", "filename", @@ -1163,20 +1177,25 @@ class CloseEvent extends Event { this.#reason = reason; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf(CloseEvent.prototype, this), - keys: [ - ...new SafeArrayIterator(EVENT_PROPS), - "wasClean", - "code", - "reason", - ], - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(CloseEventPrototype, this), + keys: [ + ...new SafeArrayIterator(EVENT_PROPS), + "wasClean", + "code", + "reason", + ], + }), + inspectOptions, + ); } } +const CloseEventPrototype = CloseEvent.prototype; + class MessageEvent extends Event { get source() { return null; @@ -1195,23 +1214,28 @@ class MessageEvent extends Event { this.lastEventId = eventInitDict?.lastEventId ?? ""; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf(MessageEvent.prototype, this), - keys: [ - ...new SafeArrayIterator(EVENT_PROPS), - "data", - "origin", - "lastEventId", - ], - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(MessageEventPrototype, this), + keys: [ + ...new SafeArrayIterator(EVENT_PROPS), + "data", + "origin", + "lastEventId", + ], + }), + inspectOptions, + ); } // TODO(lucacasonato): remove when this interface is spec aligned [SymbolToStringTag] = "CloseEvent"; } +const MessageEventPrototype = MessageEvent.prototype; + class CustomEvent extends Event { #detail = null; @@ -1230,21 +1254,26 @@ class CustomEvent extends Event { return this.#detail; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf(CustomEvent.prototype, this), - keys: [ - ...new SafeArrayIterator(EVENT_PROPS), - "detail", - ], - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(CustomEventPrototype, this), + keys: [ + ...new SafeArrayIterator(EVENT_PROPS), + "detail", + ], + }), + inspectOptions, + ); } // TODO(lucacasonato): remove when this interface is spec aligned [SymbolToStringTag] = "CustomEvent"; } +const CustomEventPrototype = CustomEvent.prototype; + ReflectDefineProperty(CustomEvent.prototype, "detail", { enumerable: true, }); @@ -1260,23 +1289,28 @@ class ProgressEvent extends Event { this.total = eventInitDict?.total ?? 0; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf(ProgressEvent.prototype, this), - keys: [ - ...new SafeArrayIterator(EVENT_PROPS), - "lengthComputable", - "loaded", - "total", - ], - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf(ProgressEventPrototype, this), + keys: [ + ...new SafeArrayIterator(EVENT_PROPS), + "lengthComputable", + "loaded", + "total", + ], + }), + inspectOptions, + ); } // TODO(lucacasonato): remove when this interface is spec aligned [SymbolToStringTag] = "ProgressEvent"; } +const ProgressEventPrototype = ProgressEvent.prototype; + class PromiseRejectionEvent extends Event { #promise = null; #reason = null; @@ -1308,25 +1342,30 @@ class PromiseRejectionEvent extends Event { this.#reason = reason; } - [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(createFilteredInspectProxy({ - object: this, - evaluate: ObjectPrototypeIsPrototypeOf( - PromiseRejectionEvent.prototype, - this, - ), - keys: [ - ...new SafeArrayIterator(EVENT_PROPS), - "promise", - "reason", - ], - })); + [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { + return inspect( + createFilteredInspectProxy({ + object: this, + evaluate: ObjectPrototypeIsPrototypeOf( + PromiseRejectionEventPrototype, + this, + ), + keys: [ + ...new SafeArrayIterator(EVENT_PROPS), + "promise", + "reason", + ], + }), + inspectOptions, + ); } // TODO(lucacasonato): remove when this interface is spec aligned [SymbolToStringTag] = "PromiseRejectionEvent"; } +const PromiseRejectionEventPrototype = PromiseRejectionEvent.prototype; + defineEnumerableProps(PromiseRejectionEvent, [ "promise", "reason", @@ -1342,7 +1381,7 @@ function makeWrappedHandler(handler, isSpecialErrorEventHandler) { if ( isSpecialErrorEventHandler && - ObjectPrototypeIsPrototypeOf(ErrorEvent.prototype, evt) && + ObjectPrototypeIsPrototypeOf(ErrorEventPrototype, evt) && evt.type === "error" ) { const ret = FunctionPrototypeCall( |