| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | |
| 2 // Redistribution and use in source and binary forms, with or without | |
| 3 // modification, are permitted provided that the following conditions are | |
| 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 | |
| 28 // Flags: --expose-debug-as debug --expose-gc --allow-natives-syntax | |
| 29 // Flags: --inline-construct | |
| 30 | |
| 31 // Get the Debug object exposed from the debug context global object. | |
| 32 Debug = debug.Debug | |
| 33 | |
| 34 var listenerComplete = false; | |
| 35 var exception = false; | |
| 36 | |
| 37 var testingConstructCall = false; | |
| 38 | |
| 39 var input = [ | |
| 40 {a: 1, b: 2}, | |
| 41 {a: 3, b: 4}, | |
| 42 {a: 5, b: 6}, | |
| 43 {a: 7, b: 8}, | |
| 44 {a: 9, b: 10} | |
| 45 ]; | |
| 46 | |
| 47 var expected = [ | |
| 48 { locals: {i: 0, x0: 3.03, y0: 4.04, a0: 1.01, b0: 2.02}, | |
| 49 args: { names: ["i", "x0", "y0"], values: [0, 3.03, 4.04] } }, | |
| 50 { locals: {i: 1, x1: 5.05, y1: 6.06, a1: 3.03, b1: 4.04}, | |
| 51 args: { names: ["i", "x1", "y1"], values: [1, 5.05, 6.06] } }, | |
| 52 { locals: {i: 2, a2: 5.05, b2: 6.06}, | |
| 53 args: { names: ["i"], values: [2] } }, | |
| 54 { locals: {i: 3, x3: 9.09, y3: 10.10, z3: undefined, a3: 7.07, b3: 8.08}, | |
| 55 args: { names: ["i", "x3", "y3", "z3"], | |
| 56 values: [3, 9.09, 10.10, undefined] } }, | |
| 57 { locals: {i: 4, x4: 11.11, y4: 12.12, a4: 9.09, b4: 10.10}, | |
| 58 args: { names: ["i", "x4", "y4"], values: [4, 11.11, 12.12] } } | |
| 59 ]; | |
| 60 | |
| 61 function listener(event, exec_state, event_data, data) { | |
| 62 try { | |
| 63 if (event == Debug.DebugEvent.Break) | |
| 64 { | |
| 65 assertEquals(6, exec_state.frameCount()); | |
| 66 | |
| 67 for (var i = 0; i < exec_state.frameCount(); i++) { | |
| 68 var frame = exec_state.frame(i); | |
| 69 if (i < exec_state.frameCount() - 1) { | |
| 70 var expected_args = expected[i].args; | |
| 71 var expected_locals = expected[i].locals; | |
| 72 | |
| 73 // All frames except the bottom one have expected locals. | |
| 74 var locals = {}; | |
| 75 for (var j = 0; j < frame.localCount(); j++) { | |
| 76 locals[frame.localName(j)] = frame.localValue(j).value(); | |
| 77 } | |
| 78 assertPropertiesEqual(expected_locals, locals); | |
| 79 | |
| 80 // All frames except the bottom one have two scopes. | |
| 81 assertEquals(3, frame.scopeCount()); | |
| 82 assertEquals(debug.ScopeType.Local, frame.scope(0).scopeType()); | |
| 83 assertEquals(debug.ScopeType.Script, frame.scope(1).scopeType()); | |
| 84 assertEquals(debug.ScopeType.Global, frame.scope(2).scopeType()); | |
| 85 | |
| 86 Object.keys(expected_locals).forEach(function (name) { | |
| 87 assertEquals(expected_locals[name], | |
| 88 frame.scope(0).scopeObject().value()[name]); | |
| 89 }); | |
| 90 | |
| 91 for (var j = 0; j < expected_args.names.length; j++) { | |
| 92 var arg_name = expected_args.names[j]; | |
| 93 var arg_value = expected_args.values[j]; | |
| 94 assertEquals(arg_value, | |
| 95 frame.scope(0).scopeObject().value()[arg_name]); | |
| 96 } | |
| 97 | |
| 98 // Evaluate in the inlined frame. | |
| 99 Object.keys(expected_locals).forEach(function (name) { | |
| 100 assertEquals(expected_locals[name], frame.evaluate(name).value()); | |
| 101 }); | |
| 102 | |
| 103 for (var j = 0; j < expected_args.names.length; j++) { | |
| 104 var arg_name = expected_args.names[j]; | |
| 105 var arg_value = expected_args.values[j]; | |
| 106 assertEquals(arg_value, frame.evaluate(arg_name).value()); | |
| 107 assertEquals(arg_value, frame.evaluate('arguments['+j+']').value()); | |
| 108 } | |
| 109 } else { | |
| 110 // The bottom frame only have the global scope. | |
| 111 assertEquals(2, frame.scopeCount()); | |
| 112 assertEquals(debug.ScopeType.Script, frame.scope(0).scopeType()); | |
| 113 assertEquals(debug.ScopeType.Global, frame.scope(1).scopeType()); | |
| 114 } | |
| 115 | |
| 116 // Check the frame function. | |
| 117 switch (i) { | |
| 118 case 0: assertEquals("h", frame.func().name()); break; | |
| 119 case 1: assertEquals("g3", frame.func().name()); break; | |
| 120 case 2: assertEquals("g2", frame.func().name()); break; | |
| 121 case 3: assertEquals("g1", frame.func().name()); break; | |
| 122 case 4: assertEquals("f", frame.func().name()); break; | |
| 123 case 5: break; | |
| 124 default: assertUnreachable(); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 // Indicate that all was processed. | |
| 129 listenerComplete = true; | |
| 130 } | |
| 131 } catch (e) { | |
| 132 exception = e.toString() + e.stack; | |
| 133 }; | |
| 134 }; | |
| 135 | |
| 136 for (var i = 0; i < 4; i++) f(input.length - 1, 11.11, 12.12); | |
| 137 %OptimizeFunctionOnNextCall(f); | |
| 138 f(input.length - 1, 11.11, 12.12); | |
| 139 | |
| 140 // Add the debug event listener. | |
| 141 Debug.setListener(listener); | |
| 142 | |
| 143 function h(i, x0, y0) { | |
| 144 var a0 = input[i].a; | |
| 145 var b0 = input[i].b; | |
| 146 a0 = a0 + a0 / 100; | |
| 147 b0 = b0 + b0 / 100; | |
| 148 debugger; // Breakpoint. | |
| 149 return a0 + b0; | |
| 150 }; | |
| 151 | |
| 152 function g3(i, x1, y1) { | |
| 153 var a1 = input[i].a; | |
| 154 var b1 = input[i].b; | |
| 155 a1 = a1 + a1 / 100; | |
| 156 b1 = b1 + b1 / 100; | |
| 157 h(i - 1, a1, b1); | |
| 158 return a1 + b1; | |
| 159 }; | |
| 160 | |
| 161 function g2(i) { | |
| 162 var a2 = input[i].a; | |
| 163 var b2 = input[i].b; | |
| 164 a2 = a2 + a2 / 100; | |
| 165 b2 = b2 + b2 / 100; | |
| 166 g3(i - 1, a2, b2); | |
| 167 return a2 + b2; | |
| 168 }; | |
| 169 | |
| 170 function g1(i, x3, y3, z3) { | |
| 171 var a3 = input[i].a; | |
| 172 var b3 = input[i].b; | |
| 173 a3 = a3 + a3 / 100; | |
| 174 b3 = b3 + b3 / 100; | |
| 175 new g2(i - 1, a3, b3); | |
| 176 return a3 + b3; | |
| 177 }; | |
| 178 | |
| 179 function f(i, x4, y4) { | |
| 180 var a4 = input[i].a; | |
| 181 var b4 = input[i].b; | |
| 182 a4 = a4 + a4 / 100; | |
| 183 b4 = b4 + b4 / 100; | |
| 184 g1(i - 1, a4, b4); | |
| 185 return a4 + b4; | |
| 186 }; | |
| 187 | |
| 188 // Test calling f normally and as a constructor. | |
| 189 f(input.length - 1, 11.11, 12.12); | |
| 190 f(input.length - 1, 11.11, 12.12, ""); | |
| 191 testingConstructCall = true; | |
| 192 new f(input.length - 1, 11.11, 12.12); | |
| 193 new f(input.length - 1, 11.11, 12.12, ""); | |
| 194 | |
| 195 // Make sure that the debug event listener was invoked. | |
| 196 assertFalse(exception, "exception in listener " + exception) | |
| 197 assertTrue(listenerComplete); | |
| 198 | |
| 199 //Throw away type information for next run. | |
| 200 gc(); | |
| 201 | |
| 202 Debug.setListener(null); | |
| OLD | NEW |