Debian Codegraph @

js/src/tests/test262/built-ins/Promise/any/invoke-resolve-on-values-every-iteration-of-custom.js

raw
1 // |reftest| async
2 // Copyright (C) 2019 Sergey Rubanov. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 description: >
7 Invocation of the constructor's `resolve` method for iterable with non-promise values
8 esid: sec-promise.any
9 info: |
10 5. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability).
11
12 Runtime Semantics: PerformPromiseAny
13
14 8. Repeat
15 ...
16 i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »).
17
18 flags: [async]
19 features: [Promise.any, class, arrow-function]
20 ---*/
21 class Custom extends Promise {}
22
23 let values = [1, 2, 3];
24 let cresolveCallCount = 0;
25 let presolveCallCount = 0;
26 let boundCustomResolve = Custom.resolve.bind(Custom);
27 let boundPromiseResolve = Promise.resolve.bind(Promise);
28
29 Custom.resolve = function(...args) {
30 cresolveCallCount += 1;
31 return boundCustomResolve(...args);
32 };
33
34 Promise.resolve = function(...args) {
35 presolveCallCount += 1;
36 return boundPromiseResolve(...args);
37 };
38
39 Promise.any.call(Custom, values)
40 .then(() => {
41 assert.sameValue(presolveCallCount, 0, '`Promise.resolve` is never invoked');
42 assert.sameValue(cresolveCallCount, 3, '`Custom.resolve` invoked once for every iterated promise');
43 }).then($DONE, $DONE);
44