Skip to content

Commit

Permalink
feat(web): Implement DOMException's stack property. (denoland#12294)
Browse files Browse the repository at this point in the history
As per WebIDL (https://heycam.github.io/webidl/#es-DOMException-specialness),
if `Error` objects have a `stack` property, so should `DOMException`
instances.
  • Loading branch information
Andreu Botella authored Oct 3, 2021
1 parent 8884141 commit 2170a41
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 10 additions & 5 deletions ext/web/01_dom_exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -13603,9 +13603,7 @@
"DOMException-constants.any.html": true,
"DOMException-constructor-and-prototype.any.html": true,
"DOMException-constructor-behavior.any.html": true,
"DOMException-custom-bindings.any.html": [
"If the implementation has a stack property on normal errors, it also does on DOMExceptions"
]
"DOMException-custom-bindings.any.html": true
},
"class-string-interface.any.html": true,
"class-string-iterator-prototype-object.any.html": true,
Expand Down Expand Up @@ -15339,4 +15337,4 @@
"Pattern: [] Inputs: []"
]
}
}
}

0 comments on commit 2170a41

Please sign in to comment.