Bug 266943
| Summary: | Throwing an Error subclass includes constructor in stacktrace (unlike V8) | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | Jarred Sumner <jarred> |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | mark.lam, webkit-bug-importer, ysuzuki |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
Jarred Sumner
The following code:
```js
class CustomError extends Error {
constructor(message) {
super(message);
}
}
const error = new CustomError("uh-oh!");
throw error;
```
Prints the following in `jsc`:
```
Exception: Error: uh-oh!
CustomError@throw.js:3:10
global code@throw.js:7:30
```
The first line of the stack trace is `super(message)`, which is not what users want to see. They want to see where the the error was thrown, not the `super` call for the Error subclass.
In Node.js/V8, this works as expected - the first line is the one which threw
```
throw error;
^
CustomError: uh-oh!
at Object.<anonymous> (/Users/jarred/throw.js:7:15)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49
Node.js v21.4.0
```
Similarly, pasting the snippet into Chrome DevTools reports:
```
VM51:9 Uncaught Error: uh-oh!
at <anonymous>:7:15
```
Line 7 is the throw statement
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/120375032>
Sosuke Suzuki
Pull request: https://github.com/WebKit/WebKit/pull/49808
EWS
Committed 299375@main (70c384691cea): <https://commits.webkit.org/299375@main>
Reviewed commits have been landed. Closing PR #49808 and removing active labels.