Closed Bug 1568903 Opened 5 years ago Closed 5 years ago

Implement the Promise.any proposal

Categories

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

enhancement

Tracking

()

RESOLVED FIXED
mozilla72
Tracking Status
firefox72 --- fixed

People

(Reporter: alex.fdm, Assigned: anba)

References

(Blocks 1 open bug, )

Details

Attachments

(11 files)

(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details
(deleted), text/x-phabricator-request
Details

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
Pushed by csabou@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/58c002a9cb78 Part 1: Clean-up GlobalObject.h includes. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/d2b01a1ad0a9 Part 2: Move ErrorObject parts from jsexn.cpp to ErrorObject.cpp. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/27c54b414c35 Part 3: Apply include-what-you-use for jsexn and ErrorObject. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/127a44494b67 Part 4: Implement AggregateError for Nightly. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/567d497a39f4 Part 5: Rename shared functions for Promise combinators. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/595accbef95e Part 6: Add helper to create Promise combinator element functions. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/3f4aee7f2893 Part 7: Add function to check if Promise combinator element function was already called. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/379d0f2de211 Part 8: Add separate struct to work with Promise combinator elements arrays. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/f4d9fda6d7f2 Part 9: Implement the Promise.any proposal. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/76ad398222a6 Part 10: Update test_xrayToJS to handle the new AggregateError object and the Promise method. r=peterv,jorendorff
Backout by nerli@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cfe990fab350 Backed out 10 changesets for causing mochitest failures
Flags: needinfo?(andrebargull)
Pushed by csabou@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/12503fb17ac5 Part 1: Clean-up GlobalObject.h includes. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/a49b752bfeee Part 2: Move ErrorObject parts from jsexn.cpp to ErrorObject.cpp. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/2378a03445a7 Part 3: Apply include-what-you-use for jsexn and ErrorObject. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/b1811bdf29c0 Part 4: Implement AggregateError for Nightly. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/5aa617ae468c Part 5: Rename shared functions for Promise combinators. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/182fe08e0d52 Part 6: Add helper to create Promise combinator element functions. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/08498010c540 Part 7: Add function to check if Promise combinator element function was already called. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/e7097ccc33a9 Part 8: Add separate struct to work with Promise combinator elements arrays. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/936031ae609c Part 9: Implement the Promise.any proposal. r=jorendorff https://hg.mozilla.org/integration/autoland/rev/3f147b35398c Part 10: Update test_xrayToJS to handle the new AggregateError object and the Promise method. r=peterv,jorendorff https://hg.mozilla.org/integration/autoland/rev/196a50e2cdd6 Part 11: Update ecma-globals list in mocha interfaces tests. r=jorendorff
Regressions: 1598869

Filed bug 1599434 and bug 1599435 for adding AggregateError support to devtools and PromiseWorker.

Removing DDN; we'll track this using https://bugzilla.mozilla.org/show_bug.cgi?id=1599769 instead.

Keywords: dev-doc-needed
Regressions: 1612730
Blocks: 1599769
Regressions: 1652148
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: