Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Promise.allSettled #6138

Merged
merged 4 commits into from
Jun 4, 2019

Conversation

boingoing
Copy link
Contributor

@boingoing boingoing commented Jun 1, 2019

Implement Promise.allSettled

This is now in Stage 3 and supported in V8 and JSC. See spec:
https://tc39.github.io/proposal-promise-allSettled/

Fixes: #6056

{
Assert(values != nullptr);

TryCallResolveOrRejectHandler(promiseCapability->GetResolve(), values, scriptContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At https://tc39.github.io/proposal-promise-allSettled/#sec-performpromiseallsettled step 6.d.iii.2, it seems that if this call throws, then it is "caught" by allSettled step 7, which then rejects the resulting promise with the exception value.

I believe the following:

function FakePromise(fn) {
  function resolve() { print('resolve called'); throw new Error('oops'); }
  function reject(e) { print('reject called: ' + e.message) }
  fn(resolve, reject);
  this.then = function(onResolve, onReject) {};
}

FakePromise.resolve = function() {};

Promise.allSettled.call(FakePromise, []);

should print:

resolve called
reject called: oops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right, good catch. We have the same issue with Promise.all, it looks like. I'll make the fix to both.

Copy link
Contributor

@zenparsing zenparsing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we retrigger CI for those jobs that failed?

@fatcerberus
Copy link
Contributor

it seems that if this call throws, then it is "caught" by allSettled step 7, which then rejects the resulting promise with the exception value.

Wait, is that actually right? I thought the whole deal with Promise.allSettled was that it never rejects, so that you can see the results of all promises regardless of fulfill/reject unlike Promise.all?

@boingoing
Copy link
Contributor Author

@zenparsing I don't actually know how to retrigger the tests which failed in the new CI. These failures aren't related to my change, though, they've been failing across the CI lately. I'll rebase the branch which will trigger them to rerun, at least.

@boingoing
Copy link
Contributor Author

@fatcerberus Yes, this reading of the spec is correct. We call IfAbruptRejectPromise mostly on errors thrown out of the iterator or on errors invoking the resolve method. The case @zenparsing caught is what happens when the iterable argument is empty and an error is thrown while trying to execute resolve to get a promise resolved with the empty array.

…completion while calling Promise.resolve

When calling these methods with an empty iterator, they will call Promise.resolve synchronously with an empty array result. If Promise.resolve results in an abrupt completion, we are supposed to catch this and reject the result promise. Previously we were just letting this abrupt completion be leaked.
@chakrabot chakrabot merged commit 42c894d into chakra-core:master Jun 4, 2019
chakrabot pushed a commit that referenced this pull request Jun 4, 2019
Merge pull request #6138 from boingoing:promiseallsettled

Implement Promise.allSettled

This is now in Stage 3 and supported in V8 and JSC. See spec:
https://tc39.github.io/proposal-promise-allSettled/

Fixes: #6056
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Promise.allSettled
4 participants