summaryrefslogtreecommitdiff
path: root/ext/web/01_dom_exception.js
diff options
context:
space:
mode:
authorAndreu Botella <abb@randomunok.com>2021-10-03 17:21:49 +0200
committerGitHub <noreply@github.com>2021-10-03 17:21:49 +0200
commit2170a41d975dbdc4680eb0ea346fdb5056bfa57b (patch)
treeb98f2cec3147a005a783929aafcc23b2ec92851d /ext/web/01_dom_exception.js
parent8884141c3f08a04ff3315555c62d120c7647efbe (diff)
feat(web): Implement `DOMException`'s `stack` property. (#12294)
As per WebIDL (https://heycam.github.io/webidl/#es-DOMException-specialness), if `Error` objects have a `stack` property, so should `DOMException` instances.
Diffstat (limited to 'ext/web/01_dom_exception.js')
-rw-r--r--ext/web/01_dom_exception.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js
index ae478da2b..25eb85fc2 100644
--- a/ext/web/01_dom_exception.js
+++ b/ext/web/01_dom_exception.js
@@ -96,11 +96,16 @@
});
this.#code = nameToCodeMapping[this.#name] ?? 0;
- // `DOMException` does not have `.stack`, so `Error.prepareStackTrace()`
- // is not called on it, meaning our structured stack trace hack doesn't
- // apply. This patches it in.
- const error = new Error();
- error.stack;
+ const error = new Error(`DOMException: ${this.#message}`);
+ ObjectDefineProperty(this, "stack", {
+ value: error.stack,
+ writable: true,
+ configurable: true,
+ });
+
+ // `DOMException` isn't a native error, so `Error.prepareStackTrace()` is
+ // not called when accessing `.stack`, meaning our structured stack trace
+ // hack doesn't apply. This patches it in.
ObjectDefineProperty(this, "__callSiteEvals", {
value: ArrayPrototypeSlice(error.__callSiteEvals, 1),
configurable: true,