Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Source/JavaScriptCore/runtime/ErrorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,14 @@ void ErrorInstance::computeErrorInfo(VM& vm, bool allocationAllowed)
UNUSED_PARAM(allocationAllowed);

if (m_stackTrace && !m_stackTrace->isEmpty()) {
auto& fnWithErrorInstance = vm.onComputeErrorInfoWithErrorInstance();
auto& fn = vm.onComputeErrorInfo();
WTF::String stackString;
if (fn) {
if (fnWithErrorInstance || fn) {
if (m_stackPropertyAlreadyMaterialized)
stackString = emptyString();
else if (fnWithErrorInstance)
stackString = fnWithErrorInstance(vm, *m_stackTrace.get(), m_lineColumn.line, m_lineColumn.column, m_sourceURL, this, this->bunErrorData());
else
stackString = fn(vm, *m_stackTrace.get(), m_lineColumn.line, m_lineColumn.column, m_sourceURL, this->bunErrorData());
} else {
Expand Down
11 changes: 11 additions & 0 deletions Source/JavaScriptCore/runtime/VM.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ constexpr bool validateDFGDoesGC = ENABLE_DFG_DOES_GC_VALIDATION;
#if USE(BUN_JSC_ADDITIONS)
using StackTraceAppenderFunction = WTF::Function<void(VM&, JSCell* owner, Vector<StackFrame>& stackTrace, size_t maxToAppend)>;
using ErrorInfoFunction = WTF::Function<String(VM&, Vector<StackFrame>& stackTrace, unsigned& line, unsigned& column, String& sourceURL, void* bunErrorData)>;
// Like ErrorInfoFunction, but also receives the ErrorInstance whose stack trace is being
// rendered. ErrorInstance::computeErrorInfo runs it from the GC's unconditional finalizers
// (the frames are about to be dropped), so it must not allocate on the JS heap; the instance
// is there so the embedder can read the error's name and message for the header of the
// stack string, which ErrorInfoFunction cannot do. Preferred over ErrorInfoFunction when set.
using ErrorInfoFunctionWithErrorInstance = WTF::Function<String(VM&, Vector<StackFrame>& stackTrace, unsigned& line, unsigned& column, String& sourceURL, JSC::JSObject* errorInstance, void* bunErrorData)>;
using ErrorInfoFunctionJSValue = WTF::Function<JSValue(VM&, Vector<StackFrame>& stackTrace, unsigned& line, unsigned& column, String& sourceURL, JSC::JSObject*, void* bunErrorData)>;
#endif

Expand Down Expand Up @@ -1081,6 +1087,9 @@ class VM : public ThreadSafeRefCountedWithSuppressingSaferCPPChecking<VM> {
const ErrorInfoFunction& onComputeErrorInfo() const { return m_onComputeErrorInfo; }
ErrorInfoFunction& onComputeErrorInfo() { return m_onComputeErrorInfo; }

const ErrorInfoFunctionWithErrorInstance& onComputeErrorInfoWithErrorInstance() const { return m_onComputeErrorInfoWithErrorInstance; }
ErrorInfoFunctionWithErrorInstance& onComputeErrorInfoWithErrorInstance() { return m_onComputeErrorInfoWithErrorInstance; }

const ErrorInfoFunctionJSValue& onComputeErrorInfoJSValue() const { return m_onComputeErrorInfoJSValue; }
ErrorInfoFunctionJSValue& onComputeErrorInfoJSValue() { return m_onComputeErrorInfoJSValue; }

Expand All @@ -1089,6 +1098,7 @@ class VM : public ThreadSafeRefCountedWithSuppressingSaferCPPChecking<VM> {

void setOnAppendStackTrace(StackTraceAppenderFunction&& function) { m_onAppendStackTrace = WTF::move(function); }
void setOnComputeErrorInfo(ErrorInfoFunction&& function) { m_onComputeErrorInfo = WTF::move(function); }
void setOnComputeErrorInfoWithErrorInstance(ErrorInfoFunctionWithErrorInstance&& function) { m_onComputeErrorInfoWithErrorInstance = WTF::move(function); }
void setOnComputeErrorInfoJSValue(ErrorInfoFunctionJSValue&& function) { m_onComputeErrorInfoJSValue = WTF::move(function); }
void setComputeLineColumnWithSourcemap(WTF::Function<void(VM&, SourceProvider*, LineColumn&, String&)>&& function) { m_computeLineColumnWithSourcemap = WTF::move(function); }
#endif
Expand Down Expand Up @@ -1326,6 +1336,7 @@ class VM : public ThreadSafeRefCountedWithSuppressingSaferCPPChecking<VM> {
WTF::Function<void(VM&)> m_onEachMicrotaskTick;
#if USE(BUN_JSC_ADDITIONS)
ErrorInfoFunction m_onComputeErrorInfo;
ErrorInfoFunctionWithErrorInstance m_onComputeErrorInfoWithErrorInstance;
ErrorInfoFunctionJSValue m_onComputeErrorInfoJSValue;
StackTraceAppenderFunction m_onAppendStackTrace;
WTF::Function<void(VM&, SourceProvider*, LineColumn&, String&)> m_computeLineColumnWithSourcemap;
Expand Down
Loading