| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <div id="description"></div> |
| <div id="console"></div> |
| <script> |
| description('Test Promise.'); |
| |
| window.jsTestIsAsync = true; |
| |
| var resolver; |
| |
| var firstPromise = new Promise(function(newResolver) { |
| window.thisInInit = this; |
| resolver = newResolver; |
| }); |
| |
| var secondPromise = firstPromise.then(function(result) { |
| window.thisInFulfillCallback = this; |
| shouldBeFalse('thisInFulfillCallback === firstPromise'); |
| shouldBeTrue('thisInFulfillCallback === secondPromise'); |
| window.result = result; |
| shouldBeEqualToString('result', 'hello'); |
| finishJSTest(); |
| }); |
| |
| shouldBeTrue('thisInInit === firstPromise'); |
| shouldBeTrue('firstPromise instanceof Promise'); |
| shouldBeTrue('secondPromise instanceof Promise'); |
| |
| shouldThrow('firstPromise.then(null)', '"TypeError: Expected function or undefined as as first argument"'); |
| shouldThrow('firstPromise.then(undefined, null)', '"TypeError: Expected function or undefined as as second argument"'); |
| shouldThrow('firstPromise.then(37)', '"TypeError: Expected function or undefined as as first argument"'); |
| |
| resolver.fulfill('hello'); |
| |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |