diff options
| author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-09-08 22:14:26 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-08 23:14:26 +0200 |
| commit | d9476292929a680e364db403d6fc69cfb893599f (patch) | |
| tree | 49e6a78f550232bf6175e6232ecbc96a107b06c4 | |
| parent | b31dad89a6090216361275e3cc310d10216cae65 (diff) | |
fix(ext/web): Preserve stack traces for DOMExceptions (#11959)
| -rw-r--r-- | cli/tests/testdata/dom_exception_formatting.ts.out | 1 | ||||
| -rw-r--r-- | ext/web/01_dom_exception.js | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/cli/tests/testdata/dom_exception_formatting.ts.out b/cli/tests/testdata/dom_exception_formatting.ts.out index 2a815eac1..bcdd714ea 100644 --- a/cli/tests/testdata/dom_exception_formatting.ts.out +++ b/cli/tests/testdata/dom_exception_formatting.ts.out @@ -1,2 +1,3 @@ [WILDCARD]error: Uncaught SyntaxError: foo [WILDCARD] + at file:///[WILDCARD]/dom_exception_formatting.ts:[WILDCARD] 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() { |
