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 --expose-gc --allow-natives-syntax | 28 // Flags: --expose-gc |
29 // Flags: --inline-construct | 29 // Flags: --inline-construct |
30 | 30 |
31 // Get the Debug object exposed from the debug context global object. | |
32 Debug = debug.Debug | 31 Debug = debug.Debug |
33 | 32 |
34 var listenerComplete = false; | 33 var listenerComplete = false; |
35 var exception = false; | 34 var exception = false; |
36 | 35 |
37 var testingConstructCall = false; | 36 var testingConstructCall = false; |
38 | 37 |
39 var expected = [ | 38 var expected = [ |
40 { locals: {a0: 1, b0: 2}, | 39 { locals: {i: 0, x0: 3, y0: 4, a0: 1, b0: 2}, |
41 args: { names: ["i", "x0", "y0"], values: [0, 3, 4] } }, | 40 args: { names: ["i", "x0", "y0"], values: [0, 3, 4] } }, |
42 { locals: {a1: 3, b1: 4}, | 41 { locals: {i: 1, x1: 5, y1: 6, a1: 3, b1: 4}, |
43 args: { names: ["i", "x1", "y1"], values: [1, 5, 6] } }, | 42 args: { names: ["i", "x1", "y1"], values: [1, 5, 6] } }, |
44 { locals: {a2: 5, b2: 6}, | 43 { locals: {i: 2, a2: 5, b2: 6}, |
45 args: { names: ["i"], values: [2] } }, | 44 args: { names: ["i"], values: [2] } }, |
46 { locals: {a3: 7, b3: 8}, | 45 { locals: {i: 3, x3: 9, y3: 10, z3: undefined, a3: 7, b3: 8}, |
47 args: { names: ["i", "x3", "y3", "z3"], values: [3, 9, 10, undefined] } }, | 46 args: { names: ["i", "x3", "y3", "z3"], values: [3, 9, 10, undefined] } }, |
48 { locals: {a4: 9, b4: 10}, | 47 { locals: {i: 4, x4: 11, y4: 12, a4: 9, b4: 10}, |
49 args: { names: ["i", "x4", "y4"], values: [4, 11, 12] } } | 48 args: { names: ["i", "x4", "y4"], values: [4, 11, 12] } } |
50 ]; | 49 ]; |
51 | 50 |
52 function arraySum(arr) { | |
53 return arr.reduce(function (a, b) { return a + b; }, 0); | |
54 } | |
55 | |
56 function listener(event, exec_state, event_data, data) { | 51 function listener(event, exec_state, event_data, data) { |
57 try { | 52 try { |
58 if (event == Debug.DebugEvent.Break) | 53 if (event == Debug.DebugEvent.Break) |
59 { | 54 { |
60 assertEquals(6, exec_state.frameCount()); | 55 assertEquals(6, exec_state.frameCount()); |
61 | 56 |
62 for (var i = 0; i < exec_state.frameCount(); i++) { | 57 for (var i = 0; i < exec_state.frameCount(); i++) { |
63 var frame = exec_state.frame(i); | 58 var frame = exec_state.frame(i); |
64 if (i < exec_state.frameCount() - 1) { | 59 if (i < exec_state.frameCount() - 1) { |
65 var expected_args = expected[i].args; | 60 var expected_args = expected[i].args; |
66 var expected_locals = expected[i].locals; | 61 var expected_locals = expected[i].locals; |
67 | 62 |
68 // All frames except the bottom one have expected locals. | 63 // All frames except the bottom one have expected locals. |
69 var locals = {}; | 64 var locals = {}; |
70 for (var j = 0; j < frame.localCount(); j++) { | 65 for (var j = 0; j < frame.localCount(); j++) { |
71 locals[frame.localName(j)] = frame.localValue(j).value(); | 66 locals[frame.localName(j)] = frame.localValue(j).value(); |
72 } | 67 } |
73 assertPropertiesEqual(expected_locals, locals); | 68 assertPropertiesEqual(expected_locals, locals); |
74 | 69 |
75 // All frames except the bottom one have expected arguments. | |
76 for (var j = 0; j < expected_args.names.length; j++) { | |
77 assertEquals(expected_args.names[j], frame.argumentName(j)); | |
78 assertEquals(expected_args.values[j], | |
79 frame.argumentValue(j).value()); | |
80 } | |
81 | |
82 // All frames except the bottom one have three scopes. | 70 // All frames except the bottom one have three scopes. |
83 assertEquals(3, frame.scopeCount()); | 71 assertEquals(3, frame.scopeCount()); |
84 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); | 72 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); |
85 assertEquals(debug.ScopeType.Script, frame.scope(1).scopeType()); | 73 assertEquals(debug.ScopeType.Script, frame.scope(1).scopeType()); |
86 assertEquals(debug.ScopeType.Global, frame.scope(2).scopeType()); | 74 assertEquals(debug.ScopeType.Global, frame.scope(2).scopeType()); |
87 | 75 |
88 Object.keys(expected_locals).forEach(function (name) { | 76 Object.keys(expected_locals).forEach(function (name) { |
89 assertEquals(expected_locals[name], | 77 assertEquals(expected_locals[name], |
90 frame.scope(0).scopeObject().value()[name]); | 78 frame.scope(0).scopeObject().value()[name]); |
91 }); | 79 }); |
92 | 80 |
93 for (var j = 0; j < expected_args.names.length; j++) { | 81 for (var j = 0; j < expected_args.names.length; j++) { |
94 var arg_name = expected_args.names[j]; | 82 var arg_name = expected_args.names[j]; |
95 var arg_value = expected_args.values[j]; | 83 var arg_value = expected_args.values[j]; |
96 assertEquals(arg_value, | 84 assertEquals(arg_value, |
97 frame.scope(0).scopeObject().value()[arg_name]); | 85 frame.scope(0).scopeObject().value()[arg_name]); |
98 } | 86 } |
99 | 87 |
100 // Evaluate in the inlined frame. | 88 // Evaluate in the inlined frame. |
101 Object.keys(expected_locals).forEach(function (name) { | 89 Object.keys(expected_locals).forEach(function (name) { |
102 assertEquals(expected_locals[name], frame.evaluate(name).value()); | 90 assertEquals(expected_locals[name], frame.evaluate(name).value()); |
103 }); | 91 }); |
104 | 92 |
105 for (var j = 0; j < expected_args.names.length; j++) { | 93 for (var j = 0; j < expected_args.names.length; j++) { |
106 var arg_name = expected_args.names[j]; | 94 var arg_name = expected_args.names[j]; |
107 var arg_value = expected_args.values[j]; | 95 var arg_value = expected_args.values[j]; |
108 assertEquals(arg_value, frame.evaluate(arg_name).value()); | 96 assertEquals(arg_value, frame.evaluate(arg_name).value()); |
109 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); | 97 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); |
110 } | 98 } |
111 | |
112 var expected_args_sum = arraySum(expected_args.values); | |
113 var expected_locals_sum = | |
114 arraySum(Object.keys(expected_locals). | |
115 map(function (k) { return expected_locals[k]; })); | |
116 | |
117 assertEquals(expected_locals_sum + expected_args_sum, | |
118 frame.evaluate(Object.keys(expected_locals).join('+') + | |
119 ' + ' + | |
120 expected_args.names.join('+')).value()); | |
121 | |
122 var arguments_sum = expected_args.names.map(function(_, idx) { | |
123 return "arguments[" + idx + "]"; | |
124 }).join('+'); | |
125 assertEquals(expected_args_sum, | |
126 frame.evaluate(arguments_sum).value()); | |
127 } else { | 99 } else { |
128 // The bottom frame only have the script scope and the global scope. | 100 // The bottom frame only have the script scope and the global scope. |
129 assertEquals(2, frame.scopeCount()); | 101 assertEquals(2, frame.scopeCount()); |
130 assertEquals(debug.ScopeType.Script, frame.scope(0).scopeType()); | 102 assertEquals(debug.ScopeType.Script, frame.scope(0).scopeType()); |
131 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); | 103 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); |
132 } | 104 } |
133 | 105 |
134 // Check the frame function. | 106 // Check the frame function. |
135 switch (i) { | 107 switch (i) { |
136 case 0: assertEquals(h, frame.func().value()); break; | 108 case 0: assertEquals("h", frame.func().name()); break; |
137 case 1: assertEquals(g3, frame.func().value()); break; | 109 case 1: assertEquals("g3", frame.func().name()); break; |
138 case 2: assertEquals(g2, frame.func().value()); break; | 110 case 2: assertEquals("g2", frame.func().name()); break; |
139 case 3: assertEquals(g1, frame.func().value()); break; | 111 case 3: assertEquals("g1", frame.func().name()); break; |
140 case 4: assertEquals(f, frame.func().value()); break; | 112 case 4: assertEquals("f", frame.func().name()); break; |
141 case 5: break; | 113 case 5: break; |
142 default: assertUnreachable(); | 114 default: assertUnreachable(); |
143 } | 115 } |
144 | |
145 // Check for construct call. | |
146 if (i == 4) { | |
147 assertEquals(testingConstructCall, frame.isConstructCall()); | |
148 } else if (i == 2) { | |
149 assertTrue(frame.isConstructCall()); | |
150 } else { | |
151 assertFalse(frame.isConstructCall()); | |
152 } | |
153 | |
154 if (i > 4) { | |
155 assertFalse(frame.isOptimizedFrame()); | |
156 assertFalse(frame.isInlinedFrame()); | |
157 } | |
158 } | 116 } |
159 | 117 |
160 // Indicate that all was processed. | 118 // Indicate that all was processed. |
161 listenerComplete = true; | 119 listenerComplete = true; |
162 } | 120 } |
163 } catch (e) { | 121 } catch (e) { |
164 exception = e.toString() + e.stack; | 122 exception = e.toString() + e.stack; |
165 }; | 123 }; |
166 }; | 124 }; |
167 | 125 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 new f(expected.length - 1, 11, 12, 0); | 173 new f(expected.length - 1, 11, 12, 0); |
216 | 174 |
217 // Make sure that the debug event listener was invoked. | 175 // Make sure that the debug event listener was invoked. |
218 assertFalse(exception, "exception in listener " + exception) | 176 assertFalse(exception, "exception in listener " + exception) |
219 assertTrue(listenerComplete); | 177 assertTrue(listenerComplete); |
220 | 178 |
221 // Throw away type information for next run. | 179 // Throw away type information for next run. |
222 gc(); | 180 gc(); |
223 | 181 |
224 Debug.setListener(null); | 182 Debug.setListener(null); |
OLD | NEW |