| 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 resolver; | 8 var reject; |
| 9 | 9 |
| 10 var firstPromise = new Promise(function(newResolver) { | 10 var firstPromise = new Promise(function(newResolve, newReject) { |
| 11 global.thisInInit = this; | 11 global.thisInInit = this; |
| 12 resolver = newResolver; | 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 shouldBeTrue('thisInFulfillCallback === secondPromise'); |
| 19 global.result = result; | 19 global.result = result; |
| 20 shouldBeEqualToString('result', 'hello'); | 20 shouldBeEqualToString('result', 'hello'); |
| 21 return 'bye'; | 21 return 'bye'; |
| 22 }); | 22 }); |
| 23 | 23 |
| 24 secondPromise.then(function(result) { | 24 secondPromise.then(function(result) { |
| 25 global.result = result; | 25 global.result = result; |
| 26 shouldBeEqualToString('result', 'bye'); | 26 shouldBeEqualToString('result', 'bye'); |
| 27 testPassed('fulfilled'); | 27 testPassed('fulfilled'); |
| 28 finishJSTest(); | 28 finishJSTest(); |
| 29 }, function() { | 29 }, function() { |
| 30 testFailed('rejected'); | 30 testFailed('rejected'); |
| 31 finishJSTest(); | 31 finishJSTest(); |
| 32 }, function() { | 32 }, function() { |
| 33 }); | 33 }); |
| 34 | 34 |
| 35 shouldBeTrue('thisInInit === firstPromise'); | 35 shouldBeTrue('thisInInit === firstPromise'); |
| 36 shouldBeTrue('firstPromise instanceof Promise'); | 36 shouldBeTrue('firstPromise instanceof Promise'); |
| 37 shouldBeTrue('secondPromise instanceof Promise'); | 37 shouldBeTrue('secondPromise instanceof Promise'); |
| 38 | 38 |
| 39 shouldThrow('firstPromise.catch(null)', '"TypeError: rejectCallback must be a fu
nction or undefined"'); | 39 shouldThrow('firstPromise.catch(null)', '"TypeError: rejectCallback must be a fu
nction or undefined"'); |
| 40 shouldThrow('firstPromise.catch(37)', '"TypeError: rejectCallback must be a func
tion or undefined"'); | 40 shouldThrow('firstPromise.catch(37)', '"TypeError: rejectCallback must be a func
tion or undefined"'); |
| 41 | 41 |
| 42 resolver.reject('hello'); | 42 reject('hello'); |
| 43 | 43 |
| OLD | NEW |