summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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));
+});