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 input = [ | 39 var input = [ |
38 {a: 1, b: 2}, | 40 {a: 1, b: 2}, |
39 {a: 3, b: 4}, | 41 {a: 3, b: 4}, |
40 {a: 5, b: 6}, | 42 {a: 5, b: 6}, |
41 {a: 7, b: 8}, | 43 {a: 7, b: 8}, |
42 {a: 9, b: 10} | 44 {a: 9, b: 10} |
43 ]; | 45 ]; |
44 | 46 |
45 var expected = [ | 47 var expected = [ |
46 { locals: {a0: 1.01, b0: 2.02}, args: { names: ["i", "x0", "y0"], values: [0,
3.03, 4.04] } }, | 48 { locals: {a0: 1.01, b0: 2.02}, |
47 { locals: {a1: 3.03, b1: 4.04}, args: { names: ["i", "x1", "y1"], values: [1,
5.05, 6.06] } }, | 49 args: { names: ["i", "x0", "y0"], values: [0, 3.03, 4.04] } }, |
48 { locals: {a2: 5.05, b2: 6.06}, args: { names: ["i"], values: [2] } }, | 50 { locals: {a1: 3.03, b1: 4.04}, |
49 { locals: {a3: 7.07, b3: 8.08}, args: { names: ["i", "x3", "y3", "z3"], | 51 args: { names: ["i", "x1", "y1"], values: [1, 5.05, 6.06] } }, |
50 values: [3, 9.09, 10.10, undefined] } | 52 { locals: {a2: 5.05, b2: 6.06}, |
51 }, | 53 args: { names: ["i"], values: [2] } }, |
52 { locals: {a4: 9.09, b4: 10.10}, args: { names: ["i", "x4", "y4"], values: [4,
11.11, 12.12] } } | 54 { locals: {a3: 7.07, b3: 8.08}, |
| 55 args: { names: ["i", "x3", "y3", "z3"], |
| 56 values: [3, 9.09, 10.10, undefined] } }, |
| 57 { locals: {a4: 9.09, b4: 10.10}, |
| 58 args: { names: ["i", "x4", "y4"], values: [4, 11.11, 12.12] } } |
53 ]; | 59 ]; |
54 | 60 |
55 function arraySum(arr) { | 61 function arraySum(arr) { |
56 return arr.reduce(function (a, b) { return a + b; }, 0); | 62 return arr.reduce(function (a, b) { return a + b; }, 0); |
57 } | 63 } |
58 | 64 |
59 function listener(event, exec_state, event_data, data) { | 65 function listener(event, exec_state, event_data, data) { |
60 try { | 66 try { |
61 if (event == Debug.DebugEvent.Break) | 67 if (event == Debug.DebugEvent.Break) |
62 { | 68 { |
63 assertEquals(6, exec_state.frameCount()); | 69 assertEquals(6, exec_state.frameCount()); |
64 | 70 |
65 for (var i = 0; i < exec_state.frameCount(); i++) { | 71 for (var i = 0; i < exec_state.frameCount(); i++) { |
66 var frame = exec_state.frame(i); | 72 var frame = exec_state.frame(i); |
67 if (i < exec_state.frameCount() - 1) { | 73 if (i < exec_state.frameCount() - 1) { |
68 var expected_args = expected[i].args; | 74 var expected_args = expected[i].args; |
69 var expected_locals = expected[i].locals; | 75 var expected_locals = expected[i].locals; |
70 | 76 |
71 // All frames except the bottom one have expected locals. | 77 // All frames except the bottom one have expected locals. |
72 var locals = {}; | 78 var locals = {}; |
73 for (var j = 0; j < frame.localCount(); j++) { | 79 for (var j = 0; j < frame.localCount(); j++) { |
74 locals[frame.localName(j)] = frame.localValue(j).value(); | 80 locals[frame.localName(j)] = frame.localValue(j).value(); |
75 } | 81 } |
76 assertPropertiesEqual(expected_locals, locals); | 82 assertPropertiesEqual(expected_locals, locals); |
77 | 83 |
78 // All frames except the bottom one have expected arguments. | 84 // All frames except the bottom one have expected arguments. |
79 for (var j = 0; j < expected_args.names.length; j++) { | 85 for (var j = 0; j < expected_args.names.length; j++) { |
80 assertEquals(expected_args.names[j], frame.argumentName(j)); | 86 assertEquals(expected_args.names[j], frame.argumentName(j)); |
81 assertEquals(expected_args.values[j], frame.argumentValue(j).value()
); | 87 assertEquals(expected_args.values[j], |
| 88 frame.argumentValue(j).value()); |
82 } | 89 } |
83 | 90 |
84 // All frames except the bottom one have two scopes. | 91 // All frames except the bottom one have two scopes. |
85 assertEquals(2, frame.scopeCount()); | 92 assertEquals(2, frame.scopeCount()); |
86 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); | 93 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); |
87 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); | 94 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); |
88 | 95 |
89 Object.keys(expected_locals).forEach(function (name) { | 96 Object.keys(expected_locals).forEach(function (name) { |
90 assertEquals(expected_locals[name], frame.scope(0).scopeObject().val
ue()[name]); | 97 assertEquals(expected_locals[name], |
| 98 frame.scope(0).scopeObject().value()[name]); |
91 }); | 99 }); |
92 | 100 |
93 for (var j = 0; j < expected_args.names.length; j++) { | 101 for (var j = 0; j < expected_args.names.length; j++) { |
94 var arg_name = expected_args.names[j]; | 102 var arg_name = expected_args.names[j]; |
95 var arg_value = expected_args.values[j]; | 103 var arg_value = expected_args.values[j]; |
96 assertEquals(arg_value, frame.scope(0).scopeObject().value()[arg_nam
e]); | 104 assertEquals(arg_value, |
| 105 frame.scope(0).scopeObject().value()[arg_name]); |
97 } | 106 } |
98 | 107 |
99 // Evaluate in the inlined frame. | 108 // Evaluate in the inlined frame. |
100 Object.keys(expected_locals).forEach(function (name) { | 109 Object.keys(expected_locals).forEach(function (name) { |
101 assertEquals(expected_locals[name], frame.evaluate(name).value()); | 110 assertEquals(expected_locals[name], frame.evaluate(name).value()); |
102 }); | 111 }); |
103 | 112 |
104 for (var j = 0; j < expected_args.names.length; j++) { | 113 for (var j = 0; j < expected_args.names.length; j++) { |
105 var arg_name = expected_args.names[j]; | 114 var arg_name = expected_args.names[j]; |
106 var arg_value = expected_args.values[j]; | 115 var arg_value = expected_args.values[j]; |
107 assertEquals(arg_value, frame.evaluate(arg_name).value()); | 116 assertEquals(arg_value, frame.evaluate(arg_name).value()); |
108 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); | 117 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); |
109 } | 118 } |
110 | 119 |
111 var expected_args_sum = arraySum(expected_args.values); | 120 var expected_args_sum = arraySum(expected_args.values); |
112 var expected_locals_sum = | 121 var expected_locals_sum = |
113 arraySum(Object.keys(expected_locals). | 122 arraySum(Object.keys(expected_locals). |
114 map(function (k) { return expected_locals[k]; })); | 123 map(function (k) { return expected_locals[k]; })); |
115 | 124 |
116 assertEquals(expected_locals_sum + expected_args_sum, | 125 assertEquals(expected_locals_sum + expected_args_sum, |
117 frame.evaluate(Object.keys(expected_locals).join('+') + '
+ ' + | 126 frame.evaluate(Object.keys(expected_locals).join('+') + |
| 127 ' + ' + |
118 expected_args.names.join('+')).value()); | 128 expected_args.names.join('+')).value()); |
119 | 129 |
120 var arguments_sum = expected_args.names.map(function(_, idx) { | 130 var arguments_sum = expected_args.names.map(function(_, idx) { |
121 return "arguments[" + idx + "]"; | 131 return "arguments[" + idx + "]"; |
122 }).join('+'); | 132 }).join('+'); |
123 assertEquals(expected_args_sum, | 133 assertEquals(expected_args_sum, |
124 frame.evaluate(arguments_sum).value()); | 134 frame.evaluate(arguments_sum).value()); |
125 } else { | 135 } else { |
126 // The bottom frame only have the global scope. | 136 // The bottom frame only have the global scope. |
127 assertEquals(1, frame.scopeCount()); | 137 assertEquals(1, frame.scopeCount()); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 new f(input.length - 1, 11.11, 12.12, ""); | 228 new f(input.length - 1, 11.11, 12.12, ""); |
219 | 229 |
220 // Make sure that the debug event listener was invoked. | 230 // Make sure that the debug event listener was invoked. |
221 assertFalse(exception, "exception in listener " + exception) | 231 assertFalse(exception, "exception in listener " + exception) |
222 assertTrue(listenerComplete); | 232 assertTrue(listenerComplete); |
223 | 233 |
224 //Throw away type information for next run. | 234 //Throw away type information for next run. |
225 gc(); | 235 gc(); |
226 | 236 |
227 Debug.setListener(null); | 237 Debug.setListener(null); |
OLD | NEW |