1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description('Test Promise.race');
window.jsTestIsAsync = true;
result = undefined;
var p1 = new Promise(function(resolve) { resolve('p1'); });
var p2 = new Promise(function(resolve) { resolve('p2'); });
var p3 = new Promise(function(resolve) { resolve('p3'); });
var p4 = new Promise(function() {});
var p5 = new Promise(function() {});
var p6 = new Promise(function(_, reject) { reject('p6'); });
var p7 = new Promise(function(_, reject) { reject('p7'); });
var p8 = new Promise(function(_, reject) { reject('p8'); });
var p9 = new Promise(function(resolve) { resolve(p2); });
Promise.race([p4, p5]).then(function(result) {
testFailed('Promise.race([p4, p5]) is fulfilled.');
}, function() {
testFailed('Promise.race([p4, p5]) is rejected.');
});
Promise.race().then(function(result) {
testFailed('Promise.race() is fulfilled.');
}, function() {
testFailed('Promise.race() is rejected.');
});
Promise.race({}).then(function(result) {
testFailed('Promise.race({}) is fulfilled.');
}, function() {
testFailed('Promise.race({}) is rejected.');
});
// If the argument is an empty array, the result promise won't be fulfilled.
Promise.race([]).then(function(result) {
testFailed('Promise.race([]) is fulfilled.');
}, function() {
testFailed('Promise.race([]) is rejected.');
});
Promise.race([p4, p1, p6]).then(function(result) {
testPassed('Promise.race([p4, p1, p6]) is fulfilled.');
window.result = result;
shouldBeEqualToString('result', 'p1');
}, function() {
testFailed('Promise.race([p4, p1, p6]) is rejected.');
}).then(function() {
return Promise.race([p4, p6, p1]).then(function(result) {
testFailed('Promise.race([p4, p6, p1]) is fulfilled.');
}, function(result) {
testPassed('Promise.race([p4, p6, p1]) is rejected.');
window.result = result;
shouldBeEqualToString('result', 'p6');
});
}).then(function() {
return Promise.race([p9]).then(function(result) {
testPassed('Promise.race([p9]) is fulfilled.');
window.result = result;
shouldBeEqualToString('result', 'p2');
}, function() {
testFailed('Promise.race([p9]) is rejected.');
});
}).then(function() {
// Array hole should not be skipped.
return Promise.race([p4,,]).then(function(result) {
testPassed('Promise.race([p4,,]) is fulfilled.');
window.result = result;
shouldBe('result', 'undefined');
}, function() {
testFailed('Promise.race([p4,,]) is rejected.');
});
}).then(function() {
// Immediate value should be converted to a promise object by the
// ToPromise operation.
return Promise.race([p4,42]).then(function(result) {
testPassed('Promise.race([p4,42]) is fulfilled.');
window.result = result;
shouldBe('result', '42');
}, function() {
testFailed('Promise.race([p4,42]) is rejected.');
});
}).then(finishJSTest, finishJSTest);
shouldBe('result', 'undefined');
</script>
</body>
</html>
|