1 // Copyright 2013 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
32 listenerComplete = false;
35 // var0: init after break point, changed by debug eval.
36 // const0: init before break point, changed by debug eval.
37 // const1: init after break point, materialized but untouched by debug eval.
38 // const2: init after break point, materialized and changed by debug eval.
39 // const3: context allocated const, init before break point, changed by eval.
46 assertEquals(undefined, const1);
47 assertEquals(undefined, const2);
48 assertEquals(3, const3);
49 assertEquals(21, var1);
51 debugger; // Break point.
53 assertEquals(30, var0);
54 // TODO(yangguo): debug evaluate should not be able to alter
55 // stack-allocated const values
56 // assertEquals(0, const0);
57 assertEquals(undefined, const1);
58 assertEquals(undefined, const2);
62 assertEquals(20, var0);
63 assertEquals(1, const1);
64 assertEquals(2, const2);
69 assertEquals(31, var1);
70 assertEquals(3, const3);
74 function listener(event, exec_state, event_data, data) {
75 if (event != Debug.DebugEvent.Break) return;
77 var frame = exec_state.frame(0);
78 var evaluate = function(something) {
79 return frame.evaluate(something).value()
82 var count = frame.localCount();
83 assertEquals(4, count);
84 var expectation = { "const0" : 0,
90 for (var i = 0; i < frame.localCount(); ++i) {
91 var name = frame.localName(i);
92 var value = frame.localValue(i).value();
93 assertEquals(expectation[name], value);
96 evaluate('const0 = 10');
97 evaluate('const2 = 12');
98 evaluate('const3 = 13');
99 evaluate('var0 = 30');
100 evaluate('var1 = 31');
102 // Indicate that all was processed.
103 listenerComplete = true;
106 print("Caught something. " + e + " " + e.stack);
110 // Run and compile before debugger is active.
111 try { f(); } catch (e) { }
113 Debug.setListener(listener);
117 Debug.setListener(null);
119 assertFalse(exception, "exception in listener")
120 assertTrue(listenerComplete);