summaryrefslogtreecommitdiff
path: root/extensions/web/02_event.js
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2021-06-24 09:43:41 -0400
committerGitHub <noreply@github.com>2021-06-24 09:43:41 -0400
commita2067ec46d410b691229b6fcaa12ff5f1dd223f3 (patch)
tree76cb85186de7db5801eeaab6479c42fe01127586 /extensions/web/02_event.js
parent4b3845b998ae2f7cd6e02625b4cfc3613878ceb2 (diff)
fix(inspect): eliminate panic inspecting event classes (#10979)
Diffstat (limited to 'extensions/web/02_event.js')
-rw-r--r--extensions/web/02_event.js60
1 files changed, 46 insertions, 14 deletions
diff --git a/extensions/web/02_event.js b/extensions/web/02_event.js
index 17d5cb54e..40cfd30a8 100644
--- a/extensions/web/02_event.js
+++ b/extensions/web/02_event.js
@@ -144,7 +144,7 @@
}
[Symbol.for("Deno.customInspect")](inspect) {
- return buildCustomInspectOutput(this, EVENT_PROPS, inspect);
+ return inspect(buildFilteredPropertyInspectObject(this, EVENT_PROPS));
}
get type() {
@@ -395,9 +395,41 @@
}
}
- function buildCustomInspectOutput(object, keys, inspect) {
- const inspectObject = Object.fromEntries(keys.map((k) => [k, object[k]]));
- return `${object.constructor.name} ${inspect(inspectObject)}`;
+ 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 === Symbol.toStringTag) {
+ return object.constructor?.name;
+ } else if (keys.includes(key)) {
+ return Reflect.get(object, key);
+ } else {
+ return undefined;
+ }
+ },
+ getOwnPropertyDescriptor(_target, key) {
+ if (!keys.includes(key)) {
+ return undefined;
+ }
+
+ return Reflect.getOwnPropertyDescriptor(object, key) ??
+ (object.prototype &&
+ Reflect.getOwnPropertyDescriptor(object.prototype, key)) ??
+ {
+ configurable: true,
+ enumerable: true,
+ value: object[key],
+ };
+ },
+ has(_target, key) {
+ return keys.includes(key);
+ },
+ ownKeys() {
+ return keys;
+ },
+ });
}
function defineEnumerableProps(
@@ -1053,14 +1085,14 @@
}
[Symbol.for("Deno.customInspect")](inspect) {
- return buildCustomInspectOutput(this, [
+ return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"message",
"filename",
"lineno",
"colno",
"error",
- ], inspect);
+ ]));
}
}
@@ -1107,12 +1139,12 @@
}
[Symbol.for("Deno.customInspect")](inspect) {
- return buildCustomInspectOutput(this, [
+ return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"wasClean",
"code",
"reason",
- ], inspect);
+ ]));
}
}
@@ -1135,12 +1167,12 @@
}
[Symbol.for("Deno.customInspect")](inspect) {
- return buildCustomInspectOutput(this, [
+ return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"data",
"origin",
"lastEventId",
- ], inspect);
+ ]));
}
}
@@ -1165,10 +1197,10 @@
}
[Symbol.for("Deno.customInspect")](inspect) {
- return buildCustomInspectOutput(this, [
+ return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"detail",
- ], inspect);
+ ]));
}
}
@@ -1188,12 +1220,12 @@
}
[Symbol.for("Deno.customInspect")](inspect) {
- return buildCustomInspectOutput(this, [
+ return inspect(buildFilteredPropertyInspectObject(this, [
...EVENT_PROPS,
"lengthComputable",
"loaded",
"total",
- ], inspect);
+ ]));
}
}