[Webkit-unassigned] [Bug 266943] New: Throwing an Error subclass includes constructor in stacktrace (unlike V8)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Dec 30 18:51:05 PST 2023


https://bugs.webkit.org/show_bug.cgi?id=266943

            Bug ID: 266943
           Summary: Throwing an Error subclass includes constructor in
                    stacktrace (unlike V8)
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: jarred at jarredsumner.com

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 at throw.js:3:10
global code at 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

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20231231/946d47a4/attachment-0001.htm>


More information about the webkit-unassigned mailing list