Skip to content
Open
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
10 changes: 10 additions & 0 deletions Source/JavaScriptCore/runtime/AggregateError.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ namespace JSC {

ErrorInstance* createAggregateError(VM&, Structure*, JSArray* errors, const String& message, JSValue cause, ErrorInstance::SourceAppender = nullptr, RuntimeType = TypeNothing, bool useCurrentFrame = true);

inline ErrorInstance* createAggregateErrorForPromiseAnyRejection(VM& vm, Structure* structure, JSArray* errors)
{
#if USE(BUN_JSC_ADDITIONS)
String message = "All promises were rejected"_s;
#else
String message;
#endif
return createAggregateError(vm, structure, errors, message, JSValue());
}

} // namespace JSC
13 changes: 8 additions & 5 deletions Source/JavaScriptCore/runtime/ErrorInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ bool ErrorInstance::materializeErrorInfoIfNeeded(VM& vm)
#if USE(BUN_JSC_ADDITIONS)

auto& fn = vm.onComputeErrorInfoJSValue();
if (fn && m_stackTrace && !m_stackTrace->isEmpty()) {
if (fn && m_stackTrace) {
bool hasFrames = !m_stackTrace->isEmpty();
m_errorInfoMaterialized = true;
DeferGCForAWhile deferGC(vm);

Expand All @@ -424,10 +425,12 @@ bool ErrorInstance::materializeErrorInfoIfNeeded(VM& vm)

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

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 (hasFrames) {
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_stackPropertyAlreadyMaterialized)
putDirect(vm, vm.propertyNames->stack, stack, attributes);
Expand Down
2 changes: 1 addition & 1 deletion Source/JavaScriptCore/runtime/JSMicrotask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ static void promiseAnyResolveJob(JSGlobalObject* globalObject, VM& vm, JSPromise
globalContext->setRemainingElementsCount(count);
if (!count) {
auto* promise = uncheckedDowncast<JSPromise>(globalContext->promise());
auto* aggregateError = createAggregateError(vm, globalObject->errorStructure(ErrorType::AggregateError), errors, String(), jsUndefined());
auto* aggregateError = createAggregateErrorForPromiseAnyRejection(vm, globalObject->errorStructure(ErrorType::AggregateError), errors);
scope.release();
promise->reject(vm, aggregateError);
}
Expand Down
8 changes: 4 additions & 4 deletions Source/JavaScriptCore/runtime/JSPromiseConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ static JSObject* promiseAnySlow(JSGlobalObject* globalObject, CallFrame* callFra
uint64_t count = globalContext->remainingElementsCount() - 1;
globalContext->setRemainingElementsCount(count);
if (!count) {
auto* aggregateError = createAggregateError(vm, globalObject->errorStructure(ErrorType::AggregateError), errors, String(), jsUndefined());
auto* aggregateError = createAggregateErrorForPromiseAnyRejection(vm, globalObject->errorStructure(ErrorType::AggregateError), errors);
callReject(aggregateError);
if (scope.exception()) [[unlikely]] {
callRejectWithScopeException();
Expand Down Expand Up @@ -1334,7 +1334,7 @@ JSC_DEFINE_HOST_FUNCTION(promiseConstructorFuncAny, (JSGlobalObject* globalObjec
uint64_t count = globalContext->remainingElementsCount() - 1;
globalContext->setRemainingElementsCount(count);
if (!count) {
auto* aggregateError = createAggregateError(vm, globalObject->errorStructure(ErrorType::AggregateError), errors, String(), jsUndefined());
auto* aggregateError = createAggregateErrorForPromiseAnyRejection(vm, globalObject->errorStructure(ErrorType::AggregateError), errors);
scope.release();
promise->reject(vm, aggregateError);
if (scope.exception()) [[unlikely]] {
Expand Down Expand Up @@ -1371,7 +1371,7 @@ JSC_DEFINE_HOST_FUNCTION(promiseAnyRejectFunction, (JSGlobalObject* globalObject
uint64_t count = globalContext->remainingElementsCount() - 1;
globalContext->setRemainingElementsCount(count);
if (!count) {
auto* aggregateError = createAggregateError(vm, globalObject->errorStructure(ErrorType::AggregateError), errors, String(), jsUndefined());
auto* aggregateError = createAggregateErrorForPromiseAnyRejection(vm, globalObject->errorStructure(ErrorType::AggregateError), errors);
scope.release();
promise->reject(vm, aggregateError);
}
Expand Down Expand Up @@ -1406,7 +1406,7 @@ JSC_DEFINE_HOST_FUNCTION(promiseAnySlowRejectFunction, (JSGlobalObject* globalOb
uint64_t count = globalContext->remainingElementsCount() - 1;
globalContext->setRemainingElementsCount(count);
if (!count) {
auto* aggregateError = createAggregateError(vm, globalObject->errorStructure(ErrorType::AggregateError), errors, String(), jsUndefined());
auto* aggregateError = createAggregateErrorForPromiseAnyRejection(vm, globalObject->errorStructure(ErrorType::AggregateError), errors);
MarkedArgumentBuffer rejectArguments;
rejectArguments.append(aggregateError);
ASSERT(!rejectArguments.hasOverflowed());
Expand Down
Loading