Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/built-ins/Promise/all/resolve-before-loop-exit-from-same.js

raw
1 // Copyright (C) 2015 André Bargull. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 es6id: 25.4.4.1.1
6 description: >
7 Cannot tamper remainingElementsCount when Promise.all resolve element function is called twice in a row.
8 info: |
9 Runtime Semantics: PerformPromiseAll( iteratorRecord, constructor, resultCapability)
10
11 ...
12 4. Let remainingElementsCount be a new Record { [[value]]: 1 }.
13 ...
14 6.d ...
15 ii. Set remainingElementsCount.[[value]] to remainingElementsCount.[[value]] − 1.
16 iii. If remainingElementsCount.[[value]] is 0,
17 1. Let valuesArray be CreateArrayFromList(values).
18 2. Let resolveResult be Call(resultCapability.[[Resolve]], undefined, «valuesArray»).
19 3. ReturnIfAbrupt(resolveResult).
20 ...
21
22 25.4.4.1.2 Promise.all Resolve Element Functions
23 1. Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot.
24 2. If alreadyCalled.[[value]] is true, return undefined.
25 3. Set alreadyCalled.[[value]] to true.
26 ...
27 ---*/
28
29 var callCount = 0;
30
31 function Constructor(executor) {
32 function resolve(values) {
33 callCount += 1;
34 assert(Array.isArray(values), "values is array");
35 assert.sameValue(values.length, 3, "values length");
36 assert.sameValue(values[0], "p1-fulfill", "values[0]");
37 assert.sameValue(values[1], "p2-fulfill", "values[1]");
38 assert.sameValue(values[2], "p3-fulfill", "values[2]");
39 }
40 executor(resolve, $ERROR);
41 }
42 Constructor.resolve = function(v) {
43 return v;
44 };
45
46 var p1OnFulfilled;
47
48 var p1 = {
49 then: function(onFulfilled, onRejected) {
50 p1OnFulfilled = onFulfilled;
51 }
52 };
53 var p2 = {
54 then: function(onFulfilled, onRejected) {
55 onFulfilled("p2-fulfill");
56 onFulfilled("p2-fulfill-unexpected");
57 }
58 };
59 var p3 = {
60 then: function(onFulfilled, onRejected) {
61 onFulfilled("p3-fulfill");
62 }
63 };
64
65 assert.sameValue(callCount, 0, "callCount before call to all()");
66
67 Promise.all.call(Constructor, [p1, p2, p3]);
68
69 assert.sameValue(callCount, 0, "callCount after call to all()");
70
71 p1OnFulfilled("p1-fulfill");
72
73 assert.sameValue(callCount, 1, "callCount after resolving p1");