Issue #2435 - Re-Implement rejected Promises events according to spec

Own implementation; upstream gets several things wrong.
This commit is contained in:
Martok 2024-01-04 13:23:53 +01:00 • committed by roytam1
commit 90eb83819c
6 changed files with 119 additions and 60 deletions

View file

@ -430,6 +430,12 @@ public:
// in the last turn of the event loop.
JS::PersistentRooted<JS::GCVector<JSObject*, 0, js::SystemAllocPolicy>> mConsumedRejections;
// This is for the "outstanding rejected promises weak set" in the spec,
// https://html.spec.whatwg.org/multipage/webappapis.html#outstanding-rejected-promises-weak-set
typedef nsRefPtrHashtable<nsUint64HashKey, dom::Promise> PromiseHashtable;
PromiseHashtable mOutstandingRejections;
nsTArray<nsCOMPtr<nsISupports /* UncaughtRejectionObserver */ >> mUncaughtRejectionObservers;
private:
@ -480,25 +486,6 @@ private:
typedef nsTArray<RefPtr<dom::Promise>> PromiseArray;
PromiseArray mAboutToBeNotifiedRejectedPromises;
// This is for the "outstanding rejected promises weak set" in the spec,
// https://html.spec.whatwg.org/multipage/webappapis.html#outstanding-rejected-promises-weak-set
// We use different data structure and opposite logic here to achieve the same
// effect. Basically this is used for tracking the rejected promise that does
// NOT need firing a rejectionhandled event. We will check the table to see if
// firing rejectionhandled event is required when a rejected promise is being
// handled.
//
// The rejected promise will be stored in the table if
// - it is unhandled, and
// - The unhandledrejection is not yet fired.
//
// And be removed when
// - it is handled, or
// - A unhandledrejection is fired and it isn't being handled in event
// handler.
typedef nsRefPtrHashtable<nsUint64HashKey, dom::Promise> PromiseHashtable;
PromiseHashtable mPendingUnhandledRejections;
class NotifyUnhandledRejections final : public CancelableRunnable {
public:
NotifyUnhandledRejections(CycleCollectedJSContext* aCx,