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
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.
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.
28 // Flags: --expose-debug-as debug
29 // Get the Debug object exposed from the debug context global object.
33 function FindCallFrame(exec_state, frame_code) {
34 var number = Number(frame_code);
36 return exec_state.frame(number);
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()) {
46 throw new Error("Failed to find function name " + function_name);
49 function TestCase(test_scenario, expected_output) {
50 // Global variable, accessed from eval'd script.
55 // Extra stack variable. To make function not slim.
56 // Restarter doesn't work on slim function when stopped on 'debugger'
57 // statement. (There is no padding for 'debugger' statement).
70 // Function call with argument adaptor is intentional.
75 // Function call with argument adaptor is intentional.
91 function DebuggerStatementHandler(exec_state) {
93 assertTrue(scenario_pos < test_scenario.length);
94 var change_code = test_scenario[scenario_pos++];
95 if (change_code == '=') {
99 var frame = FindCallFrame(exec_state, change_code);
101 Debug.LiveEdit.RestartFrame(frame);
105 var saved_exception = null;
107 function listener(event, exec_state, event_data, data) {
108 if (saved_exception != null) {
111 if (event == Debug.DebugEvent.Break) {
113 DebuggerStatementHandler(exec_state);
118 print("Other: " + event);
122 Debug.setListener(listener);
123 assertEquals("Capybara", TestCode());
124 Debug.setListener(null);
126 if (saved_exception) {
127 print("Exception: " + saved_exception);
128 print("Stack: " + saved_exception.stack);
134 assertEquals(expected_output, test_output);
137 TestCase('0==', "FEDCBA=A=");
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=");
144 TestCase('=', "FEDCBA=");
146 TestCase('C==', "FEDCBA=CBA=");
148 TestCase('B=C=A=D==', "FEDCBA=BA=CBA=A=DCBA=");
150 // Successive restarts don't work now and require additional fix.
151 //TestCase('BCDE==', "FEDCBA=EDCBA=");
152 //TestCase('BC=BCDE==', "FEDCBA=CBA=EDCBA=");
153 //TestCase('EF==', "FEDCBA=FEDCBA=");