From 5fa58c92165e23386b8ed3c3079103997fe1bef9 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 8 Jul 2021 09:43:36 -0400 Subject: fix: inspecting prototypes of built-ins with custom inspect implementations should not throw (#11308) --- extensions/fetch/23_request.js | 20 ++++++++++++-------- extensions/fetch/23_response.js | 26 +++++++++++++++----------- 2 files changed, 27 insertions(+), 19 deletions(-) (limited to 'extensions/fetch') diff --git a/extensions/fetch/23_request.js b/extensions/fetch/23_request.js index 829f7e6dc..1372125c1 100644 --- a/extensions/fetch/23_request.js +++ b/extensions/fetch/23_request.js @@ -12,6 +12,7 @@ ((window) => { const webidl = window.__bootstrap.webidl; + const consoleInternal = window.__bootstrap.console; const { HTTP_TOKEN_CODE_POINT_RE, byteUpperCase } = window.__bootstrap.infra; const { URL } = window.__bootstrap.url; const { guardFromHeaders } = window.__bootstrap.headers; @@ -393,14 +394,17 @@ } [SymbolFor("Deno.customInspect")](inspect) { - const inner = { - bodyUsed: this.bodyUsed, - headers: this.headers, - method: this.method, - redirect: this.redirect, - url: this.url, - }; - return `Request ${inspect(inner)}`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof Request, + keys: [ + "bodyUsed", + "headers", + "method", + "redirect", + "url", + ], + })); } } diff --git a/extensions/fetch/23_response.js b/extensions/fetch/23_response.js index 11eb13570..0db20e90e 100644 --- a/extensions/fetch/23_response.js +++ b/extensions/fetch/23_response.js @@ -13,6 +13,7 @@ ((window) => { const webidl = window.__bootstrap.webidl; + const consoleInternal = window.__bootstrap.console; const { HTTP_TAB_OR_SPACE, regexMatcher } = window.__bootstrap.infra; const { extractBody, mixinBody } = window.__bootstrap.fetchBody; const { getLocationHref } = window.__bootstrap.location; @@ -377,17 +378,20 @@ } [SymbolFor("Deno.customInspect")](inspect) { - const inner = { - body: this.body, - bodyUsed: this.bodyUsed, - headers: this.headers, - ok: this.ok, - redirected: this.redirected, - status: this.status, - statusText: this.statusText, - url: this.url, - }; - return `Response ${inspect(inner)}`; + return inspect(consoleInternal.createFilteredInspectProxy({ + object: this, + evaluate: this instanceof Response, + keys: [ + "body", + "bodyUsed", + "headers", + "ok", + "redirected", + "status", + "statusText", + "url", + ], + })); } } -- cgit v1.2.3