From 0014b64978b7d5d4732428d21c4d51fc39944fcf Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Fri, 21 Aug 2026 20:51:01 +0000 Subject: [PATCH] ErrorInstance: pass the error to the onComputeErrorInfo hook ErrorInstance::reconcileWeakReferencesAtGCEnd materializes the stack string of a live error when a frame of its stack trace died. The hook that builds that string only received the frames, so the embedder could not put the error's name and message on the first line. Pass the error instance, like the onComputeErrorInfoJSValue hook already does. --- Source/JavaScriptCore/runtime/ErrorInstance.cpp | 2 +- Source/JavaScriptCore/runtime/VM.h | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Source/JavaScriptCore/runtime/ErrorInstance.cpp b/Source/JavaScriptCore/runtime/ErrorInstance.cpp index 0f090b58c1e95..ae122859be500 100644 --- a/Source/JavaScriptCore/runtime/ErrorInstance.cpp +++ b/Source/JavaScriptCore/runtime/ErrorInstance.cpp @@ -396,7 +396,7 @@ void ErrorInstance::computeErrorInfo(VM& vm, bool allocationAllowed) if (m_stackPropertyAlreadyMaterialized) stackString = emptyString(); else - stackString = fn(vm, *m_stackTrace.get(), m_lineColumn.line, m_lineColumn.column, m_sourceURL, this->bunErrorData()); + stackString = fn(vm, *m_stackTrace.get(), m_lineColumn.line, m_lineColumn.column, m_sourceURL, this, this->bunErrorData()); } else { getLineColumnAndSource(vm, m_stackTrace.get(), m_lineColumn, m_sourceURL); // If the stack property was already materialized by Error.captureStackString, diff --git a/Source/JavaScriptCore/runtime/VM.h b/Source/JavaScriptCore/runtime/VM.h index cf23d183cee9d..0709cec3af9c5 100644 --- a/Source/JavaScriptCore/runtime/VM.h +++ b/Source/JavaScriptCore/runtime/VM.h @@ -173,7 +173,11 @@ constexpr bool validateDFGDoesGC = ENABLE_DFG_DOES_GC_VALIDATION; #if USE(BUN_JSC_ADDITIONS) using StackTraceAppenderFunction = WTF::Function& stackTrace, size_t maxToAppend)>; -using ErrorInfoFunction = WTF::Function& stackTrace, unsigned& line, unsigned& column, String& sourceURL, void* bunErrorData)>; +// Called by ErrorInstance::computeErrorInfo. Its main caller is ErrorInstance::reconcileWeakReferencesAtGCEnd, +// which runs inside Heap::runEndPhase when a frame of a not yet materialized stack trace died; the returned +// string then becomes the error's final .stack. errorInstance is the error being formatted, so the embedder +// can still put its name and message on the first line. The function must not allocate GC cells or run JS. +using ErrorInfoFunction = WTF::Function& stackTrace, unsigned& line, unsigned& column, String& sourceURL, JSC::JSObject* errorInstance, void* bunErrorData)>; using ErrorInfoFunctionJSValue = WTF::Function& stackTrace, unsigned& line, unsigned& column, String& sourceURL, JSC::JSObject*, void* bunErrorData)>; #endif