From a5b2b471d26986a3bfc5dc2824011b1163bab697 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 23 Sep 2026 05:18:58 +0000 Subject: [PATCH 1/2] [JSC] ErrorInstance::setStackFrames arms the lazy error info again New frames replace the ones an earlier lookup of stack, line, column or sourceURL materialized. The next lookup formats the new frames. A call while materializeErrorInfoIfNeeded() still reads the frames keeps them. --- Source/JavaScriptCore/runtime/ErrorInstance.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/JavaScriptCore/runtime/ErrorInstance.cpp b/Source/JavaScriptCore/runtime/ErrorInstance.cpp index 1fc50aeed8231..119a3c540f49e 100644 --- a/Source/JavaScriptCore/runtime/ErrorInstance.cpp +++ b/Source/JavaScriptCore/runtime/ErrorInstance.cpp @@ -124,6 +124,11 @@ String appendSourceToErrorMessage(CodeBlock* codeBlock, BytecodeIndex bytecodeIn void ErrorInstance::setStackFrames(VM& vm, WTF::Vector&& stackFrames) { + // materializeErrorInfoIfNeeded() is formatting m_stackTrace right now (a callback of the + // hook replaces the frames of the error being read): the frames the hook reads stay. + if (m_errorInfoMaterialized && m_stackTrace) + return; + std::unique_ptr> stackTrace = makeUnique>(WTF::move(stackFrames)); Locker locker { cellLock() }; @@ -133,6 +138,10 @@ void ErrorInstance::setStackFrames(VM& vm, WTF::Vector&& stackFrames #if USE(BUN_JSC_ADDITIONS) m_stackStringIsFramesOnly = false; #endif + // New frames arm the lazy error info again: the next lookup of stack, line, column or + // sourceURL formats them, even if an earlier lookup already materialized the old frames. + m_errorInfoMaterialized = false; + m_stackPropertyAlreadyMaterialized = false; vm.writeBarrier(this); } From b2e7fa4101c6fc56d1f12d42700327ff4c3633ff Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Wed, 23 Sep 2026 06:59:14 +0000 Subject: [PATCH 2/2] Describe the capture that setStackFrames() refuses --- Source/JavaScriptCore/runtime/ErrorInstance.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/JavaScriptCore/runtime/ErrorInstance.cpp b/Source/JavaScriptCore/runtime/ErrorInstance.cpp index 119a3c540f49e..6758e3927c90e 100644 --- a/Source/JavaScriptCore/runtime/ErrorInstance.cpp +++ b/Source/JavaScriptCore/runtime/ErrorInstance.cpp @@ -124,8 +124,9 @@ String appendSourceToErrorMessage(CodeBlock* codeBlock, BytecodeIndex bytecodeIn void ErrorInstance::setStackFrames(VM& vm, WTF::Vector&& stackFrames) { - // materializeErrorInfoIfNeeded() is formatting m_stackTrace right now (a callback of the - // hook replaces the frames of the error being read): the frames the hook reads stay. + // materializeErrorInfoIfNeeded() is formatting m_stackTrace right now: the hook set the flag + // and still reads the frames. A capture from inside the hook's callback (Error.prepareStackTrace) + // on the error being formatted keeps the frames the callback was given. if (m_errorInfoMaterialized && m_stackTrace) return;