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.
34 function TestCase(test_scenario, expected_output) {
35 // Global variable, accessed from eval'd script.
38 var script_text_generator = (function() {
39 var variables = { a: 1, b: 1, c: 1, d: 1, e: 1, f: 1 };
43 return "(function() {\n " +
44 " function A() {\n " +
45 " test_output += 'a' + " + variables.a + ";\n " +
46 " test_output += '=';\n " +
48 " return 'Capybara';\n " +
50 " function B(p1, p2) {\n " +
51 " test_output += 'b' + " + variables.b + ";\n " +
54 " function C() {\n " +
55 " test_output += 'c' + " + variables.c + ";\n " +
56 " // Function call with argument adaptor is intentional.\n " +
59 " function D() {\n " +
60 " test_output += 'd' + " + variables.d + ";\n " +
61 " // Function call with argument adaptor is intentional.\n " +
62 " return C(1, 2);\n " +
64 " function E() {\n " +
65 " test_output += 'e' + " + variables.e + ";\n " +
68 " function F() {\n " +
69 " test_output += 'f' + " + variables.f + ";\n " +
75 change: function(var_name) {
76 variables[var_name]++;
81 var test_fun = eval(script_text_generator.get());
83 var script = Debug.findScript(test_fun);
87 function DebuggerStatementHandler() {
89 assertTrue(scenario_pos < test_scenario.length);
90 var change_var = test_scenario[scenario_pos++];
91 if (change_var == '=') {
95 script_text_generator.change(change_var);
97 Debug.LiveEdit.SetScriptSource(script, script_text_generator.get(),
100 print("LiveEdit exception: " + e);
106 var saved_exception = null;
108 function listener(event, exec_state, event_data, data) {
109 if (event == Debug.DebugEvent.Break) {
111 DebuggerStatementHandler();
116 print("Other: " + event);
120 Debug.setListener(listener);
121 assertEquals("Capybara", test_fun());
122 Debug.setListener(null);
124 if (saved_exception) {
125 print("Exception: " + saved_exception);
131 assertEquals(expected_output, test_output);
134 TestCase(['='], "f1e1d1c1b1a1=");
136 TestCase(['c', '=', '='], "f1e1d1c1b1a1=c2b1a1=");
138 TestCase(['b', 'c', 'd', 'e', '=', '='], "f1e1d1c1b1a1=e2d2c2b2a1=");
140 TestCase(['b', 'c', '=', 'b', 'c', 'd', 'e', '=', '='], "f1e1d1c1b1a1=c2b2a1=e2d2c3b3a1=");
142 TestCase(['e', 'f', '=', '='], "f1e1d1c1b1a1=f2e2d1c1b1a1=");