Open Bug 1568903 Opened 4 months ago Updated 11 days ago

Implement the Promise.any proposal

Categories

(Core :: JavaScript: Standard Library, enhancement, P3)

enhancement

Tracking

()

ASSIGNED

People

(Reporter: alex.fdm, Assigned: anba)

References

(Blocks 1 open bug, )

Details

(Keywords: dev-doc-needed)

Attachments

(10 files)

47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review

This proposal is currently in Stage 2.

The proposal is now at stage 3 and ready for implementations: https://github.com/tc39/proposal-promise-any

Note that this includes AggregateError as well.

Component: JavaScript Engine → JavaScript: Standard Library

GlobalObject.h had an unnecessary #include for ErrorObject.h, which led to
recompiling more or less all of SpiderMonkey when modifying ErrorObject.h,
because GlobalObject.h is (transitively) included in most files.

The ErrorObject classes are already declared in ErrorObject.h, so it seems
useful to also move their definitions into the corresponding cpp file.

Also adds js::CaptureStack to jsexn.h so it can be called from ErrorObject.cpp
and to remove the duplicated implementation in JSContext.cpp.

Depends on D51649

Update the #includes after moving the code in part 2.

Depends on D51651

Adds AggregateError, but only enables it for Nightly builds, because the draft
proposal is still incomplete, so it doesn't make sense to let this feature ride
the trains at this moment.

  • The other_error_properties array was changed to individual static variables,
    because AggregateError has more than three properties, which prevents it to be
    stored in JSPropertySpec[][3].

  • AggregateErrorObject can't use the normal ErrorObject class, because it
    needs an additional slot for the [[AggregateErrors]].

  • For similar reasons it can't use the shared Error constructor function,
    because the AggregateError constructor has an additional errors iterable
    argument which it needs to process.

Depends on D51652

The draft propsal calls Promise.all, Promise.allSetteld, Promise.any, and
Promise.race "Promise combinators". Let's reuse that name to avoid having to
spell each function name in shared functions. For example instead of
CommonStaticAllRace, or soon CommonStaticAllRaceAny, we get
CommonPromiseCombinator.

  • PromiseAllDataHolder is currently used for Promise.all and
    Promise.allSettled, and soon also for Promise.any. Rename it to
    PromiseCombinatorDataHolder to express that different Promise combinators use
    this object.

Depends on D51653

Moves the NewNativeFunction and the two setExtendedSlot calls into a helper
function to reduce code duplication.

Depends on D51654

The first five steps in each Promise combinator element function are always the
same. Add a helper function for this task to reduce more code duplication.

Depends on D51655

Adds a separate struct to hold the elements arrays and to apply wrapping and
unwrapping at the correct points. This will let us avoid copying this code
another time for the Promise.any proposal.

Depends on D51656

As with AggregateError, Promise.any is only enabled in Nightly.

Now that everything is in place, the actual Promise.any implementation is
relatively straight forward. The only tricky part is probably just the
ThrowAggregateError function, when the async stack is created to give a
better stack trace.

Depends on D51658

Assignee: nobody → andrebargull
Status: NEW → ASSIGNED
You need to log in before you can comment on or make changes to this bug.