Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2024-01-09 12:01:14 +08:00
commit d4a80aa2c4
42 changed files with 538 additions and 364 deletions

View file

@ -100,6 +100,10 @@ class PromiseObject : public NativeObject
int32_t flags = getFixedSlot(PromiseSlot_Flags).toInt32();
setFixedSlot(PromiseSlot_Flags, Int32Value(flags | PROMISE_FLAG_REPORTED));
}
bool isReported() {
MOZ_ASSERT(isUnhandled());
return flags() & PROMISE_FLAG_REPORTED;
}
};
/**

View file

@ -4949,12 +4949,31 @@ JS::GetPromiseResult(JS::HandleObject promiseObj)
return promise->state() == JS::PromiseState::Fulfilled ? promise->value() : promise->reason();
}
JS_PUBLIC_API(bool)
JS::GetPromiseIsHandled(JS::HandleObject promise)
{
PromiseObject* promiseObj = &promise->as<PromiseObject>();
return !promiseObj->isUnhandled();
}
JS_PUBLIC_API(JSObject*)
JS::GetPromiseAllocationSite(JS::HandleObject promise)
{
return promise->as<PromiseObject>().allocationSite();
}
JS_PUBLIC_API(bool)
JS::GetPromiseIsReported(JS::HandleObject promise)
{
return promise->as<PromiseObject>().isReported();
}
JS_PUBLIC_API(void)
JS::MarkPromiseRejectionReported(JS::HandleObject promise)
{
return promise->as<PromiseObject>().markAsReported();
}
JS_PUBLIC_API(JSObject*)
JS::GetPromiseResolutionSite(JS::HandleObject promise)
{

View file

@ -4611,6 +4611,27 @@ GetPromiseID(JS::HandleObject promise);
extern JS_PUBLIC_API(JS::Value)
GetPromiseResult(JS::HandleObject promise);
/**
* Returns whether the given promise's rejection is already handled or not.
*
* The caller must check the given promise is rejected before checking it's
* handled or not.
*/
extern JS_PUBLIC_API(bool)
GetPromiseIsHandled(JS::HandleObject promise);
/**
* Returns whether the given promise's rejection is reported or not.
*/
extern JS_PUBLIC_API(bool)
GetPromiseIsReported(JS::HandleObject promise);
/**
* Mark the given promise's rejection as already reported.
*/
extern JS_PUBLIC_API(void)
MarkPromiseRejectionReported(JS::HandleObject promise);
/**
* Returns a js::SavedFrame linked list of the stack that lead to the given
* Promise's allocation.

View file

@ -3485,21 +3485,6 @@ XPCJSContext::BeforeProcessTask(bool aMightBlock)
{
MOZ_ASSERT(NS_IsMainThread());
// If ProcessNextEvent was called during a Promise "then" callback, we
// must process any pending microtasks before blocking in the event loop,
// otherwise we may deadlock until an event enters the queue later.
if (aMightBlock) {
if (Promise::PerformMicroTaskCheckpoint()) {
// If any microtask was processed, we post a dummy event in order to
// force the ProcessNextEvent call not to block. This is required
// to support nested event loops implemented using a pattern like
// "while (condition) thread.processNextEvent(true)", in case the
// condition is triggered here by a Promise "then" callback.
NS_DispatchToMainThread(new Runnable());
}
}
// Start the slow script timer.
mSlowScriptCheckpoint = mozilla::TimeStamp::NowLoRes();
mSlowScriptSecondHalf = false;