OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug --harmony-async-await --allow-natives-syntax |
6 // Test the mirror object for promises. | 6 // Test the mirror object for promises. |
7 | 7 |
| 8 var AsyncFunction = (async function() {}).constructor; |
| 9 |
8 function MirrorRefCache(json_refs) { | 10 function MirrorRefCache(json_refs) { |
9 var tmp = eval('(' + json_refs + ')'); | 11 var tmp = eval('(' + json_refs + ')'); |
10 this.refs_ = []; | 12 this.refs_ = []; |
11 for (var i = 0; i < tmp.length; i++) { | 13 for (var i = 0; i < tmp.length; i++) { |
12 this.refs_[tmp[i].handle] = tmp[i]; | 14 this.refs_[tmp[i].handle] = tmp[i]; |
13 } | 15 } |
14 } | 16 } |
15 | 17 |
16 MirrorRefCache.prototype.lookup = function(handle) { | 18 MirrorRefCache.prototype.lookup = function(handle) { |
17 return this.refs_[handle]; | 19 return this.refs_[handle]; |
(...skipping 28 matching lines...) Expand all Loading... |
46 var fromJSON = eval('(' + json + ')'); | 48 var fromJSON = eval('(' + json + ')'); |
47 assertEquals('promise', fromJSON.type); | 49 assertEquals('promise', fromJSON.type); |
48 assertEquals('Object', fromJSON.className); | 50 assertEquals('Object', fromJSON.className); |
49 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); | 51 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); |
50 assertEquals('Promise', refs.lookup(fromJSON.constructorFunction.ref).name); | 52 assertEquals('Promise', refs.lookup(fromJSON.constructorFunction.ref).name); |
51 assertEquals(status, fromJSON.status); | 53 assertEquals(status, fromJSON.status); |
52 assertEquals(value, refs.lookup(fromJSON.promiseValue.ref).value); | 54 assertEquals(value, refs.lookup(fromJSON.promiseValue.ref).value); |
53 } | 55 } |
54 | 56 |
55 // Test a number of different promises. | 57 // Test a number of different promises. |
56 var resolved = new Promise(function(resolve, reject) { resolve() }); | 58 var resolved = (async function() {})(); |
57 var rejected = new Promise(function(resolve, reject) { reject() }); | 59 var rejected = (async function() { throw undefined; })(); |
58 var pending = new Promise(function(resolve, reject) {}); | 60 var pending = (async function() { await 1; })(); |
59 | 61 |
60 testPromiseMirror(resolved, "resolved", undefined); | 62 testPromiseMirror(resolved, "resolved", undefined); |
61 testPromiseMirror(rejected, "rejected", undefined); | 63 testPromiseMirror(rejected, "rejected", undefined); |
62 testPromiseMirror(pending, "pending", undefined); | 64 testPromiseMirror(pending, "pending", undefined); |
63 | 65 |
64 var resolvedv = new Promise(function(resolve, reject) { resolve('resolve') }); | 66 var resolvedv = (async function() { return "resolve"; })(); |
65 var rejectedv = new Promise(function(resolve, reject) { reject('reject') }); | 67 var rejectedv = (async function() { return Promise.reject("reject"); })(); |
66 var thrownv = new Promise(function(resolve, reject) { throw 'throw' }); | 68 var thrownv = (async function() { throw "throw"; })(); |
67 | 69 |
68 testPromiseMirror(resolvedv, "resolved", 'resolve'); | 70 testPromiseMirror(resolvedv, "resolved", 'resolve'); |
69 testPromiseMirror(rejectedv, "rejected", 'reject'); | 71 testPromiseMirror(rejectedv, "rejected", 'reject'); |
70 testPromiseMirror(thrownv, "rejected", 'throw'); | 72 testPromiseMirror(thrownv, "rejected", 'throw'); |
71 | 73 |
72 // Test internal properties of different promises. | 74 // Test internal properties of different promises. |
73 var m1 = debug.MakeMirror(new Promise( | 75 var m1 = debug.MakeMirror((async function() { return 1; })()); |
74 function(resolve, reject) { resolve(1) })); | |
75 var ip = m1.internalProperties(); | 76 var ip = m1.internalProperties(); |
76 assertEquals(2, ip.length); | 77 assertEquals(2, ip.length); |
77 assertEquals("[[PromiseStatus]]", ip[0].name()); | 78 assertEquals("[[PromiseStatus]]", ip[0].name()); |
78 assertEquals("[[PromiseValue]]", ip[1].name()); | 79 assertEquals("[[PromiseValue]]", ip[1].name()); |
79 assertEquals("resolved", ip[0].value().value()); | 80 assertEquals("resolved", ip[0].value().value()); |
80 assertEquals(1, ip[1].value().value()); | 81 assertEquals(1, ip[1].value().value()); |
81 | 82 |
82 var m2 = debug.MakeMirror(new Promise(function(resolve, reject) { reject(2) })); | 83 var m2 = debug.MakeMirror((async function() { throw 2; })()); |
83 ip = m2.internalProperties(); | 84 ip = m2.internalProperties(); |
84 assertEquals("rejected", ip[0].value().value()); | 85 assertEquals("rejected", ip[0].value().value()); |
85 assertEquals(2, ip[1].value().value()); | 86 assertEquals(2, ip[1].value().value()); |
86 | 87 |
87 var m3 = debug.MakeMirror(new Promise(function(resolve, reject) { })); | 88 var m3 = debug.MakeMirror((async function() { await 1; })()); |
88 ip = m3.internalProperties(); | 89 ip = m3.internalProperties(); |
89 assertEquals("pending", ip[0].value().value()); | 90 assertEquals("pending", ip[0].value().value()); |
90 assertEquals("undefined", typeof(ip[1].value().value())); | 91 assertEquals("undefined", typeof(ip[1].value().value())); |
| 92 |
| 93 %RunMicrotasks(); |
OLD | NEW |