Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 696c406fe52267891404c045028f727184c68cb2
      
https://github.com/WebKit/WebKit/commit/696c406fe52267891404c045028f727184c68cb2
  Author: Vassili Bykov <[email protected]>
  Date:   2026-10-01 (Thu, 01 Oct 2026)

  Changed paths:
    M Source/JavaScriptCore/runtime/ErrorConstructor.cpp
    M Source/JavaScriptCore/runtime/ErrorInstance.cpp
    M Source/JavaScriptCore/runtime/ErrorInstance.h

  Log Message:
  -----------
  [JSC] Build the stack string for Error.captureStackTrace() lazily
https://bugs.webkit.org/show_bug.cgi?id=325578
rdar://188656702

Reviewed by Yusuke Suzuki.

Error.captureStackTrace() stores the stack trace string in the argument object 
as the "stack"
property. It is a common idiom for this function to be called in an Error 
subclass constructor.
The "stack" property is often never accessed, while constructing the stack 
trace string it
contains is expensive.

This patch changes the implementation of Error.captureStackTrace() to behave 
similarly to the
stack captured by the Error constructor in ErrorInstance::m_stackTrace. When 
the argument is an
ErrorInstance that does not have its own "stack" property yet, calling the 
function only captures
the frames of the stack in m_capturedStackTrace, and installs "stack" as a 
placeholder property so
that the order of own property keys does not change. The frames are formatted 
into the stack trace
string when the error info is first accessed, and the placeholder is replaced 
with an ordinary
data property. Also similar to the constructor-captured stack, the trace string 
is rendered while
it still can be in reconcileWeakReferencesAtGCEnd() if JSCells referenced by 
any of the captured
frames (codeBlock or callee) are about to be collected. Other arguments keep 
the eager behavior.

m_stackString now holds the string for "stack" from whichever source provides 
it, so it no longer
doubles as the marker that line, column and sourceURL are available in 
m_lineColumn and
m_sourceURL. A new m_hasErrorInfo bit takes over that role. computeErrorInfo() 
no longer stores an
empty stack string as a marker when Error.captureStackTrace() provides "stack".

Covered by existing tests.

Canonical link: https://commits.webkit.org/322427@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to