@@ -0,0 +1,43 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Error thrown when invoking the instance's `then` method (closing iterator)
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 »).
features: [Promise.allSettled, Symbol.iterator]
---*/

var promise = new Promise(function() {});
var returnCount = 0;
var iter = {};
iter[Symbol.iterator] = function() {
return {
next() {
return {
done: false,
value: promise
};
},
return() {
returnCount += 1;
return {};
}
};
};

promise.then = function() {
throw new Test262Error();
};

Promise.allSettled(iter);

assert.sameValue(returnCount, 1);
@@ -0,0 +1,32 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
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]
features: [Promise.allSettled]
---*/

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);
@@ -0,0 +1,45 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Error thrown when accesing the instance's `then` method (closing iterator)
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 »).
features: [Promise.allSettled, Symbol.iterator]
---*/

var promise = new Promise(function() {});
var returnCount = 0;
var iter = {};
iter[Symbol.iterator] = function() {
return {
next() {
return {
done: false,
value: promise
};
},
return() {
returnCount += 1;
return {};
}
};
};

Object.defineProperty(promise, 'then', {
get() {
throw new Test262Error();
}
});

Promise.allSettled(iter);

assert.sameValue(returnCount, 1);
@@ -0,0 +1,33 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Error thrown when accessing 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]
features: [Promise.allSettled]
---*/

var promise = new Promise(function() {});
var error = new Test262Error();

Object.defineProperty(promise, 'then', {
get() {
throw error;
}
});

Promise.allSettled([promise]).then(function() {
$ERROR('The promise should be rejected');
}, function(reason) {
assert.sameValue(reason, error);
}).then($DONE, $DONE);
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Invocation of the instance's `then` method
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 »).
features: [Promise.allSettled]
---*/

var p1 = new Promise(function() {});
var p2 = new Promise(function() {});
var p3 = new Promise(function() {});
var callCount = 0;
var currentThis = p1;
var nextThis = p2;
var afterNextThis = p3;

p1.then = p2.then = p3.then = function(a, b) {
assert.sameValue(typeof a, 'function', 'type of first argument');
assert.sameValue(
a.length,
1,
'The length property of a promise resolve function is 1.'
);
assert.sameValue(typeof b, 'function', 'type of second argument');
assert.sameValue(
b.length,
1,
'The length property of a promise reject function is 1.'
);
assert.sameValue(arguments.length, 2, '`then` invoked with two arguments');
assert.sameValue(this, currentThis, '`this` value');

currentThis = nextThis;
nextThis = afterNextThis;
afterNextThis = null;

callCount += 1;
};

Promise.allSettled([p1, p2, p3]);

assert.sameValue(callCount, 3, '`then` invoked once for every iterated value');
@@ -0,0 +1,10 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: Promise.allSettled is callable
features: [Promise.allSettled]
---*/

assert.sameValue(typeof Promise.allSettled, 'function');
@@ -0,0 +1,36 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument is `false`
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled(false).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,36 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument is `null`
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled(null).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,36 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument is a number
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled(1).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,42 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject with abrupt completion from GetIterator
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
...
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

var poison = [];
var error = new Test262Error();
Object.defineProperty(poison, Symbol.iterator, {
get() {
throw error;
}
});

try {
Promise.allSettled(poison).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(err) {
assert.sameValue(err, error);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,35 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Resolve when argument is a string
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
#sec-getiterator
GetIterator ( obj [ , hint [ , method ] ] )
...
Let iterator be ? Call(method, obj).
If Type(iterator) is not Object, throw a TypeError exception.
...
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled('').then(function(v) {
assert.sameValue(v.length, 0);
}, function() {
$DONE('The promise should be resolved, but was rejected');
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be resolved, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,49 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument is a symbol
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled(Symbol()).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,49 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument is `true`
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled(true).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,49 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument is `undefined`
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled(undefined).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value false
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
i. Set method to ? GetMethod(obj, @@asyncIterator).
ii. If method is undefined, then
1. Let syncMethod be ? GetMethod(obj, @@iterator).
2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod).
...
4. Let iterator be ? Call(method, obj).
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: false
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value null
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: null
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value 1
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: 1
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value ""
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: ''
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value Symbol()
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: Symbol()
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value true
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: true
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,51 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator property has the value undefined
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]: undefined
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,54 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Error when call an iterator next step (rejecting promise)
info: |
Promise.allSettled ( iterable )
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
...
6. Repeat
a. Let next be IteratorStep(iteratorRecord).
b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true.
c. ReturnIfAbrupt(next).
...
IteratorStep ( iteratorRecord )
1. Let result be ? IteratorNext(iteratorRecord).
IteratorNext ( iteratorRecord [ , value ] )
1. If value is not present, then
a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « »).
2. Else,
a. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
...
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

var iterNextValThrows = {};
var error = new Test262Error();
iterNextValThrows[Symbol.iterator] = function() {
return {
next() {
throw error;
}
};
};

Promise.allSettled(iterNextValThrows).then(function() {
$DONE('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
}).then($DONE, $DONE);
@@ -0,0 +1,56 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Error when accessing an iterator result's `value` property (not closing
iterator)
info: |
Promise.allSettled ( iterable )
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
...
6. Repeat
...
e. Let nextValue be IteratorValue(next).
f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
g. ReturnIfAbrupt(nextValue).
features: [Promise.allSettled, Symbol.iterator]
---*/

var iterNextValThrows = {};
var returnCount = 0;
var nextCount = 0;
var poisonedVal = {
done: false
};
var error = new Test262Error();
Object.defineProperty(poisonedVal, 'value', {
get() {
throw error;
}
});
iterNextValThrows[Symbol.iterator] = function() {
return {
next() {
nextCount += 1;
return poisonedVal;
},
return() {
returnCount += 1;
return {};
}
};
};

Promise.allSettled(iterNextValThrows);

assert.sameValue(returnCount, 0);
assert.sameValue(nextCount, 1);
@@ -0,0 +1,50 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Error when accessing an iterator result's `value` property (rejecting promise)
info: |
Promise.allSettled ( iterable )
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
...
6. Repeat
...
e. Let nextValue be IteratorValue(next).
f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true.
g. ReturnIfAbrupt(nextValue).
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

var iterNextValThrows = {};
var poisonedVal = {
done: false
};
var error = new Test262Error();
Object.defineProperty(poisonedVal, 'value', {
get() {
throw error;
}
});
iterNextValThrows[Symbol.iterator] = function() {
return {
next() {
return poisonedVal;
}
};
};

Promise.allSettled(iterNextValThrows).then(function() {
$DONE('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
}).then($DONE, $DONE);
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns false
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return false;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns null
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return null;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns a number
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return 1;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns a string
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return '';
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns a symbol
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return Symbol();
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns true
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return true;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Reject when argument's Symbol.iterator returns undefined
info: |
Promise.allSettled ( iterable )
...
4. Let iteratorRecord be GetIterator(iterable).
5. IfAbruptRejectPromise(iteratorRecord, promiseCapability).
...
GetIterator ( obj [ , hint [ , method ] ] )
...
3. If method is not present, then
a. If hint is async, then
...
b. Otherwise, set method to ? GetMethod(obj, @@iterator).
4. Let iterator be ? Call(method, obj).
5. If Type(iterator) is not Object, throw a TypeError exception.
...
GetMethod
2. Let func be ? GetV(V, P).
3. If func is either undefined or null, return undefined.
4. If IsCallable(func) is false, throw a TypeError exception.
Call ( F, V [ , argumentsList ] )
2. If IsCallable(F) is false, throw a TypeError exception.
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

try {
Promise.allSettled({
[Symbol.iterator]() {
return undefined;
}
}).then(function() {
$DONE('The promise should be rejected, but was resolved');
}, function(error) {
assert.sameValue(Object.getPrototypeOf(error), TypeError.prototype);
assert(error instanceof TypeError);
}).then($DONE, $DONE);
} catch (error) {
$DONE(`The promise should be rejected, but threw an exception: ${error.message}`);
}
@@ -0,0 +1,52 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Error when advancing the provided iterable (not closing iterator)
info: |
Promise.allSettled ( iterable )
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
6. Repeat
a. Let next be IteratorStep(iteratorRecord).
b. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
c. ReturnIfAbrupt(next).
features: [Promise.allSettled, Symbol.iterator]
---*/

var iterStepThrows = {};
var poisonedDone = {};
var returnCount = 0;
var error = new Test262Error();
Object.defineProperty(poisonedDone, 'done', {
get() {
throw error;
}
});
Object.defineProperty(poisonedDone, 'value', {
get() {}
});

iterStepThrows[Symbol.iterator] = function() {
return {
next() {
return poisonedDone;
},
return() {
returnCount += 1;
return {};
}
};
};

Promise.allSettled(iterStepThrows);

assert.sameValue(returnCount, 0);
@@ -0,0 +1,52 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Error when advancing the provided iterable (rejecting promise)
info: |
Promise.allSettled ( iterable )
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
6. Repeat
a. Let next be IteratorStep(iteratorRecord).
b. If next is an abrupt completion, set iteratorRecord.[[done]] to true.
c. ReturnIfAbrupt(next).
features: [Promise.allSettled, Symbol.iterator]
flags: [async]
---*/

var iterStepThrows = {};
var poisonedDone = {};
var error = new Test262Error();
Object.defineProperty(poisonedDone, 'done', {
get() {
throw error;
}
});
Object.defineProperty(poisonedDone, 'value', {
get() {
$DONE('The `value` property should not be accessed.');
}
});

iterStepThrows[Symbol.iterator] = function() {
return {
next() {
return poisonedDone;
}
};
};

Promise.allSettled(iterStepThrows).then(function() {
$DONE('The promise should be rejected.');
}, function(reason) {
assert.sameValue(reason, error);
}).then($DONE, $DONE);
@@ -0,0 +1,28 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: Promise.allSettled `length` property
info: |
ES Section 17:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this value
is equal to the largest number of named arguments shown in the subclause
headings for the function description, including optional parameters.
[...]
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

verifyProperty(Promise.allSettled, 'length', {
configurable: true,
writable: false,
enumerable: false,
value: 1,
});
@@ -0,0 +1,29 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: Promise.allSettled `name` property
info: |
ES Section 17:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value is a
String. Unless otherwise specified, this value is the name that is given to
the function in this specification.
[...]
Unless otherwise specified, the name property of a built-in Function
object, if it exists, has the attributes { [[Writable]]: false,
[[Enumerable]]: false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

verifyProperty(Promise.allSettled, 'name', {
configurable: true,
writable: false,
enumerable: false,
value: 'allSettled',
});
@@ -0,0 +1,48 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallsettled
description: >
Each Promise.allSettled element is called with a new Promise.allSettled Reject Element function.
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
...
features: [Promise.allSettled]
---*/

function rejectFunction() {}

function Constructor(executor) {
executor(rejectFunction, $ERROR);
}
Constructor.resolve = function(v) {
return v;
};

var callCount1 = 0,
callCount2 = 0;
var p1OnRejected;

var p1 = {
then(_, onRejected) {
callCount1 += 1;
p1OnRejected = onRejected;
assert.notSameValue(onRejected, rejectFunction, 'p1.then');
}
};
var p2 = {
then(_, onRejected) {
callCount2 += 1;
assert.notSameValue(onRejected, rejectFunction, 'p2.then');
assert.notSameValue(onRejected, p1OnRejected, 'p1.onRejected != p2.onRejected');
}
};

Promise.allSettled.call(Constructor, [p1, p2]);

assert.sameValue(callCount1, 1, 'p1.then call count');
assert.sameValue(callCount2, 1, 'p2.then call count');
@@ -0,0 +1,50 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallsettled
description: >
Each Promise.allSettled element is called with a new Promise.allSettled Resolve Element function.
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
...
k Let resolveElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
...
features: [Promise.allSettled]
---*/

function resolveFunction() {}

function Constructor(executor) {
executor(resolveFunction, $ERROR);
}
Constructor.resolve = function(v) {
return v;
};

var callCount1 = 0,
callCount2 = 0;
var p1OnFulfilled;

var p1 = {
then(onFulfilled, onRejected) {
callCount1 += 1;
p1OnFulfilled = onFulfilled;
assert.notSameValue(onFulfilled, resolveFunction, 'p1.then');
}
};
var p2 = {
then(onFulfilled, onRejected) {
callCount2 += 1;
assert.notSameValue(onFulfilled, resolveFunction, 'p2.then');
assert.notSameValue(onFulfilled, p1OnFulfilled, 'p1.onFulfilled != p2.onFulfilled');
}
};

Promise.allSettled.call(Constructor, [p1, p2]);

assert.sameValue(callCount1, 1, 'p1.then call count');
assert.sameValue(callCount2, 1, 'p2.then call count');
@@ -0,0 +1,21 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: Promise.allSettled property descriptor
info: |
ES Section 17
Every other data property described in clauses 18 through 26 and in Annex
B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

verifyProperty(Promise, 'allSettled', {
configurable: true,
writable: true,
enumerable: false,
});
@@ -0,0 +1,47 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Rejecting through deferred invocation of the provided resolving function
esid: sec-promise.allsettled
info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
Runtime Semantics: PerformPromiseAllSettled
6. Repeat
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
Promise.allSettled Reject Element Functions
9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "rejected").
11. Perform ! CreateDataProperty(obj, "reason", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
flags: [async]
features: [Promise.allSettled]
---*/

var simulation = {};
var thenable = {
then(_, reject) {
new Promise(function(resolve) {
resolve();
})
.then(function() {
reject(simulation);
});
}
};

Promise.allSettled([thenable])
.then((settleds) => {
assert.sameValue(settleds.length, 1);
assert.sameValue(settleds[0].status, 'rejected');
assert.sameValue(settleds[0].reason, simulation);
$DONE();
}).then($DONE, $DONE);
@@ -0,0 +1,29 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-reject-element-functions
description: The [[Extensible]] slot of Promise.allSettled Reject Element functions
info: |
17 ECMAScript Standard Built-in Objects:
Unless specified otherwise, the [[Extensible]] internal slot
of a built-in object initially has the value true.
features: [Promise.allSettled]
---*/

var rejectElementFunction;
var thenable = {
then(_, reject) {
rejectElementFunction = reject;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert(Object.isExtensible(rejectElementFunction));
@@ -0,0 +1,40 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-reject-element-functions
description: The `length` property of Promise.allSettled Reject Element functions
info: |
The length property of a Promise.allSettled Reject Element function is 1.
17 ECMAScript Standard Built-in Objects:
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

var rejectElementFunction;
var thenable = {
then(_, reject) {
rejectElementFunction = reject;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(rejectElementFunction.length, 1);

verifyProperty(rejectElementFunction, 'length', {
value: 1,
enumerable: false,
writable: false,
configurable: true,
});
@@ -0,0 +1,32 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-reject-element-functions
description: The `name` property of Promise.allSettled Reject Element functions
info: |
A promise resolve function is an anonymous built-in function.
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
features: [Promise.allSettled]
---*/

var rejectElementFunction;
var thenable = {
then(_, reject) {
rejectElementFunction = reject;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(Object.prototype.hasOwnProperty.call(rejectElementFunction, 'name'), false);
@@ -0,0 +1,33 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-reject-element-functions
description: Promise.allSettled Reject Element functions are not constructors
info: |
17 ECMAScript Standard Built-in Objects:
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified
in the description of a particular function.
features: [Promise.allSettled]
---*/

var rejectElementFunction;
var thenable = {
then(_, reject) {
rejectElementFunction = reject;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(Object.prototype.hasOwnProperty.call(rejectElementFunction, 'prototype'), false);
assert.throws(TypeError, function() {
new rejectElementFunction();
});
@@ -0,0 +1,31 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-reject-element-functions
description: The [[Prototype]] of Promise.allSettled Reject Element functions
info: |
17 ECMAScript Standard Built-in Objects:
Unless otherwise specified every built-in function and every built-in
constructor has the Function prototype object, which is the initial
value of the expression Function.prototype (19.2.3), as the value of
its [[Prototype]] internal slot.
features: [Promise.allSettled]
---*/

var rejectElementFunction;
var thenable = {
then(_, reject) {
rejectElementFunction = reject;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(Object.getPrototypeOf(rejectElementFunction), Function.prototype);
@@ -0,0 +1,53 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Resolved promises ignore rejections through deferred invocation of the
provided resolving function
esid: sec-promise.allsettled
info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
Runtime Semantics: PerformPromiseAllSettled
6. Repeat
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
flags: [async]
features: [Promise.allSettled]
---*/

var simulation = {};

var fulfiller = {
then(resolve) {
new Promise(function(resolve) {
resolve();
})
.then(function() {
resolve(42);
});
}
};
var rejector = {
then(resolve, reject) {
new Promise(function(resolve) {
resolve();
})
.then(function() {
resolve(simulation);
reject();
});
}
};

Promise.allSettled([fulfiller, rejector])
.then((settleds) => {
assert.sameValue(settleds.length, 2);
assert.sameValue(settleds[0].status, 'fulfilled');
assert.sameValue(settleds[0].value, 42);
assert.sameValue(settleds[1].status, 'fulfilled');
assert.sameValue(settleds[1].value, simulation);
$DONE();
}).then($DONE, $DONE);
@@ -0,0 +1,44 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: >
Resolved promises ignore rejections through immediate invocation of the
provided resolving function
esid: sec-promise.allsettled
info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
Runtime Semantics: PerformPromiseAllSettled
6. Repeat
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
flags: [async]
features: [Promise.allSettled]
---*/

var simulation = {};

var fulfiller = {
then(resolve) {
resolve(42);
}
};

var lateRejector = {
then(resolve, reject) {
resolve(simulation);
reject();
}
};

Promise.allSettled([fulfiller, lateRejector])
.then((settleds) => {
assert.sameValue(settleds.length, 2);
assert.sameValue(settleds[0].status, 'fulfilled');
assert.sameValue(settleds[0].value, 42);
assert.sameValue(settleds[1].status, 'fulfilled');
assert.sameValue(settleds[1].value, simulation);
$DONE();
}).then($DONE, $DONE);
@@ -0,0 +1,31 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
description: Rejecting through immediate invocation of the provided resolving function
esid: sec-promise.allsettled
info: |
6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
Runtime Semantics: PerformPromiseAllSettled
6. Repeat
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
flags: [async]
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var simulation = {};
var thenable = {
then(_, reject) {
reject(simulation);
}
};

Promise.allSettled([thenable])
.then((settleds) => {
checkSettledPromises(settleds, [{ status: 'rejected', reason: simulation }]);
$DONE();
}).then($DONE, $DONE);
@@ -0,0 +1,83 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallsettled
description: >
Cannot tamper remainingElementsCount when Promise.allSettled resolve element function is called twice in a row.
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
...
6.d ...
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
iii. If remainingElementsCount.[[value]] is 0, then
1. Let valuesArray be CreateArrayFromList(values).
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
...
Promise.allSettled Resolve Element Functions
2. Let alreadyCalled be F.[[AlreadyCalled]].
3. If alreadyCalled.[[Value]] is true, return undefined.
4. Set alreadyCalled.[[Value]] to true.
...
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var callCount = 0;

function Constructor(executor) {
function resolve(values) {
callCount += 1;
checkSettledPromises(values, [
{
status: 'fulfilled',
value: 'p1-fulfill'
},
{
status: 'fulfilled',
value: 'p2-fulfill'
},
{
status: 'fulfilled',
value: 'p3-fulfill'
}
], 'values');
}
executor(resolve, $ERROR);
}
Constructor.resolve = function(v) {
return v;
};

var p1OnFulfilled;

var p1 = {
then(onFulfilled, onRejected) {
p1OnFulfilled = onFulfilled;
}
};
var p2 = {
then(onFulfilled, onRejected) {
onFulfilled('p2-fulfill');
onFulfilled('p2-fulfill-unexpected');
}
};
var p3 = {
then(onFulfilled, onRejected) {
onFulfilled('p3-fulfill');
}
};

assert.sameValue(callCount, 0, 'callCount before call to all()');

Promise.allSettled.call(Constructor, [p1, p2, p3]);

assert.sameValue(callCount, 0, 'callCount after call to all()');

p1OnFulfilled('p1-fulfill');

assert.sameValue(callCount, 1, 'callCount after resolving p1');
@@ -0,0 +1,79 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallsettled
description: >
Cannot tamper remainingElementsCount when two Promise.allSettled resolve element functions are called in succession.
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
...
6.d ...
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
iii. If remainingElementsCount.[[value]] is 0, then
1. Let valuesArray be CreateArrayFromList(values).
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
...
Promise.allSettled Resolve Element Functions
2. Let alreadyCalled be F.[[AlreadyCalled]].
3. If alreadyCalled.[[Value]] is true, return undefined.
4. Set alreadyCalled.[[Value]] to true.
...
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var callCount = 0;

function Constructor(executor) {
function resolve(values) {
callCount += 1;
checkSettledPromises(values, [
{
status: 'fulfilled',
value: 'p1-fulfill'
},
{
status: 'fulfilled',
value: 'p2-fulfill'
},
{
status: 'fulfilled',
value: 'p3-fulfill'
}
], 'values');
}
executor(resolve, $ERROR);
}
Constructor.resolve = function(v) {
return v;
};

var p1OnFulfilled;

var p1 = {
then(onFulfilled, onRejected) {
p1OnFulfilled = onFulfilled;
}
};
var p2 = {
then(onFulfilled, onRejected) {
p1OnFulfilled('p1-fulfill');
onFulfilled('p2-fulfill');
}
};
var p3 = {
then(onFulfilled, onRejected) {
onFulfilled('p3-fulfill');
}
};

assert.sameValue(callCount, 0, 'callCount before call to all()');

Promise.allSettled.call(Constructor, [p1, p2, p3]);

assert.sameValue(callCount, 1, 'callCount after call to all()');
@@ -0,0 +1,29 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-resolve-element-functions
description: The [[Extensible]] slot of Promise.allSettled Resolve Element functions
info: |
17 ECMAScript Standard Built-in Objects:
Unless specified otherwise, the [[Extensible]] internal slot
of a built-in object initially has the value true.
features: [Promise.allSettled]
---*/

var resolveElementFunction;
var thenable = {
then(fulfill) {
resolveElementFunction = fulfill;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert(Object.isExtensible(resolveElementFunction));
@@ -0,0 +1,38 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-resolve-element-functions
description: The `length` property of Promise.allSettled Resolve Element functions
info: |
The length property of a Promise.allSettled resolve element function is 1.

17 ECMAScript Standard Built-in Objects:
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Promise.allSettled]
---*/

var resolveElementFunction;
var thenable = {
then(fulfill) {
resolveElementFunction = fulfill;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

verifyProperty(resolveElementFunction, 'length', {
value: 1,
enumerable: false,
writable: false,
configurable: true,
});
@@ -0,0 +1,35 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-resolve-element-functions
description: The `name` property of Promise.allSettled Resolve Element functions
info: |
A promise resolve function is an anonymous built-in function.

17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, that is not
identified as an anonymous function has a name property whose value
is a String.
features: [Promise.allSettled]
---*/

var resolveElementFunction;
var thenable = {
then(fulfill) {
resolveElementFunction = fulfill;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(
Object.prototype.hasOwnProperty.call(resolveElementFunction, 'name'),
false
);
@@ -0,0 +1,33 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-resolve-element-functions
description: Promise.allSettled Resolve Element functions are not constructors
info: |
17 ECMAScript Standard Built-in Objects:
Built-in function objects that are not identified as constructors do not
implement the [[Construct]] internal method unless otherwise specified
in the description of a particular function.
features: [Promise.allSettled]
---*/

var resolveElementFunction;
var thenable = {
then(fulfill) {
resolveElementFunction = fulfill;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(Object.prototype.hasOwnProperty.call(resolveElementFunction, 'prototype'), false);
assert.throws(TypeError, function() {
new resolveElementFunction();
});
@@ -0,0 +1,31 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled-resolve-element-functions
description: The [[Prototype]] of Promise.allSettled Resolve Element functions
info: |
17 ECMAScript Standard Built-in Objects:
Unless otherwise specified every built-in function and every built-in
constructor has the Function prototype object, which is the initial
value of the expression Function.prototype (19.2.3), as the value of
its [[Prototype]] internal slot.
features: [Promise.allSettled]
---*/

var resolveElementFunction;
var thenable = {
then(fulfill) {
resolveElementFunction = fulfill;
}
};

function NotPromise(executor) {
executor(function() {}, function() {});
}
NotPromise.resolve = function(v) {
return v;
};
Promise.allSettled.call(NotPromise, [thenable]);

assert.sameValue(Object.getPrototypeOf(resolveElementFunction), Function.prototype);
@@ -0,0 +1,89 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-performpromiseallsettled
description: >
Cannot tamper remainingElementsCount when Promise.allSettled resolve element function is called multiple times.
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )

4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
...
6.d ...
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
iii. If remainingElementsCount.[[value]] is 0, then
1. Let valuesArray be CreateArrayFromList(values).
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
...

Promise.allSettled Resolve Element Functions

2. Let alreadyCalled be F.[[AlreadyCalled]].
3. If alreadyCalled.[[Value]] is true, return undefined.
4. Set alreadyCalled.[[Value]] to true.
...
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var callCount = 0;

function Constructor(executor) {
function resolve(values) {
callCount += 1;
checkSettledPromises(values, [
{
status: 'fulfilled',
value: 'p1-fulfill'
},
{
status: 'fulfilled',
value: 'p2-fulfill'
},
{
status: 'fulfilled',
value: 'p3-fulfill'
}
], 'values');
}
executor(resolve, $ERROR);
}
Constructor.resolve = function(v) {
return v;
};

var p1OnFulfilled, p2OnFulfilled, p3OnFulfilled;

var p1 = {
then(onFulfilled, onRejected) {
p1OnFulfilled = onFulfilled;
}
};
var p2 = {
then(onFulfilled, onRejected) {
p2OnFulfilled = onFulfilled;
}
};
var p3 = {
then(onFulfilled, onRejected) {
p3OnFulfilled = onFulfilled;
}
};

assert.sameValue(callCount, 0, 'callCount before call to all()');

Promise.allSettled.call(Constructor, [p1, p2, p3]);

assert.sameValue(callCount, 0, 'callCount after call to all()');

p1OnFulfilled('p1-fulfill');
p1OnFulfilled('p1-fulfill-unexpected-1');
p1OnFulfilled('p1-fulfill-unexpected-2');

assert.sameValue(callCount, 0, 'callCount after resolving p1');

p2OnFulfilled('p2-fulfill');
p3OnFulfilled('p3-fulfill');

assert.sameValue(callCount, 1, 'callCount after resolving all elements');
@@ -0,0 +1,39 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Resolving with a non-thenable object value
esid: sec-promise.allsettled
info: |
Promise.allSettled Resolve Element Functions

14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be ! CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
flags: [async]
includes: [compareArray.js, promiseHelper.js]
features: [Promise.allSettled]
---*/

var v1 = {};
var v2 = {};
var v3 = {};

Promise.allSettled([v1, v2, v3])
.then(function(values) {
checkSettledPromises(values, [
{
status: 'fulfilled',
value: v1
},
{
status: 'fulfilled',
value: v2
},
{
status: 'fulfilled',
value: v3
}
], 'values');
}, function() {
$DONE('The promise should not be rejected.');
}).then($DONE, $DONE);
@@ -0,0 +1,46 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Resolving with an object with a "poisoned" `then` property
esid: sec-promise.allsettled
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )

4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
...
6.d ...
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
iii. If remainingElementsCount.[[value]] is 0, then
1. Let valuesArray be CreateArrayFromList(values).
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
...
flags: [async]
features: [Promise.allSettled]
---*/

var value = {};
var promise;

try {
Object.defineProperty(Array.prototype, 'then', {
get() {
throw value;
},
configurable: true
});

promise = Promise.allSettled([]);
} finally {
delete Array.prototype.then;
}

promise.then(function() {
$DONE('The promise should not be fulfilled.');
}, function(val) {
if (val !== value) {
$DONE('The promise should be rejected with the expected value.');
return;
}

$DONE();
});
@@ -0,0 +1,29 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Resolving with a thenable object value
esid: sec-promise.allsettled
info: |
Let promiseCapability be NewPromiseCapability(C).
flags: [async]
features: [Promise.allSettled]
---*/

var value = {};
var promise;

try {
Array.prototype.then = function(resolve) {
resolve(value);
};

promise = Promise.allSettled([]);
} finally {
delete Array.prototype.then;
}

promise.then(function(val) {
assert.sameValue(val, value);
}, function() {
$DONE('The promise should not be rejected.');
}).then($DONE, $DONE);
@@ -0,0 +1,64 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Resolution is a collection of all the settled values (all fulfilled)
info: |
Runtime Semantics: PerformPromiseAllSettled

6. Repeat,
...
j. Let steps be the algorithm steps defined in Promise.allSettled Resolve Element Functions.
k. Let resolveElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
r. Let rejectSteps be the algorithm steps defined in Promise.allSettled Reject Element Functions.
s. Let rejectElement be ! CreateBuiltinFunction(rejectSteps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).

Promise.allSettled Resolve Element Functions

9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "fulfilled").
11. Perform ! CreateDataProperty(obj, "value", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be ! CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).

Promise.allSettled Reject Element Functions

9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "rejected").
11. Perform ! CreateDataProperty(obj, "reason", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
flags: [async]
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var obj = {};
var p1 = new Promise(function(resolve) {
resolve(1);
});
var p2 = new Promise(function(resolve) {
resolve('test262');
});
var p3 = new Promise(function(resolve) {
resolve(obj);
});

Promise.allSettled([p1, p2, p3]).then(function(settled) {
checkSettledPromises(settled, [
{ status: 'fulfilled', value: 1 },
{ status: 'fulfilled', value: 'test262' },
{ status: 'fulfilled', value: obj }
], 'settled');
}).then($DONE, $DONE);
@@ -0,0 +1,77 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Resolution is a collection of all the settled values (fulfilled and rejected)
info: |
Runtime Semantics: PerformPromiseAllSettled

6. Repeat,
...
j. Let steps be the algorithm steps defined in Promise.allSettled Resolve Element Functions.
k. Let resolveElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
r. Let rejectSteps be the algorithm steps defined in Promise.allSettled Reject Element Functions.
s. Let rejectElement be ! CreateBuiltinFunction(rejectSteps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).

Promise.allSettled Resolve Element Functions

9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "fulfilled").
11. Perform ! CreateDataProperty(obj, "value", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be ! CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).

Promise.allSettled Reject Element Functions

9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "rejected").
11. Perform ! CreateDataProperty(obj, "reason", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
flags: [async]
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var obj1 = {};
var obj2 = {};
var r1 = new Promise(function(_, reject) {
reject(1);
});
var f1 = new Promise(function(resolve) {
resolve(2);
});
var f2 = new Promise(function(resolve) {
resolve('tc39');
});
var r2 = new Promise(function(_, reject) {
reject('test262');
});
var r3 = new Promise(function(_, reject) {
reject(obj1);
});
var f3 = new Promise(function(resolve) {
resolve(obj2);
});

Promise.allSettled([r1, f1, f2, r2, r3, f3]).then(function(settled) {
checkSettledPromises(settled, [
{ status: 'rejected', reason: 1 },
{ status: 'fulfilled', value: 2 },
{ status: 'fulfilled', value: 'tc39' },
{ status: 'rejected', reason: 'test262' },
{ status: 'rejected', reason: obj1 },
{ status: 'fulfilled', value: obj2 }
], 'settled');
}).then($DONE, $DONE);
@@ -0,0 +1,64 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Resolution is a collection of all the settled values (fulfiled and rejected promises)
info: |
Runtime Semantics: PerformPromiseAllSettled

6. Repeat,
...
j. Let steps be the algorithm steps defined in Promise.allSettled Resolve Element Functions.
k. Let resolveElement be ! CreateBuiltinFunction(steps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
r. Let rejectSteps be the algorithm steps defined in Promise.allSettled Reject Element Functions.
s. Let rejectElement be ! CreateBuiltinFunction(rejectSteps, « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »).
...
z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).

Promise.allSettled Resolve Element Functions

9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "fulfilled").
11. Perform ! CreateDataProperty(obj, "value", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be ! CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).

Promise.allSettled Reject Element Functions

9. Let obj be ! ObjectCreate(%ObjectPrototype%).
10. Perform ! CreateDataProperty(obj, "status", "rejected").
11. Perform ! CreateDataProperty(obj, "reason", x).
12. Set values[index] to be obj.
13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1.
14. If remainingElementsCount.[[Value]] is 0, then
a. Let valuesArray be CreateArrayFromList(values).
b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »).
flags: [async]
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var obj = {};
var p1 = new Promise(function(_, reject) {
reject(1);
});
var p2 = new Promise(function(_, reject) {
reject('test262');
});
var p3 = new Promise(function(_, reject) {
reject(obj);
});

Promise.allSettled([p1, p2, p3]).then(function(settled) {
checkSettledPromises(settled, [
{ status: 'rejected', reason: 1 },
{ status: 'rejected', reason: 'test262' },
{ status: 'rejected', reason: obj }
], 'settled');
}).then($DONE, $DONE);
@@ -0,0 +1,25 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: Promise.allSettled([]) returns immediately
includes: [promiseHelper.js]
flags: [async]
features: [Promise.allSettled]
---*/

var sequence = [];

Promise.allSettled([]).then(function() {
sequence.push(2);
}).catch($DONE);

Promise.resolve().then(function() {
sequence.push(3);
}).then(function() {
sequence.push(4);
checkSequence(sequence, 'Promises resolved in unexpected sequence');
}).then($DONE, $DONE);

sequence.push(1);
@@ -0,0 +1,44 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: Resolution ticks are set in a predictable sequence with extra then calls
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )

4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
...
6.d ...
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
iii. If remainingElementsCount.[[value]] is 0, then
1. Let valuesArray be CreateArrayFromList(values).
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
...
flags: [async]
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var sequence = [];

var p1 = new Promise(function(resolve) {
resolve({});
});

sequence.push(1);

Promise.allSettled([p1]).then(function(resolved) {
sequence.push(4);
checkSequence(sequence, 'Expected Promise.allSettled().then to queue second');
}).catch($DONE);

p1.then(function() {
sequence.push(3);
checkSequence(sequence, 'Expected p1.then to queue first');
}).then(function() {
sequence.push(5);
checkSequence(sequence, 'Expected final then to queue last');
}).then($DONE, $DONE);

sequence.push(2);
@@ -0,0 +1,58 @@
// Copyright (C) 2019 Leo Balter. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-promise.allsettled
description: >
Resolution ticks are set in a predictable sequence of mixed fulfilled and rejected promises
info: |
Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )

4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
...
6.d ...
ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
iii. If remainingElementsCount.[[value]] is 0, then
1. Let valuesArray be CreateArrayFromList(values).
2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
...
flags: [async]
includes: [promiseHelper.js]
features: [Promise.allSettled]
---*/

var sequence = [];

var p1 = new Promise(function(_, reject) {
reject('');
});
var p2 = new Promise(function(resolve) {
resolve('');
});
var p3 = new Promise(function(_, reject) {
reject('');
});

sequence.push(1);

p1.catch(function() {
sequence.push(3);
checkSequence(sequence, 'Expected to be called first.');
}).catch($DONE);

Promise.allSettled([p1, p2, p3]).then(function() {
sequence.push(6);
checkSequence(sequence, 'Expected to be called fourth.');
}).then($DONE, $DONE);

p2.then(function() {
sequence.push(4);
checkSequence(sequence, 'Expected to be called second.');
}).catch($DONE);

sequence.push(2);

p3.catch(function() {
sequence.push(5);
checkSequence(sequence, 'Expected to be called third.');
}).catch($DONE);