OLD | NEW |
(Empty) | |
| 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 // The functions used for testing backtraces. They are at the top to make the |
| 29 // testing of source line/column easier. |
| 30 function f(x, y) { |
| 31 a=1; |
| 32 }; |
| 33 |
| 34 var m = (0, function() { |
| 35 new f(1); |
| 36 }); |
| 37 |
| 38 function g() { |
| 39 m(); |
| 40 }; |
| 41 |
| 42 |
| 43 // Get the Debug object exposed from the debug context global object. |
| 44 Debug = debug.Debug |
| 45 |
| 46 listenerCalled = false; |
| 47 exception = false; |
| 48 |
| 49 function listener(event, exec_state, event_data, data) { |
| 50 try { |
| 51 if (event == Debug.DebugEvent.Break) { |
| 52 // The expected backtrace is |
| 53 // 0: f |
| 54 // 1: m |
| 55 // 2: g |
| 56 // 3: [anonymous] |
| 57 assertEquals(4, exec_state.frameCount()); |
| 58 |
| 59 var frame0 = exec_state.frame(0); |
| 60 assertEquals("f", frame0.func().name()); |
| 61 assertEquals(0, frame0.index()); |
| 62 assertEquals(31, frame0.sourceLine()); |
| 63 assertEquals(2, frame0.sourceColumn()); |
| 64 assertEquals(2, frame0.localCount()); |
| 65 assertEquals("x", frame0.localName(0)); |
| 66 assertEquals(1, frame0.localValue(0).value()); |
| 67 assertEquals("y", frame0.localName(1)); |
| 68 assertEquals(undefined, frame0.localValue(1).value()); |
| 69 |
| 70 var frame1 = exec_state.frame(1); |
| 71 assertEquals("m", frame1.func().name()); |
| 72 assertEquals(1, frame1.index()); |
| 73 assertEquals(35, frame1.sourceLine()); |
| 74 assertEquals(2, frame1.sourceColumn()); |
| 75 assertEquals(0, frame1.localCount()); |
| 76 |
| 77 var frame2 = exec_state.frame(2); |
| 78 assertEquals("g", frame2.func().name()); |
| 79 |
| 80 var frame3 = exec_state.frame(3); |
| 81 assertEquals("", frame3.func().name()); |
| 82 |
| 83 listenerCalled = true; |
| 84 } |
| 85 } catch (e) { |
| 86 exception = e; |
| 87 }; |
| 88 }; |
| 89 |
| 90 // Add the debug event listener. |
| 91 Debug.setListener(listener); |
| 92 |
| 93 // Set a break point and call to invoke the debug event listener. |
| 94 Debug.setBreakPoint(f, 0, 0); |
| 95 g(); |
| 96 |
| 97 // Make sure that the debug event listener vas invoked. |
| 98 assertFalse(exception, "exception in listener"); |
| 99 assertTrue(listenerCalled); |
OLD | NEW |