summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-05-07 22:02:29 +0100
committerGitHub <noreply@github.com>2024-05-07 21:02:29 +0000
commit25fcfe5d79850b6969f2756415fc01e2234850c9 (patch)
treec9b57ed0a0beee991db3cefaadbf42bf446ec040
parent998036b3998301dc53b0dc4700b91d0a9c630702 (diff)
fix: DOMException doesn't throw on __callSitesEvals (#23729)
-rw-r--r--ext/web/01_dom_exception.js7
-rw-r--r--tests/unit/dom_exception_test.ts7
2 files changed, 13 insertions, 1 deletions
diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js
index 9bab4881a..82e8f867f 100644
--- a/ext/web/01_dom_exception.js
+++ b/ext/web/01_dom_exception.js
@@ -167,7 +167,12 @@ ObjectDefineProperty(DOMException.prototype, "stack", {
// hack doesn't apply. This patches it in.
ObjectDefineProperty(DOMException.prototype, "__callSiteEvals", {
get() {
- return ArrayPrototypeSlice(this[_error].__callSiteEvals, 1);
+ // Call the stack getter so `__callSiteEvals` get populated.
+ this[_error].stack;
+ // To be extra sure, use an empty array if `__callSiteEvals` is still not there,
+ // eg. if the user overrides `Error.prepareStackTrace`.
+ const callSiteEvals = this[_error].__callSiteEvals ?? [];
+ return ArrayPrototypeSlice(callSiteEvals, 1);
},
configurable: true,
});
diff --git a/tests/unit/dom_exception_test.ts b/tests/unit/dom_exception_test.ts
index de335e105..806248caa 100644
--- a/tests/unit/dom_exception_test.ts
+++ b/tests/unit/dom_exception_test.ts
@@ -1,6 +1,7 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
import {
+ assert,
assertEquals,
assertNotEquals,
assertStringIncludes,
@@ -21,3 +22,9 @@ Deno.test(function nameToCodeMappingPrototypeAccess() {
assertNotEquals(newCode, new DOMException("test", "pollution").code);
Reflect.deleteProperty(objectPrototype, "pollution");
});
+
+Deno.test(function callSitesEvalsDoesntThrow() {
+ const e2 = new DOMException("asdf");
+ // @ts-ignore no types for `__callSiteEvals` but it's observable.
+ assert(Array.isArray(e2.__callSiteEvals));
+});