summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/fast/js/Promise-init.html
blob: 688245118d1f62ee194b2c28e686f598f9aae305 (plain)
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
<!DOCTYPE html>
<html>
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
window.jsTestIsAsync = true;

description('Test Promise.');

var thisInInit;
var resolve, reject;
var promise = new Promise(function(newResolve, newReject) {
  thisInInit = this;
  resolve = newResolve;
  reject = newReject;
});

shouldBeTrue('promise instanceof Promise');
shouldBe('promise.constructor', 'Promise');
shouldBeFalse('thisInInit === promise');
shouldBeTrue('thisInInit === window');
shouldBeTrue('resolve instanceof Function');
shouldBeTrue('reject instanceof Function');

shouldThrow('new Promise()', '"TypeError: Promise constructor takes a function argument"');
shouldThrow('new Promise(37)', '"TypeError: Promise constructor takes a function argument"');

shouldNotThrow('promise = new Promise(function() { throw Error("foo"); })');
promise.then(undefined, function(result) {
  window.result = result;
  shouldBeEqualToString('result.message', 'foo');
});

new Promise(function(resolve) {
  resolve("hello");
  throw Error("foo");
}).then(function(result) {
  window.result = result;
  testPassed('fulfilled');
  shouldBeEqualToString('result', 'hello');
  finishJSTest();
}, function(result) {
  window.result = result;
  testFailed('rejected');
  finishJSTest();
});

</script>
</body>
</html>