1// Copyright 2008 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 29// Get the Debug object exposed from the debug context global object. 30Debug = debug.Debug 31 32listenerComplete = false; 33exception = false; 34 35 36function h() { 37 var a = 1; 38 var b = 2; 39 debugger; // Breakpoint. 40} 41 42function checkFrame0(frame) { 43 // Frame 0 (h) has normal variables a and b. 44 var count = frame.localCount(); 45 assertEquals(2, count); 46 for (var i = 0; i < count; ++i) { 47 var name = frame.localName(i); 48 var value = frame.localValue(i).value(); 49 if (name == 'a') { 50 assertEquals(1, value); 51 } else { 52 assertEquals('b', name); 53 assertEquals(2, value); 54 } 55 } 56} 57 58 59function g() { 60 var a = 3; 61 eval("var b = 4;"); 62 h(); 63} 64 65function checkFrame1(frame) { 66 // Frame 1 (g) has normal variable a (and arguments). 67 var count = frame.localCount(); 68 assertEquals(2, count); 69 for (var i = 0; i < count; ++i) { 70 var name = frame.localName(i); 71 var value = frame.localValue(i).value(); 72 if (name == 'a') { 73 assertEquals(3, value); 74 } else { 75 assertEquals('arguments', name); 76 } 77 } 78} 79 80 81function f() { 82 var a = 5; 83 var b = 0; 84 with ({b:6}) { 85 g(); 86 } 87} 88 89function checkFrame2(frame) { 90 // Frame 2 (f) has normal variables a and b (and arguments). 91 var count = frame.localCount(); 92 assertEquals(3, count); 93 for (var i = 0; i < count; ++i) { 94 var name = frame.localName(i); 95 var value = frame.localValue(i).value(); 96 if (name == 'a') { 97 assertEquals(5, value); 98 } else if (name == 'b') { 99 assertEquals(0, value); 100 } else { 101 assertEquals('arguments', name); 102 } 103 } 104} 105 106 107function listener(event, exec_state, event_data, data) { 108 try { 109 if (event == Debug.DebugEvent.Break) 110 { 111 checkFrame0(exec_state.frame(0)); 112 checkFrame1(exec_state.frame(1)); 113 checkFrame2(exec_state.frame(2)); 114 115 // Evaluating a and b on frames 0, 1 and 2 produces 1, 2, 3, 4, 5 and 6. 116 assertEquals(1, exec_state.frame(0).evaluate('a').value()); 117 assertEquals(2, exec_state.frame(0).evaluate('b').value()); 118 assertEquals(3, exec_state.frame(1).evaluate('a').value()); 119 assertEquals(4, exec_state.frame(1).evaluate('b').value()); 120 assertEquals(5, exec_state.frame(2).evaluate('a').value()); 121 assertEquals(6, exec_state.frame(2).evaluate('b').value()); 122 123 // Indicate that all was processed. 124 listenerComplete = true; 125 } 126 } catch (e) { 127 exception = e 128 }; 129}; 130 131// Add the debug event listener. 132Debug.setListener(listener); 133 134f(); 135 136// Make sure that the debug event listener vas invoked. 137assertTrue(listenerComplete); 138assertFalse(exception, "exception in listener") 139