Debian Codegraph @

js/src/tests/test262/built-ins/Promise/any/call-reject-element-items.js

raw
1 // Copyright (C) 2020 Rick Waldron. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-promise.any-reject-element-functions
6 description: >
7 Cannot change result value of rejected Promise.any elements.
8 info: |
9 Promise.any Reject Element Functions
10
11 Let alreadyCalled be the value of F's [[AlreadyCalled]] internal slot.
12 If alreadyCalled.[[value]] is true, return undefined.
13 Set alreadyCalled.[[value]] to true.
14
15 features: [Promise.any]
16 ---*/
17
18 let callCount = 0;
19
20 function Constructor(executor) {
21 function reject(error) {
22 callCount += 1;
23 assert(Array.isArray(error.errors), "error.errors is array");
24 assert.sameValue(error.errors.length, 2, "error.errors length");
25 assert.sameValue(error.errors[0], "expectedValue-p1", "error.errors[0]");
26 assert.sameValue(error.errors[1], "expectedValue-p2", "error.errors[1]");
27 }
28 executor(Test262Error.thrower, reject);
29 }
30 Constructor.resolve = function(v) {
31 return v;
32 };
33
34 let p1 = {
35 then(onFulfilled, onRejected) {
36 onRejected("expectedValue-p1");
37 onRejected("unexpectedValue-p1");
38 }
39 };
40 let p2 = {
41 then(onFulfilled, onRejected) {
42 onRejected("expectedValue-p2");
43 onRejected("unexpectedValue-p2");
44 }
45 };
46
47 assert.sameValue(callCount, 0, "callCount before call to any()");
48
49 Promise.any.call(Constructor, [p1, p2]);
50
51 assert.sameValue(callCount, 1, "callCount after call to any()");
52
53 reportCompare(0, 0);