OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | |
29 | 28 |
30 "use strict"; | 29 "use strict"; |
31 let top_level_let = 255; | 30 let top_level_let = 255; |
32 | 31 |
33 // Get the Debug object exposed from the debug context global object. | |
34 var Debug = debug.Debug; | 32 var Debug = debug.Debug; |
35 | 33 |
36 function CheckScope(scope_mirror, scope_expectations, expected_scope_type) { | 34 const ScopeType = debug.ScopeType; |
37 assertEquals(expected_scope_type, scope_mirror.scopeType()); | |
38 | 35 |
39 var scope_object = scope_mirror.scopeObject().value(); | 36 let exception = null; |
| 37 let listenerDelegate = null; |
| 38 |
| 39 const expected_break_count = 5; |
| 40 let break_count = 0; |
| 41 |
| 42 Debug.setListener(function(event, exec_state, event_data, data) { |
| 43 if (event != Debug.DebugEvent.Break) return; |
| 44 try { |
| 45 break_count++; |
| 46 listenerDelegate(exec_state); |
| 47 } catch (e) { |
| 48 exception = e; |
| 49 print(e, e.stack); |
| 50 } |
| 51 }); |
| 52 |
| 53 function CheckScope(scope_frame, scope_expectations, expected_scope_type) { |
| 54 assertEquals(expected_scope_type, scope_frame.scopeType()); |
| 55 |
| 56 var scope_object = scope_frame.scopeObject().value(); |
40 | 57 |
41 for (let name in scope_expectations) { | 58 for (let name in scope_expectations) { |
42 let actual = scope_object[name]; | 59 let actual = scope_object[name]; |
43 let expected = scope_expectations[name]; | 60 let expected = scope_expectations[name]; |
44 assertEquals(expected, actual); | 61 assertEquals(expected, actual); |
45 } | 62 } |
46 } | 63 } |
47 | 64 |
48 // A copy of the scope types from debug/mirrors.js. | 65 // --- |
49 var ScopeType = { Global: 0, | |
50 Local: 1, | |
51 With: 2, | |
52 Closure: 3, | |
53 Catch: 4, | |
54 Block: 5, | |
55 Script: 6}; | |
56 | 66 |
57 var f1 = (function F1(x) { | 67 listenerDelegate = function(exec_state) { |
| 68 const frame = exec_state.frame(0); |
| 69 |
| 70 assertEquals(6, frame.scopeCount()); |
| 71 |
| 72 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 73 CheckScope(frame.scope(1), { a: 4, b: 5 }, ScopeType.Closure); |
| 74 CheckScope(frame.scope(2), { z: 22, w: 5, v: "Capybara" }, ScopeType.Closure); |
| 75 CheckScope(frame.scope(3), { x: 5 }, ScopeType.Closure); |
| 76 CheckScope(frame.scope(4), { top_level_let: 255 }, ScopeType.Script); |
| 77 CheckScope(frame.scope(5), {}, ScopeType.Global); |
| 78 }; |
| 79 |
| 80 (function F1(x) { |
58 function F2(y) { | 81 function F2(y) { |
59 var z = x + y; | 82 var z = x + y; |
60 { | 83 { |
61 var w = 5; | 84 var w = 5; |
62 var v = "Capybara"; | 85 var v = "Capybara"; |
63 var F3 = function(a, b) { | 86 var F3 = function(a, b) { |
64 function F4(p) { | 87 function F4(p) { |
| 88 debugger; |
65 return p + a + b + z + w + v.length; | 89 return p + a + b + z + w + v.length; |
66 } | 90 } |
67 return F4; | 91 return F4; |
68 } | 92 } |
69 return F3(4, 5); | 93 return F3(4, 5); |
70 } | 94 } |
71 } | 95 } |
72 return F2(17); | 96 return F2(17); |
73 })(5); | 97 })(5)(); |
74 | 98 |
75 var mirror = Debug.MakeMirror(f1); | 99 // --- |
76 | 100 |
77 assertEquals(5, mirror.scopeCount()); | 101 listenerDelegate = function(exec_state) { |
| 102 const frame = exec_state.frame(0); |
78 | 103 |
79 CheckScope(mirror.scope(0), { a: 4, b: 5 }, ScopeType.Closure); | 104 assertEquals(6, frame.scopeCount()); |
80 CheckScope(mirror.scope(1), { z: 22, w: 5, v: "Capybara" }, ScopeType.Closure); | |
81 CheckScope(mirror.scope(2), { x: 5 }, ScopeType.Closure); | |
82 CheckScope(mirror.scope(3), { top_level_let: 255 }, ScopeType.Script); | |
83 CheckScope(mirror.scope(4), {}, ScopeType.Global); | |
84 | 105 |
85 var f2 = (function() { | 106 CheckScope(frame.scope(0), {}, ScopeType.Local); |
| 107 CheckScope(frame.scope(1), { l3: 9 }, ScopeType.Block); |
| 108 CheckScope(frame.scope(2), { l2: 7 }, ScopeType.Block); |
| 109 CheckScope(frame.scope(3), { v1:3, l0: 0, v3: 5, v6: 11 }, ScopeType.Closure); |
| 110 CheckScope(frame.scope(4), { top_level_let: 255 }, ScopeType.Script); |
| 111 CheckScope(frame.scope(5), {}, ScopeType.Global); |
| 112 }; |
| 113 |
| 114 (function() { |
86 var v1 = 3; | 115 var v1 = 3; |
87 var v2 = 4; | 116 var v2 = 4; |
88 let l0 = 0; | 117 let l0 = 0; |
89 { | 118 { |
90 var v3 = 5; | 119 var v3 = 5; |
91 let l1 = 6; | 120 let l1 = 6; |
92 let l2 = 7; | 121 let l2 = 7; |
93 { | 122 { |
94 var v4 = 8; | 123 var v4 = 8; |
95 let l3 = 9; | 124 let l3 = 9; |
96 { | 125 { |
97 var v5 = "Cat"; | 126 var v5 = "Cat"; |
98 let l4 = 11; | 127 let l4 = 11; |
99 var v6 = l4; | 128 var v6 = l4; |
100 return function() { | 129 return function() { |
| 130 debugger; |
101 return l0 + v1 + v3 + l2 + l3 + v6; | 131 return l0 + v1 + v3 + l2 + l3 + v6; |
102 }; | 132 }; |
103 } | 133 } |
104 } | 134 } |
105 } | 135 } |
106 })(); | 136 })()(); |
107 | |
108 var mirror = Debug.MakeMirror(f2); | |
109 | |
110 assertEquals(5, mirror.scopeCount()); | |
111 | |
112 CheckScope(mirror.scope(0), { l3: 9 }, ScopeType.Block); | |
113 CheckScope(mirror.scope(1), { l2: 7 }, ScopeType.Block); | |
114 CheckScope(mirror.scope(2), { v1:3, l0: 0, v3: 5, v6: 11 }, ScopeType.Closure); | |
115 CheckScope(mirror.scope(3), { top_level_let: 255 }, ScopeType.Script); | |
116 CheckScope(mirror.scope(4), {}, ScopeType.Global); | |
OLD | NEW |