Fix spurious rejected promise handler calls

This commit is contained in:
Jarred Sumner
2022-11-20 14:33:57 -08:00
parent 757d19c2f7
commit 948fdfe482
5 changed files with 25 additions and 7 deletions

View File

@@ -1431,10 +1431,28 @@ JSC__JSPromise* JSC__JSPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__
return promise;
}
JSC__JSValue JSC__JSPromise__result(const JSC__JSPromise* arg0, JSC__VM* arg1)
JSC__JSValue JSC__JSPromise__result(JSC__JSPromise* promise, JSC__VM* arg1)
{
return JSC::JSValue::encode(arg0->result(reinterpret_cast<JSC::VM&>(arg1)));
auto& vm = *arg1;
// if the promise is rejected we automatically mark it as handled so it
// doesn't end up in the promise rejection tracker
switch (promise->status(vm)) {
case JSC::JSPromise::Status::Rejected: {
uint32_t flags = promise->internalField(JSC::JSPromise::Field::Flags).get().asUInt32();
if (!(flags & JSC::JSPromise::isFirstResolvingFunctionCalledFlag)) {
promise->internalField(JSC::JSPromise::Field::Flags).set(vm, promise, jsNumber(flags | JSC::JSPromise::isHandledFlag));
}
}
// fallthrough intended
case JSC::JSPromise::Status::Fulfilled: {
return JSValue::encode(promise->result(vm));
}
default:
return JSValue::encode(JSValue {});
}
}
uint32_t JSC__JSPromise__status(const JSC__JSPromise* arg0, JSC__VM* arg1)
{
switch (arg0->status(reinterpret_cast<JSC::VM&>(arg1))) {

View File

@@ -1519,7 +1519,7 @@ pub const JSPromise = extern struct {
pub fn status(this: *const JSPromise, vm: *VM) Status {
return shim.cppFn("status", .{ this, vm });
}
pub fn result(this: *const JSPromise, vm: *VM) JSValue {
pub fn result(this: *JSPromise, vm: *VM) JSValue {
return cppFn("result", .{ this, vm });
}
pub fn isHandled(this: *const JSPromise, vm: *VM) bool {

View File

@@ -1,4 +1,4 @@
//-- AUTOGENERATED FILE -- 1667784809
//-- AUTOGENERATED FILE -- 1668983536
// clang-format off
#pragma once

View File

@@ -1,5 +1,5 @@
// clang-format off
//-- AUTOGENERATED FILE -- 1668835252
//-- AUTOGENERATED FILE -- 1668983536
#pragma once
#include <stddef.h>
@@ -349,7 +349,7 @@ CPP_DECL void JSC__JSPromise__rejectWithCaughtException(JSC__JSPromise* arg0, JS
CPP_DECL void JSC__JSPromise__resolve(JSC__JSPromise* arg0, JSC__JSGlobalObject* arg1, JSC__JSValue JSValue2);
CPP_DECL JSC__JSPromise* JSC__JSPromise__resolvedPromise(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);
CPP_DECL JSC__JSValue JSC__JSPromise__resolvedPromiseValue(JSC__JSGlobalObject* arg0, JSC__JSValue JSValue1);
CPP_DECL JSC__JSValue JSC__JSPromise__result(const JSC__JSPromise* arg0, JSC__VM* arg1);
CPP_DECL JSC__JSValue JSC__JSPromise__result(JSC__JSPromise* arg0, JSC__VM* arg1);
CPP_DECL uint32_t JSC__JSPromise__status(const JSC__JSPromise* arg0, JSC__VM* arg1);
#pragma mark - JSC::JSInternalPromise

View File

@@ -167,7 +167,7 @@ pub extern fn JSC__JSPromise__rejectWithCaughtException(arg0: [*c]JSC__JSPromise
pub extern fn JSC__JSPromise__resolve(arg0: [*c]JSC__JSPromise, arg1: ?*JSC__JSGlobalObject, JSValue2: JSC__JSValue) void;
pub extern fn JSC__JSPromise__resolvedPromise(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) [*c]JSC__JSPromise;
pub extern fn JSC__JSPromise__resolvedPromiseValue(arg0: ?*JSC__JSGlobalObject, JSValue1: JSC__JSValue) JSC__JSValue;
pub extern fn JSC__JSPromise__result(arg0: [*c]const JSC__JSPromise, arg1: [*c]JSC__VM) JSC__JSValue;
pub extern fn JSC__JSPromise__result(arg0: [*c]JSC__JSPromise, arg1: [*c]JSC__VM) JSC__JSValue;
pub extern fn JSC__JSPromise__status(arg0: [*c]const JSC__JSPromise, arg1: [*c]JSC__VM) u32;
pub extern fn JSC__JSInternalPromise__create(arg0: ?*JSC__JSGlobalObject) [*c]JSC__JSInternalPromise;
pub extern fn JSC__JSInternalPromise__isHandled(arg0: [*c]const JSC__JSInternalPromise, arg1: [*c]JSC__VM) bool;