Skip to content

Instantly share code, notes, and snippets.

@leobalter
Last active April 10, 2019 21:03
Show Gist options
  • Save leobalter/d5ddfd403c0b92333201ea7f8872d5a4 to your computer and use it in GitHub Desktop.
Save leobalter/d5ddfd403c0b92333201ea7f8872d5a4 to your computer and use it in GitHub Desktop.
/*---
description: >
Error thrown when invoking the instance's `then` method (rejecting Promise)
esid: sec-promise.allSettled
info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
7. If result is an abrupt completion, then
a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
b. IfAbruptRejectPromise(result, promiseCapability).
Runtime Semantics: PerformPromiseAllSettled
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
flags: [async]
---*/
var promise = new Promise(function() {});
var error = new Test262Error();
promise.then = function() {
throw error;
};
Promise.allSettled([promise]).then(function() {
throw new Test262Error('The promise should be rejected');
}, function(reason) {
assert.sameValue(reason, error);
}).then($DONE, $DONE);
var assert = require('assert');
var allSettled = require('promise.allsettled');
allSettled.shim(); // will be a no-op if not needed
var promise = new Promise(function() {});
var error = new Error();
promise.then = function() {
throw error;
};
function $DONE(arg) {
assert.strictEqual(arg, undefined);
console.log('ok');
}
Promise.all([promise]).then(function() {
throw 'The promise should be rejected';
}, function(reason) {
assert.strictEqual(reason, error);
}).then($DONE, $DONE);
Promise.allSettled([promise]) // shim is throwing here and not rejecting the promise per spec text
.then(function() {
throw 'The promise should be rejected';
}, function(reason) {
assert.strictEqual(reason, error); // this is the current spec text today
}).then($DONE, $DONE);
Promise.allSettled([promise])
.then(function(arr) {
arr[0] // sounds like it should be { status: 'rejected', reason: error }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment