OLD | NEW |
1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // modification, are permitted provided that the following conditions are | 3 // found in the LICENSE file. |
4 // met: | |
5 // | |
6 // * Redistributions of source code must retain the above copyright | |
7 // notice, this list of conditions and the following disclaimer. | |
8 // * Redistributions in binary form must reproduce the above | |
9 // copyright notice, this list of conditions and the following | |
10 // disclaimer in the documentation and/or other materials provided | |
11 // with the distribution. | |
12 // * Neither the name of Google Inc. nor the names of its | |
13 // contributors may be used to endorse or promote products derived | |
14 // from this software without specific prior written permission. | |
15 // | |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | 4 |
28 // Flags: --expose-debug-as debug | 5 // Flags: --expose-debug-as debug --harmony-async-await --allow-natives-syntax |
29 // Test the mirror object for functions. | 6 // Test the mirror object for functions. |
30 | 7 |
| 8 var AsyncFunction = (async function() {}).constructor; |
| 9 |
31 function MirrorRefCache(json_refs) { | 10 function MirrorRefCache(json_refs) { |
32 var tmp = eval('(' + json_refs + ')'); | 11 var tmp = eval('(' + json_refs + ')'); |
33 this.refs_ = []; | 12 this.refs_ = []; |
34 for (var i = 0; i < tmp.length; i++) { | 13 for (var i = 0; i < tmp.length; i++) { |
35 this.refs_[tmp[i].handle] = tmp[i]; | 14 this.refs_[tmp[i].handle] = tmp[i]; |
36 } | 15 } |
37 } | 16 } |
38 | 17 |
39 MirrorRefCache.prototype.lookup = function(handle) { | 18 MirrorRefCache.prototype.lookup = function(handle) { |
40 return this.refs_[handle]; | 19 return this.refs_[handle]; |
(...skipping 26 matching lines...) Expand all Loading... |
67 assertTrue(mirror.prototypeObject() instanceof debug.Mirror); | 46 assertTrue(mirror.prototypeObject() instanceof debug.Mirror); |
68 | 47 |
69 // Test text representation | 48 // Test text representation |
70 assertEquals(f.toString(), mirror.toText()); | 49 assertEquals(f.toString(), mirror.toText()); |
71 | 50 |
72 // Parse JSON representation and check. | 51 // Parse JSON representation and check. |
73 var fromJSON = eval('(' + json + ')'); | 52 var fromJSON = eval('(' + json + ')'); |
74 assertEquals('function', fromJSON.type); | 53 assertEquals('function', fromJSON.type); |
75 assertEquals('Function', fromJSON.className); | 54 assertEquals('Function', fromJSON.className); |
76 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); | 55 assertEquals('function', refs.lookup(fromJSON.constructorFunction.ref).type); |
77 assertEquals('Function', refs.lookup(fromJSON.constructorFunction.ref).name); | 56 assertEquals('AsyncFunction', |
| 57 refs.lookup(fromJSON.constructorFunction.ref).name); |
78 assertTrue(fromJSON.resolved); | 58 assertTrue(fromJSON.resolved); |
79 assertEquals(f.name, fromJSON.name); | 59 assertEquals(f.name, fromJSON.name); |
80 assertEquals(f.toString(), fromJSON.source); | 60 assertEquals(f.toString(), fromJSON.source); |
81 | 61 |
82 // Check the formatted text (regress 1142074). | 62 // Check the formatted text (regress 1142074). |
83 assertEquals(f.toString(), fromJSON.text); | 63 assertEquals(f.toString(), fromJSON.text); |
84 } | 64 } |
85 | 65 |
86 | 66 |
87 // Test a number of different functions. | 67 // Test a number of different functions. |
88 testFunctionMirror(function(){}); | 68 testFunctionMirror(async function(){}); |
89 testFunctionMirror(function a(){return 1;}); | 69 testFunctionMirror(AsyncFunction()); |
90 testFunctionMirror(Math.sin); | 70 testFunctionMirror(new AsyncFunction()); |
91 testFunctionMirror((function(){}).bind({}), "Object"); | 71 testFunctionMirror(async() => {}); |
| 72 testFunctionMirror(async function a(){return 1;}); |
| 73 testFunctionMirror(({ async foo() {} }).foo); |
| 74 testFunctionMirror((async function(){}).bind({}), "Object"); |
| 75 |
| 76 %RunMicrotasks(); |
OLD | NEW |