ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2008 the V8 project authors. All rights reserved. |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 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. |
| 30 | Debug = debug.Debug |
| 31 | |
| 32 | listenerComplete = false; |
| 33 | exception = false; |
| 34 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 35 | |
| 36 | function checkFrame0(name, value) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 37 | assertTrue(name == 'a' || name == 'b'); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 38 | if (name == 'a') { |
| 39 | assertEquals(1, value); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 40 | } |
| 41 | if (name == 'b') { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 42 | assertEquals(2, value); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | |
| 47 | function checkFrame1(name, value) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 48 | assertTrue(name == '.arguments' || name == 'a'); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 49 | if (name == 'a') { |
| 50 | assertEquals(3, value); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | |
| 55 | function checkFrame2(name, value) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 56 | assertTrue(name == '.arguments' || name == 'a' || |
| 57 | name == 'arguments' || name == 'b'); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 58 | if (name == 'a') { |
| 59 | assertEquals(5, value); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 60 | } |
| 61 | if (name == 'b') { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 62 | assertEquals(0, value); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 67 | function listener(event, exec_state, event_data, data) { |
| 68 | try { |
| 69 | if (event == Debug.DebugEvent.Break) |
| 70 | { |
| 71 | // Frame 0 has normal variables a and b. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 72 | var frame0 = exec_state.frame(0); |
| 73 | checkFrame0(frame0.localName(0), frame0.localValue(0).value()); |
| 74 | checkFrame0(frame0.localName(1), frame0.localValue(1).value()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 75 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 76 | // Frame 1 has normal variable a (and the .arguments variable). |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 77 | var frame1 = exec_state.frame(1); |
| 78 | checkFrame1(frame1.localName(0), frame1.localValue(0).value()); |
| 79 | checkFrame1(frame1.localName(1), frame1.localValue(1).value()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 80 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 81 | // Frame 2 has normal variables a and b (and both the .arguments and |
| 82 | // arguments variable). |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 83 | var frame2 = exec_state.frame(2); |
| 84 | checkFrame2(frame2.localName(0), frame2.localValue(0).value()); |
| 85 | checkFrame2(frame2.localName(1), frame2.localValue(1).value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 86 | checkFrame2(frame2.localName(2), frame2.localValue(2).value()); |
| 87 | checkFrame2(frame2.localName(3), frame2.localValue(3).value()); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 88 | |
| 89 | // Evaluating a and b on frames 0, 1 and 2 produces 1, 2, 3, 4, 5 and 6. |
| 90 | assertEquals(1, exec_state.frame(0).evaluate('a').value()); |
| 91 | assertEquals(2, exec_state.frame(0).evaluate('b').value()); |
| 92 | assertEquals(3, exec_state.frame(1).evaluate('a').value()); |
| 93 | assertEquals(4, exec_state.frame(1).evaluate('b').value()); |
| 94 | assertEquals(5, exec_state.frame(2).evaluate('a').value()); |
| 95 | assertEquals(6, exec_state.frame(2).evaluate('b').value()); |
| 96 | |
| 97 | // Indicate that all was processed. |
| 98 | listenerComplete = true; |
| 99 | } |
| 100 | } catch (e) { |
| 101 | exception = e |
| 102 | }; |
| 103 | }; |
| 104 | |
| 105 | // Add the debug event listener. |
iposva@chromium.org | 245aa85 | 2009-02-10 00:49:54 +0000 | [diff] [blame] | 106 | Debug.setListener(listener); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 107 | |
| 108 | function h() { |
| 109 | var a = 1; |
| 110 | var b = 2; |
| 111 | debugger; // Breakpoint. |
| 112 | }; |
| 113 | |
| 114 | function g() { |
| 115 | var a = 3; |
| 116 | eval("var b = 4;"); |
| 117 | h(); |
| 118 | }; |
| 119 | |
| 120 | function f() { |
| 121 | var a = 5; |
| 122 | var b = 0; |
| 123 | with ({b:6}) { |
| 124 | g(); |
| 125 | } |
| 126 | }; |
| 127 | |
| 128 | f(); |
| 129 | |
| 130 | // Make sure that the debug event listener vas invoked. |
| 131 | assertTrue(listenerComplete); |
| 132 | assertFalse(exception, "exception in listener") |