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
14 changes: 7 additions & 7 deletions Source/JavaScriptCore/runtime/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,9 @@ JSObject* addErrorInfo(VM& vm, JSObject* error, int line, const SourceCode& sour
if (ErrorInstance* errorInstance = dynamicDowncast<ErrorInstance>(error)) {
#if USE(BUN_JSC_ADDITIONS)
// A host that formats the stack itself (VM::onComputeErrorInfo; Bun) reads the parser's position from these
// fields, maps it through its source maps and hands back the line to report: what it computed stands. It is
// only asked when the stack has a frame.
// fields, maps it through its source maps and hands back the line to report: what it computed stands.
bool hostComputes = (vm.onComputeErrorInfoJSValue() || vm.onComputeErrorInfo())
&& !errorInstance->hasMaterializedErrorInfo() && errorInstance->stackTrace() && !errorInstance->stackTrace()->isEmpty();
&& !errorInstance->hasMaterializedErrorInfo() && errorInstance->stackTrace();
Comment thread
dylan-conway marked this conversation as resolved.
Resolved

if (line != -1) {
errorInstance->setLine(line);
Expand All @@ -275,11 +274,12 @@ JSObject* addErrorInfo(VM& vm, JSObject* error, int line, const SourceCode& sour
auto catchScope = DECLARE_TOP_EXCEPTION_SCOPE(vm);
errorInstance->materializeErrorInfoIfNeeded(vm);
catchScope.clearExceptionExceptTermination();
return errorInstance;
}
// It can give an error with no frames no stack, which then gets the parser's position below.
if (errorInstance->hasMaterializedErrorInfo())
return errorInstance;
} else
#endif

errorInstance->materializeErrorInfoIfNeeded(vm);
errorInstance->materializeErrorInfoIfNeeded(vm);
}

// Without such a host, materializing takes line and sourceURL from the top frame of the stack (the caller of eval or
Comment thread
dylan-conway marked this conversation as resolved.
Resolved
Expand Down
45 changes: 28 additions & 17 deletions Source/JavaScriptCore/runtime/ErrorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ErrorInstance::ErrorInstance(VM& vm, Structure* structure, ErrorType errorType)
#endif // ENABLE(WEBASSEMBLY)
#if USE(BUN_JSC_ADDITIONS)
, m_stackStringIsFramesOnly(false)
, m_hookGaveNoStack(false)
#endif
{
}
Expand Down Expand Up @@ -476,33 +477,43 @@ bool ErrorInstance::materializeErrorInfoIfNeeded(VM& vm)
#if USE(BUN_JSC_ADDITIONS)

auto& fn = vm.onComputeErrorInfoJSValue();
if (fn && m_stackTrace && !m_stackTrace->isEmpty()) {
// The hook's stack begins with "name: message", so one captured with Error.stackTraceLimit = 0 is not empty.
if (fn && m_stackTrace && (!m_stackTrace->isEmpty() || !m_hookGaveNoStack)) {
m_errorInfoMaterialized = true;
bool hasFrames = !m_stackTrace->isEmpty();
DeferGCForAWhile deferGC(vm);

JSValue stack;
if (!m_stackPropertyProvidedByCapturedStackTrace)
stack = fn(vm, *m_stackTrace.get(), m_lineColumn.line, m_lineColumn.column, m_sourceURL, this);

{
Locker locker { cellLock() };
m_stackTrace->clear();
m_stackTrace = nullptr;
m_stackString = String();
}
if (hasFrames || stack) {
{
Locker locker { cellLock() };
m_stackTrace->clear();
m_stackTrace = nullptr;
m_stackString = String();
}
Comment thread
dylan-conway marked this conversation as resolved.
Resolved

auto attributes = static_cast<unsigned>(PropertyAttribute::DontEnum);
auto attributes = static_cast<unsigned>(PropertyAttribute::DontEnum);

// An error has these from the start, so one with immutable properties still gets them. No JavaScript runs from here on.
AllowLazyMaterializationOfImmutableProperties allowMaterialization(vm);
putDirect(vm, vm.propertyNames->line, jsNumber(m_lineColumn.line), attributes);
putDirect(vm, vm.propertyNames->column, jsNumber(m_lineColumn.column), attributes);
if (!m_sourceURL.isEmpty())
putDirect(vm, vm.propertyNames->sourceURL, jsString(vm, WTF::move(m_sourceURL)), attributes);
// An error has these from the start, so one with immutable properties still gets them. No JavaScript runs from here on.
AllowLazyMaterializationOfImmutableProperties allowMaterialization(vm);
if (hasFrames || m_lineColumn.line) {
putDirect(vm, vm.propertyNames->line, jsNumber(m_lineColumn.line), attributes);
putDirect(vm, vm.propertyNames->column, jsNumber(m_lineColumn.column), attributes);
if (!m_sourceURL.isEmpty())
putDirect(vm, vm.propertyNames->sourceURL, jsString(vm, WTF::move(m_sourceURL)), attributes);
}

if (!m_stackPropertyProvidedByCapturedStackTrace)
putDirect(vm, vm.propertyNames->stack, stack, attributes);
return true;
if (!m_stackPropertyProvidedByCapturedStackTrace)
putDirect(vm, vm.propertyNames->stack, stack, attributes);
return true;
}

// The hook gave an error with no frames no stack. It is not asked again, and what follows is as if it had not been asked.
m_hookGaveNoStack = true;
m_errorInfoMaterialized = false;
}

#endif
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/runtime/ErrorInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class ErrorInstance : public JSNonFinalObject {
#endif
#if USE(BUN_JSC_ADDITIONS)
bool m_stackStringIsFramesOnly : 1;
bool m_hookGaveNoStack : 1;
JSValue stackWithHeader(VM&, String&& frames);
#endif
};
Expand Down
Loading