Debian Codegraph @

js/src/tests/test262/built-ins/Promise/allSettled/invoke-then.js

raw
1 // Copyright (C) 2019 Leo Balter. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: >
6 Invocation of the instance's `then` method
7 esid: sec-promise.allsettled
8 info: |
9 6. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability).
10 7. If result is an abrupt completion, then
11 a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result).
12 b. IfAbruptRejectPromise(result, promiseCapability).
13
14 Runtime Semantics: PerformPromiseAllSettled
15
16 z. Perform ? Invoke(nextPromise, "then", « resolveElement, rejectElement »).
17 features: [Promise.allSettled]
18 ---*/
19
20 var p1 = new Promise(function() {});
21 var p2 = new Promise(function() {});
22 var p3 = new Promise(function() {});
23 var callCount = 0;
24 var currentThis = p1;
25 var nextThis = p2;
26 var afterNextThis = p3;
27
28 p1.then = p2.then = p3.then = function(a, b) {
29 assert.sameValue(typeof a, 'function', 'type of first argument');
30 assert.sameValue(
31 a.length,
32 1,
33 'The length property of a promise resolve function is 1.'
34 );
35 assert.sameValue(typeof b, 'function', 'type of second argument');
36 assert.sameValue(
37 b.length,
38 1,
39 'The length property of a promise reject function is 1.'
40 );
41 assert.sameValue(arguments.length, 2, '`then` invoked with two arguments');
42 assert.sameValue(this, currentThis, '`this` value');
43
44 currentThis = nextThis;
45 nextThis = afterNextThis;
46 afterNextThis = null;
47
48 callCount += 1;
49 };
50
51 Promise.allSettled([p1, p2, p3]);
52
53 assert.sameValue(callCount, 3, '`then` invoked once for every iterated value');
54
55 reportCompare(0, 0);