Debian Codegraph @

js/src/tests/test262/built-ins/Promise/allSettled/resolve-before-loop-exit-from-same.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 esid: sec-performpromiseallsettled
6 description: >
7 Cannot tamper remainingElementsCount when Promise.allSettled resolve element function is called twice in a row.
8 info: |
9 Runtime Semantics: PerformPromiseAllSettled ( iteratorRecord, constructor, resultCapability )
10
11 4. Let remainingElementsCount be a new Record { [[Value]]: 1 }.
12 ...
13 6.d ...
14 ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
15 iii. If remainingElementsCount.[[value]] is 0, then
16 1. Let valuesArray be CreateArrayFromList(values).
17 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »).
18 ...
19
20 Promise.allSettled Resolve Element Functions
21
22 2. Let alreadyCalled be F.[[AlreadyCalled]].
23 3. If alreadyCalled.[[Value]] is true, return undefined.
24 4. Set alreadyCalled.[[Value]] to true.
25 ...
26 includes: [promiseHelper.js]
27 features: [Promise.allSettled]
28 ---*/
29
30 var callCount = 0;
31
32 function Constructor(executor) {
33 function resolve(values) {
34 callCount += 1;
35 checkSettledPromises(values, [
36 {
37 status: 'fulfilled',
38 value: 'p1-fulfill'
39 },
40 {
41 status: 'fulfilled',
42 value: 'p2-fulfill'
43 },
44 {
45 status: 'fulfilled',
46 value: 'p3-fulfill'
47 }
48 ], 'values');
49 }
50 executor(resolve, Test262Error.thrower);
51 }
52 Constructor.resolve = function(v) {
53 return v;
54 };
55
56 var p1OnFulfilled;
57
58 var p1 = {
59 then(onFulfilled, onRejected) {
60 p1OnFulfilled = onFulfilled;
61 }
62 };
63 var p2 = {
64 then(onFulfilled, onRejected) {
65 onFulfilled('p2-fulfill');
66 onFulfilled('p2-fulfill-unexpected');
67 }
68 };
69 var p3 = {
70 then(onFulfilled, onRejected) {
71 onFulfilled('p3-fulfill');
72 }
73 };
74
75 assert.sameValue(callCount, 0, 'callCount before call to all()');
76
77 Promise.allSettled.call(Constructor, [p1, p2, p3]);
78
79 assert.sameValue(callCount, 0, 'callCount after call to all()');
80
81 p1OnFulfilled('p1-fulfill');
82
83 assert.sameValue(callCount, 1, 'callCount after resolving p1');
84
85 reportCompare(0, 0);