Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
|
Yang
2012/06/22 08:13:23
Update to 2012.
| |
| 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. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 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 | 28 // Flags: --expose-debug-as debug |
| 29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
| 30 | 30 |
| 31 Debug = debug.Debug | 31 Debug = debug.Debug |
| 32 | 32 |
| 33 function FindCallFrame(exec_state, frame_code) { | |
| 34 var number = Number(frame_code); | |
| 35 if (number >= 0) { | |
| 36 return exec_state.frame(number); | |
| 37 } else { | |
| 38 for (var i = 0; i < exec_state.frameCount(); i++) { | |
| 39 var frame = exec_state.frame(i); | |
| 40 var func_mirror = frame.func(); | |
| 41 if (frame_code == func_mirror.name()) { | |
| 42 return frame; | |
| 43 } | |
| 44 } | |
| 45 } | |
| 46 throw new Error("Failed to find function name " + function_name); | |
| 47 } | |
| 48 | 33 |
| 49 function TestCase(test_scenario, expected_output) { | 34 function TestCase(test_scenario, expected_output) { |
| 50 // Global variable, accessed from eval'd script. | 35 // Global variable, accessed from eval'd script. |
| 51 test_output = ""; | 36 test_output = ""; |
| 52 | 37 |
| 53 function TestCode() { | 38 var script_text_generator = (function() { |
| 54 function A() { | 39 var variables = { a: 1, b: 1, c: 1, d: 1, e: 1, f: 1 }; |
| 55 // Extra stack variable. To make function not slim. | 40 |
| 56 // Restarter doesn't work on slim function when stopped on 'debugger' | 41 return { |
| 57 // statement. (There is no padding for 'debugger' statement). | 42 get: function() { |
| 58 var o = {}; | 43 return "(function() {\n " + |
| 59 test_output += 'A'; | 44 " function A() {\n " + |
| 60 test_output += '='; | 45 " test_output += 'a' + " + variables.a + ";\n " + |
| 61 debugger; | 46 " test_output += '=';\n " + |
| 62 return 'Capybara'; | 47 " debugger;\n " + |
| 63 } | 48 " return 'Capybara';\n " + |
| 64 function B(p1, p2) { | 49 " }\n " + |
| 65 test_output += 'B'; | 50 " function B(p1, p2) {\n " + |
| 66 return A(); | 51 " test_output += 'b' + " + variables.b + ";\n " + |
| 67 } | 52 " return A();\n " + |
| 68 function C() { | 53 " }\n " + |
| 69 test_output += 'C'; | 54 " function C() {\n " + |
| 70 // Function call with argument adaptor is intentional. | 55 " test_output += 'c' + " + variables.c + ";\n " + |
| 71 return B(); | 56 " // Function call with argument adaptor is intentional.\n " + |
| 72 } | 57 " return B();\n " + |
| 73 function D() { | 58 " }\n " + |
| 74 test_output += 'D'; | 59 " function D() {\n " + |
| 75 // Function call with argument adaptor is intentional. | 60 " test_output += 'd' + " + variables.d + ";\n " + |
| 76 return C(1, 2); | 61 " // Function call with argument adaptor is intentional.\n " + |
| 77 } | 62 " return C(1, 2);\n " + |
| 78 function E() { | 63 " }\n " + |
| 79 test_output += 'E'; | 64 " function E() {\n " + |
| 80 return D(); | 65 " test_output += 'e' + " + variables.e + ";\n " + |
| 81 } | 66 " return D();\n " + |
| 82 function F() { | 67 " }\n " + |
| 83 test_output += 'F'; | 68 " function F() {\n " + |
| 84 return E(); | 69 " test_output += 'f' + " + variables.f + ";\n " + |
| 85 } | 70 " return E();\n " + |
| 86 return F(); | 71 " }\n " + |
| 87 } | 72 " return F();\n " + |
| 73 "})\n"; | |
| 74 }, | |
| 75 change: function(var_name) { | |
| 76 variables[var_name]++; | |
| 77 } | |
| 78 }; | |
| 79 })(); | |
| 80 | |
| 81 var test_fun = eval(script_text_generator.get()); | |
| 82 | |
| 83 var script = Debug.findScript(test_fun); | |
| 88 | 84 |
| 89 var scenario_pos = 0; | 85 var scenario_pos = 0; |
| 90 | 86 |
| 91 function DebuggerStatementHandler(exec_state) { | 87 function DebuggerStatementHandler() { |
| 92 while (true) { | 88 while (true) { |
| 93 assertTrue(scenario_pos < test_scenario.length); | 89 assertTrue(scenario_pos < test_scenario.length); |
| 94 var change_code = test_scenario[scenario_pos++]; | 90 var change_var = test_scenario[scenario_pos++]; |
| 95 if (change_code == '=') { | 91 if (change_var == '=') { |
| 96 // Continue. | 92 // Continue. |
| 97 return; | 93 return; |
| 98 } | 94 } |
| 99 var frame = FindCallFrame(exec_state, change_code); | 95 script_text_generator.change(change_var); |
| 100 // Throws if fails. | 96 try { |
| 101 Debug.LiveEdit.RestartFrame(frame); | 97 Debug.LiveEdit.SetScriptSource(script, script_text_generator.get(), fals e, []); |
|
Yang
2012/06/22 08:13:23
80 char limit.
| |
| 98 } catch (e) { | |
| 99 print("LiveEdit exception: " + e); | |
| 100 throw e; | |
| 101 } | |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 var saved_exception = null; | 105 var saved_exception = null; |
| 106 | 106 |
| 107 function listener(event, exec_state, event_data, data) { | 107 function listener(event, exec_state, event_data, data) { |
| 108 if (saved_exception != null) { | |
| 109 return; | |
| 110 } | |
| 111 if (event == Debug.DebugEvent.Break) { | 108 if (event == Debug.DebugEvent.Break) { |
| 112 try { | 109 try { |
| 113 DebuggerStatementHandler(exec_state); | 110 DebuggerStatementHandler(); |
| 114 } catch (e) { | 111 } catch (e) { |
| 115 saved_exception = e; | 112 saved_exception = e; |
| 116 } | 113 } |
| 117 } else { | 114 } else { |
| 118 print("Other: " + event); | 115 print("Other: " + event); |
| 119 } | 116 } |
| 120 } | 117 } |
| 121 | 118 |
| 122 Debug.setListener(listener); | 119 Debug.setListener(listener); |
| 123 assertEquals("Capybara", TestCode()); | 120 assertEquals("Capybara", test_fun()); |
| 124 Debug.setListener(null); | 121 Debug.setListener(null); |
| 125 | 122 |
| 126 if (saved_exception) { | 123 if (saved_exception) { |
| 127 print("Exception: " + saved_exception); | 124 print("Exception: " + saved_exception); |
| 128 print("Stack: " + saved_exception.stack); | |
| 129 assertUnreachable(); | 125 assertUnreachable(); |
| 130 } | 126 } |
| 131 | 127 |
| 132 print(test_output); | 128 print(test_output); |
| 133 | 129 |
| 134 assertEquals(expected_output, test_output); | 130 assertEquals(expected_output, test_output); |
| 135 } | 131 } |
| 136 | 132 |
| 137 TestCase('0==', "FEDCBA=A="); | 133 TestCase(['='], "f1e1d1c1b1a1="); |
| 138 TestCase('1==', "FEDCBA=BA="); | |
| 139 TestCase('2==', "FEDCBA=CBA="); | |
| 140 TestCase('3==', "FEDCBA=DCBA="); | |
| 141 TestCase('4==', "FEDCBA=EDCBA="); | |
| 142 TestCase('5==', "FEDCBA=FEDCBA="); | |
| 143 | 134 |
| 144 TestCase('=', "FEDCBA="); | 135 TestCase(['c', '=', '='], "f1e1d1c1b1a1=c2b1a1="); |
| 145 | 136 |
| 146 TestCase('C==', "FEDCBA=CBA="); | 137 TestCase(['b', 'c', 'd', 'e', '=', '='], "f1e1d1c1b1a1=e2d2c2b2a1="); |
| 147 | 138 |
| 148 TestCase('B=C=A=D==', "FEDCBA=BA=CBA=A=DCBA="); | 139 TestCase(['b', 'c', '=', 'b', 'c', 'd', 'e', '=', '='], "f1e1d1c1b1a1=c2b2a1=e2d 2c3b3a1="); |
| 149 | 140 |
| 150 // Successive restarts don't work now and require additional fix. | 141 TestCase(['e', 'f', '=', '='], "f1e1d1c1b1a1=f2e2d1c1b1a1="); |
| 151 //TestCase('BCDE==', "FEDCBA=EDCBA="); | |
| 152 //TestCase('BC=BCDE==', "FEDCBA=CBA=EDCBA="); | |
| 153 //TestCase('EF==', "FEDCBA=FEDCBA="); | |
| OLD | NEW |