From d9476292929a680e364db403d6fc69cfb893599f Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Wed, 8 Sep 2021 22:14:26 +0100 Subject: fix(ext/web): Preserve stack traces for DOMExceptions (#11959) --- ext/web/01_dom_exception.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ext/web/01_dom_exception.js') diff --git a/ext/web/01_dom_exception.js b/ext/web/01_dom_exception.js index c6f60ae2f..0d9e82c56 100644 --- a/ext/web/01_dom_exception.js +++ b/ext/web/01_dom_exception.js @@ -11,6 +11,8 @@ ((window) => { const { + ArrayPrototypeSlice, + Error, ErrorPrototype, ObjectDefineProperty, ObjectEntries, @@ -94,6 +96,16 @@ context: "Argument 2", }); 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; + ObjectDefineProperty(this, "__callSiteEvals", { + value: ArrayPrototypeSlice(error.__callSiteEvals, 1), + configurable: true, + }); } get message() { -- cgit v1.2.3