Summary: | Error.stack is missing the second frame in some cases | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | krinklemail | ||||||||||
Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> | ||||||||||
Status: | RESOLVED WONTFIX | ||||||||||||
Severity: | Normal | CC: | keith_miller, mark.lam, m.goleb+bugzilla, ysuzuki | ||||||||||
Priority: | P2 | ||||||||||||
Version: | Safari 17 | ||||||||||||
Hardware: | Unspecified | ||||||||||||
OS: | macOS 13 | ||||||||||||
Attachments: |
|
Description
krinklemail
2024-07-03 12:10:35 PDT
Keywords: stacktrace, stack trace, callstack, call stack, exception. Possibly related: https://bugs.webkit.org/show_bug.cgi?id=70605 Created attachment 471806 [details]
Runtime Error.stack differs from Web Inspector showing the correct stack
Created attachment 471807 [details]
Caller context
Created attachment 471808 [details]
Caller-caller context
Created attachment 471809 [details]
Firefox comparison for reference
This is the correct behavior because ECMAScript spec defines tail-calls, and QUnit.stack is taking tail-call form (strict mode, and calling sourceFromStacktrace in tail-call position). So, Firefox and Chrome behaviors are wrong in terms of the spec. You can ask to Firefox / Chrome to implement tail-call as spec requires, and then QUnit implementation should be fixed. Thanks, I was able to finally reproduce this in isolation by changing: ``` var QUnit_reduced = { stack: function (offset) { offset = (offset || 0) + 2; return sourceFromStacktrace(offset); } } ``` to ``` var QUnit_reduced = { stack: function (offset) { 'use strict'; offset = (offset || 0) + 2; return sourceFromStacktrace(offset); } } ``` Related reading: * https://262.ecma-international.org/11.0/#sec-function-calls-runtime-semantics-evaluation - Defining IsInTailPosition * https://262.ecma-international.org/11.0/#sec-evaluatecall - tailCall/tailPosition dictating "as if it has already returned" * https://stackoverflow.com/a/54721813/319266 - Tail Calls introduced in ES6 and shipped by Safari, but defacto JSC/WebKit-only at this point. * https://github.com/tc39/proposal-error-stacks/ - seeking to standardise Error.stack * https://github.com/tc39/proposal-error-stacks/issues/23 |