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 --inline-co
nstruct | 28 // Flags: --expose-debug-as debug --expose-gc --allow-natives-syntax |
| 29 // Flags: --inline-construct |
| 30 |
29 // Get the Debug object exposed from the debug context global object. | 31 // Get the Debug object exposed from the debug context global object. |
30 Debug = debug.Debug | 32 Debug = debug.Debug |
31 | 33 |
32 var listenerComplete = false; | 34 var listenerComplete = false; |
33 var exception = false; | 35 var exception = false; |
34 | 36 |
35 var testingConstructCall = false; | 37 var testingConstructCall = false; |
36 | 38 |
37 var expected = [ | 39 var expected = [ |
38 { locals: {a0: 1, b0: 2}, args: { names: ["i", "x0", "y0"], values: [0, 3, 4]
} }, | 40 { locals: {a0: 1, b0: 2}, |
39 { locals: {a1: 3, b1: 4}, args: { names: ["i", "x1", "y1"], values: [1, 5, 6]
} }, | 41 args: { names: ["i", "x0", "y0"], values: [0, 3, 4] } }, |
40 { locals: {a2: 5, b2: 6}, args: { names: ["i"], values: [2] } }, | 42 { locals: {a1: 3, b1: 4}, |
41 { locals: {a3: 7, b3: 8}, args: { names: ["i", "x3", "y3", "z3"], values: [3,
9, 10, undefined] } }, | 43 args: { names: ["i", "x1", "y1"], values: [1, 5, 6] } }, |
42 { locals: {a4: 9, b4: 10}, args: { names: ["i", "x4", "y4"], values: [4, 11, 1
2] } } | 44 { locals: {a2: 5, b2: 6}, |
| 45 args: { names: ["i"], values: [2] } }, |
| 46 { locals: {a3: 7, b3: 8}, |
| 47 args: { names: ["i", "x3", "y3", "z3"], values: [3, 9, 10, undefined] } }, |
| 48 { locals: {a4: 9, b4: 10}, |
| 49 args: { names: ["i", "x4", "y4"], values: [4, 11, 12] } } |
43 ]; | 50 ]; |
44 | 51 |
45 function arraySum(arr) { | 52 function arraySum(arr) { |
46 return arr.reduce(function (a, b) { return a + b; }, 0); | 53 return arr.reduce(function (a, b) { return a + b; }, 0); |
47 } | 54 } |
48 | 55 |
49 function listener(event, exec_state, event_data, data) { | 56 function listener(event, exec_state, event_data, data) { |
50 try { | 57 try { |
51 if (event == Debug.DebugEvent.Break) | 58 if (event == Debug.DebugEvent.Break) |
52 { | 59 { |
53 assertEquals(6, exec_state.frameCount()); | 60 assertEquals(6, exec_state.frameCount()); |
54 | 61 |
55 for (var i = 0; i < exec_state.frameCount(); i++) { | 62 for (var i = 0; i < exec_state.frameCount(); i++) { |
56 var frame = exec_state.frame(i); | 63 var frame = exec_state.frame(i); |
57 if (i < exec_state.frameCount() - 1) { | 64 if (i < exec_state.frameCount() - 1) { |
58 var expected_args = expected[i].args; | 65 var expected_args = expected[i].args; |
59 var expected_locals = expected[i].locals; | 66 var expected_locals = expected[i].locals; |
60 | 67 |
61 // All frames except the bottom one have expected locals. | 68 // All frames except the bottom one have expected locals. |
62 var locals = {}; | 69 var locals = {}; |
63 for (var j = 0; j < frame.localCount(); j++) { | 70 for (var j = 0; j < frame.localCount(); j++) { |
64 locals[frame.localName(j)] = frame.localValue(j).value(); | 71 locals[frame.localName(j)] = frame.localValue(j).value(); |
65 } | 72 } |
66 assertPropertiesEqual(expected_locals, locals); | 73 assertPropertiesEqual(expected_locals, locals); |
67 | 74 |
68 // All frames except the bottom one have expected arguments. | 75 // All frames except the bottom one have expected arguments. |
69 for (var j = 0; j < expected_args.names.length; j++) { | 76 for (var j = 0; j < expected_args.names.length; j++) { |
70 assertEquals(expected_args.names[j], frame.argumentName(j)); | 77 assertEquals(expected_args.names[j], frame.argumentName(j)); |
71 assertEquals(expected_args.values[j], frame.argumentValue(j).value()
); | 78 assertEquals(expected_args.values[j], |
| 79 frame.argumentValue(j).value()); |
72 } | 80 } |
73 | 81 |
74 // All frames except the bottom one have two scopes. | 82 // All frames except the bottom one have two scopes. |
75 assertEquals(2, frame.scopeCount()); | 83 assertEquals(2, frame.scopeCount()); |
76 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); | 84 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); |
77 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); | 85 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); |
78 | 86 |
79 Object.keys(expected_locals).forEach(function (name) { | 87 Object.keys(expected_locals).forEach(function (name) { |
80 assertEquals(expected_locals[name], frame.scope(0).scopeObject().val
ue()[name]); | 88 assertEquals(expected_locals[name], |
| 89 frame.scope(0).scopeObject().value()[name]); |
81 }); | 90 }); |
82 | 91 |
83 for (var j = 0; j < expected_args.names.length; j++) { | 92 for (var j = 0; j < expected_args.names.length; j++) { |
84 var arg_name = expected_args.names[j]; | 93 var arg_name = expected_args.names[j]; |
85 var arg_value = expected_args.values[j]; | 94 var arg_value = expected_args.values[j]; |
86 assertEquals(arg_value, frame.scope(0).scopeObject().value()[arg_nam
e]); | 95 assertEquals(arg_value, |
| 96 frame.scope(0).scopeObject().value()[arg_name]); |
87 } | 97 } |
88 | 98 |
89 // Evaluate in the inlined frame. | 99 // Evaluate in the inlined frame. |
90 Object.keys(expected_locals).forEach(function (name) { | 100 Object.keys(expected_locals).forEach(function (name) { |
91 assertEquals(expected_locals[name], frame.evaluate(name).value()); | 101 assertEquals(expected_locals[name], frame.evaluate(name).value()); |
92 }); | 102 }); |
93 | 103 |
94 for (var j = 0; j < expected_args.names.length; j++) { | 104 for (var j = 0; j < expected_args.names.length; j++) { |
95 var arg_name = expected_args.names[j]; | 105 var arg_name = expected_args.names[j]; |
96 var arg_value = expected_args.values[j]; | 106 var arg_value = expected_args.values[j]; |
97 assertEquals(arg_value, frame.evaluate(arg_name).value()); | 107 assertEquals(arg_value, frame.evaluate(arg_name).value()); |
98 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); | 108 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); |
99 } | 109 } |
100 | 110 |
101 var expected_args_sum = arraySum(expected_args.values); | 111 var expected_args_sum = arraySum(expected_args.values); |
102 var expected_locals_sum = | 112 var expected_locals_sum = |
103 arraySum(Object.keys(expected_locals). | 113 arraySum(Object.keys(expected_locals). |
104 map(function (k) { return expected_locals[k]; })); | 114 map(function (k) { return expected_locals[k]; })); |
105 | 115 |
106 assertEquals(expected_locals_sum + expected_args_sum, | 116 assertEquals(expected_locals_sum + expected_args_sum, |
107 frame.evaluate(Object.keys(expected_locals).join('+') + '
+ ' + | 117 frame.evaluate(Object.keys(expected_locals).join('+') + |
| 118 ' + ' + |
108 expected_args.names.join('+')).value()); | 119 expected_args.names.join('+')).value()); |
109 | 120 |
110 var arguments_sum = expected_args.names.map(function(_, idx) { | 121 var arguments_sum = expected_args.names.map(function(_, idx) { |
111 return "arguments[" + idx + "]"; | 122 return "arguments[" + idx + "]"; |
112 }).join('+'); | 123 }).join('+'); |
113 assertEquals(expected_args_sum, | 124 assertEquals(expected_args_sum, |
114 frame.evaluate(arguments_sum).value()); | 125 frame.evaluate(arguments_sum).value()); |
115 } else { | 126 } else { |
116 // The bottom frame only have the global scope. | 127 // The bottom frame only have the global scope. |
117 assertEquals(1, frame.scopeCount()); | 128 assertEquals(1, frame.scopeCount()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 new f(expected.length - 1, 11, 12, 0); | 208 new f(expected.length - 1, 11, 12, 0); |
198 | 209 |
199 // Make sure that the debug event listener was invoked. | 210 // Make sure that the debug event listener was invoked. |
200 assertFalse(exception, "exception in listener " + exception) | 211 assertFalse(exception, "exception in listener " + exception) |
201 assertTrue(listenerComplete); | 212 assertTrue(listenerComplete); |
202 | 213 |
203 // Throw away type information for next run. | 214 // Throw away type information for next run. |
204 gc(); | 215 gc(); |
205 | 216 |
206 Debug.setListener(null); | 217 Debug.setListener(null); |
OLD | NEW |