OLD | NEW |
1 importScripts('./js-test-pre.js'); | 1 importScripts('./js-test-pre.js'); |
2 | 2 |
3 description('Test Promise.'); | 3 description('Test Promise.'); |
4 | 4 |
5 var global = this; | 5 var global = this; |
6 | 6 |
7 global.jsTestIsAsync = true; | 7 global.jsTestIsAsync = true; |
8 var reject; | 8 var reject; |
9 | 9 |
10 var firstPromise = new Promise(function(newResolve, newReject) { | 10 var firstPromise = new Promise(function(newResolve, newReject) { |
11 global.thisInInit = this; | 11 global.thisInInit = this; |
12 reject = newReject; | 12 reject = newReject; |
13 }); | 13 }); |
14 | 14 |
15 var secondPromise = firstPromise.catch(function(result) { | 15 var secondPromise = firstPromise.catch(function(result) { |
16 global.thisInFulfillCallback = this; | 16 global.thisInFulfillCallback = this; |
17 shouldBeFalse('thisInFulfillCallback === firstPromise'); | 17 shouldBeFalse('thisInFulfillCallback === firstPromise'); |
18 shouldBeTrue('thisInFulfillCallback === secondPromise'); | 18 shouldBeFalse('thisInFulfillCallback === secondPromise'); |
| 19 shouldBeTrue('thisInFulfillCallback === global'); |
19 global.result = result; | 20 global.result = result; |
20 shouldBeEqualToString('result', 'hello'); | 21 shouldBeEqualToString('result', 'hello'); |
21 return 'bye'; | 22 return 'bye'; |
22 }); | 23 }); |
23 | 24 |
24 secondPromise.then(function(result) { | 25 secondPromise.then(function(result) { |
25 global.result = result; | 26 global.result = result; |
26 shouldBeEqualToString('result', 'bye'); | 27 shouldBeEqualToString('result', 'bye'); |
27 testPassed('fulfilled'); | 28 testPassed('fulfilled'); |
28 finishJSTest(); | 29 finishJSTest(); |
29 }, function() { | 30 }, function() { |
30 testFailed('rejected'); | 31 testFailed('rejected'); |
31 finishJSTest(); | 32 finishJSTest(); |
32 }, function() { | 33 }, function() { |
33 }); | 34 }); |
34 | 35 |
35 shouldBeTrue('thisInInit === firstPromise'); | 36 shouldBeFalse('thisInInit === firstPromise'); |
| 37 shouldBeTrue('thisInInit === global'); |
36 shouldBeTrue('firstPromise instanceof Promise'); | 38 shouldBeTrue('firstPromise instanceof Promise'); |
37 shouldBeTrue('secondPromise instanceof Promise'); | 39 shouldBeTrue('secondPromise instanceof Promise'); |
38 | 40 |
39 shouldThrow('firstPromise.catch(null)', '"TypeError: rejectCallback must be a fu
nction or undefined"'); | 41 shouldThrow('firstPromise.catch(null)', '"TypeError: onRejected must be a functi
on or undefined"'); |
40 shouldThrow('firstPromise.catch(37)', '"TypeError: rejectCallback must be a func
tion or undefined"'); | 42 shouldThrow('firstPromise.catch(37)', '"TypeError: onRejected must be a function
or undefined"'); |
41 | 43 |
42 reject('hello'); | 44 reject('hello'); |
43 | 45 |
OLD | NEW |