diff options
Diffstat (limited to 'extensions/web')
-rw-r--r-- | extensions/web/01_dom_exception.js | 17 | ||||
-rw-r--r-- | extensions/web/02_event.js | 127 | ||||
-rw-r--r-- | extensions/web/06_streams.js | 69 | ||||
-rw-r--r-- | extensions/web/09_file.js | 10 |
4 files changed, 126 insertions, 97 deletions
diff --git a/extensions/web/01_dom_exception.js b/extensions/web/01_dom_exception.js index 90ddb267b..3e282d969 100644 --- a/extensions/web/01_dom_exception.js +++ b/extensions/web/01_dom_exception.js @@ -17,6 +17,7 @@ ObjectSetPrototypeOf, } = window.__bootstrap.primordials; const webidl = window.__bootstrap.webidl; + const consoleInternal = window.__bootstrap.console; // Defined in WebIDL 4.3. // https://heycam.github.io/webidl/#idl-DOMException @@ -109,8 +110,20 @@ return "DOMException"; } - [Symbol.for("Deno.customInspect")]() { - return `DOMException: ${this.#message}`; + [Symbol.for("Deno.customInspect")](inspect) { + if (this instanceof DOMException) { + return `DOMException: ${this.#message}`; + } else { + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: false, + keys: [ + "message", + "name", + "code", + ], + })); + } } } diff --git a/extensions/web/02_event.js b/extensions/web/02_event.js index 4ae8b50f2..6b2cc2c04 100644 --- a/extensions/web/02_event.js +++ b/extensions/web/02_event.js @@ -9,6 +9,7 @@ ((window) => { const webidl = window.__bootstrap.webidl; const { DOMException } = window.__bootstrap.domException; + const consoleInternal = window.__bootstrap.console; const { ArrayPrototypeFilter, ArrayPrototypeIncludes, @@ -28,10 +29,7 @@ ObjectCreate, ObjectDefineProperty, ObjectGetOwnPropertyDescriptor, - Proxy, ReflectDefineProperty, - ReflectGet, - ReflectGetOwnPropertyDescriptor, Symbol, SymbolFor, SymbolToStringTag, @@ -175,7 +173,11 @@ } [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(buildFilteredPropertyInspectObject(this, EVENT_PROPS)); + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof Event, + keys: EVENT_PROPS, + })); } get type() { @@ -397,43 +399,6 @@ } } - function buildFilteredPropertyInspectObject(object, keys) { - // forward the subset of properties from `object` without evaluating - // as evaluation could lead to an error, which is better handled - // in the inspect code - return new Proxy({}, { - get(_target, key) { - if (key === SymbolToStringTag) { - return object.constructor?.name; - } else if (ArrayPrototypeIncludes(keys, key)) { - return ReflectGet(object, key); - } else { - return undefined; - } - }, - getOwnPropertyDescriptor(_target, key) { - if (!ArrayPrototypeIncludes(keys, key)) { - return undefined; - } - - return ReflectGetOwnPropertyDescriptor(object, key) ?? - (object.prototype && - ReflectGetOwnPropertyDescriptor(object.prototype, key)) ?? - { - configurable: true, - enumerable: true, - value: object[key], - }; - }, - has(_target, key) { - return ArrayPrototypeIncludes(keys, key); - }, - ownKeys() { - return keys; - }, - }); - } - function defineEnumerableProps( Ctor, props, @@ -1097,14 +1062,18 @@ } [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(buildFilteredPropertyInspectObject(this, [ - ...EVENT_PROPS, - "message", - "filename", - "lineno", - "colno", - "error", - ])); + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof ErrorEvent, + keys: [ + ...EVENT_PROPS, + "message", + "filename", + "lineno", + "colno", + "error", + ], + })); } } @@ -1151,12 +1120,16 @@ } [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(buildFilteredPropertyInspectObject(this, [ - ...EVENT_PROPS, - "wasClean", - "code", - "reason", - ])); + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof CloseEvent, + keys: [ + ...EVENT_PROPS, + "wasClean", + "code", + "reason", + ], + })); } } @@ -1179,12 +1152,16 @@ } [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(buildFilteredPropertyInspectObject(this, [ - ...EVENT_PROPS, - "data", - "origin", - "lastEventId", - ])); + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof MessageEvent, + keys: [ + ...EVENT_PROPS, + "data", + "origin", + "lastEventId", + ], + })); } } @@ -1209,10 +1186,14 @@ } [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(buildFilteredPropertyInspectObject(this, [ - ...EVENT_PROPS, - "detail", - ])); + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof CustomEvent, + keys: [ + ...EVENT_PROPS, + "detail", + ], + })); } } @@ -1232,12 +1213,16 @@ } [SymbolFor("Deno.privateCustomInspect")](inspect) { - return inspect(buildFilteredPropertyInspectObject(this, [ - ...EVENT_PROPS, - "lengthComputable", - "loaded", - "total", - ])); + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof ProgressEvent, + keys: [ + ...EVENT_PROPS, + "lengthComputable", + "loaded", + "total", + ], + })); } } diff --git a/extensions/web/06_streams.js b/extensions/web/06_streams.js index 388b7b13c..ff6c9d7d8 100644 --- a/extensions/web/06_streams.js +++ b/extensions/web/06_streams.js @@ -36,6 +36,7 @@ WeakMapPrototypeHas, WeakMapPrototypeSet, } = globalThis.__bootstrap.primordials; + const consoleInternal = window.__bootstrap.console; const { DOMException } = window.__bootstrap.domException; class AssertionError extends Error { @@ -3018,9 +3019,14 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${ - inspect({ highWaterMark: this.highWaterMark, size: this.size }) - }`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof ByteLengthQueuingStrategy, + keys: [ + "highWaterMark", + "size", + ], + })); } get [Symbol.toStringTag]() { @@ -3069,9 +3075,14 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${ - inspect({ highWaterMark: this.highWaterMark, size: this.size }) - }`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof CountQueuingStrategy, + keys: [ + "highWaterMark", + "size", + ], + })); } get [Symbol.toStringTag]() { @@ -3561,9 +3572,11 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${ - inspect({ desiredSize: this.desiredSize }) - }`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof ReadableByteStreamController, + keys: ["desiredSize"], + })); } get [Symbol.toStringTag]() { @@ -3684,9 +3697,11 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${ - inspect({ desiredSize: this.desiredSize }) - }`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof ReadableStreamDefaultController, + keys: ["desiredSize"], + })); } get [Symbol.toStringTag]() { @@ -3905,9 +3920,11 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${ - inspect({ desiredSize: this.desiredSize }) - }`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof TransformStreamDefaultController, + keys: ["desiredSize"], + })); } get [Symbol.toStringTag]() { @@ -4182,13 +4199,15 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${ - inspect({ - closed: this.closed, - desiredSize: this.desiredSize, - ready: this.ready, - }) - }`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof WritableStreamDefaultWriter, + keys: [ + "closed", + "desiredSize", + "ready", + ], + })); } get [Symbol.toStringTag]() { @@ -4240,7 +4259,11 @@ } [Symbol.for("Deno.customInspect")](inspect) { - return `${this.constructor.name} ${inspect({})}`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof WritableStreamDefaultController, + keys: [], + })); } get [Symbol.toStringTag]() { diff --git a/extensions/web/09_file.js b/extensions/web/09_file.js index a39b380a6..516e80adf 100644 --- a/extensions/web/09_file.js +++ b/extensions/web/09_file.js @@ -34,6 +34,7 @@ TypeError, Uint8Array, } = window.__bootstrap.primordials; + const consoleInternal = window.__bootstrap.console; // TODO(lucacasonato): this needs to not be hardcoded and instead depend on // host os. @@ -362,7 +363,14 @@ } [SymbolFor("Deno.customInspect")](inspect) { - return `Blob ${inspect({ size: this.size, type: this.#type })}`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof Blob, + keys: [ + "size", + "type", + ], + })); } } |