OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
11 // with the distribution. | 11 // with the distribution. |
12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
15 // | 15 // |
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug --nocrankshaft |
29 | |
30 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
31 Debug = debug.Debug | 30 Debug = debug.Debug |
32 | 31 |
33 var exception = null; | 32 var exception = null; |
34 var state = 1; | 33 var state = 1; |
35 var expected_source_line_text = null; | |
36 var expected_function_name = null; | |
37 | 34 |
38 // Simple debug event handler which first time will cause 'step in' action | 35 // Simple debug event handler which first time will cause 'step in' action |
39 // and than check that execution is paused inside function | 36 // to get into g.call and than check that execution is stopped inside |
40 // expected_function_name. | 37 // function 'g'. |
41 function listener(event, exec_state, event_data, data) { | 38 function listener(event, exec_state, event_data, data) { |
42 try { | 39 try { |
43 if (event == Debug.DebugEvent.Break) { | 40 if (event == Debug.DebugEvent.Break) { |
44 if (state == 1) { | 41 if (state == 1) { |
45 exec_state.prepareStep(Debug.StepAction.StepIn, 2); | 42 exec_state.prepareStep(Debug.StepAction.StepIn, 3); |
46 state = 2; | 43 state = 2; |
47 } else if (state == 2) { | 44 } else if (state == 2) { |
48 assertEquals(expected_function_name, event_data.func().name()); | 45 assertTrue(event_data.sourceLineText().indexOf("Expected to step") > 0, |
49 assertEquals(expected_source_line_text, | 46 "source line: \"" + event_data.sourceLineText() + "\""); |
50 event_data.sourceLineText()); | |
51 state = 3; | 47 state = 3; |
52 } | 48 } |
53 } | 49 } |
54 } catch(e) { | 50 } catch(e) { |
| 51 print("Exception: " + e); |
55 exception = e; | 52 exception = e; |
56 } | 53 } |
57 }; | 54 }; |
58 | 55 |
59 // Add the debug event listener. | 56 // Add the debug event listener. |
60 Debug.setListener(listener); | 57 Debug.setListener(listener); |
61 | 58 |
62 var a = [1,2,3,4,5]; | 59 var count = 0; |
| 60 var obj = { |
| 61 fun: function() { |
| 62 ++count; |
| 63 return count; // Expected to step |
| 64 } |
| 65 }; |
| 66 obj.fun2 = obj.fun; |
63 | 67 |
64 // Test step into function call from a function without local variables. | 68 function testCall_Dots() { |
65 function testStepInArraySlice() { | |
66 expected_function_name = 'testStepInArraySlice'; | |
67 expected_source_line_text = '} // expected line'; | |
68 debugger; | 69 debugger; |
69 var s = Array.prototype.slice.call(a, 2,3); | 70 obj.fun(); |
70 } // expected line | 71 } |
71 | 72 |
72 state = 1; | 73 function testCall_Quotes() { |
73 testStepInArraySlice(); | 74 debugger; |
74 assertNull(exception); | 75 obj["fun"](); |
75 assertEquals(3, state); | 76 } |
| 77 |
| 78 function testCall_Call() { |
| 79 debugger; |
| 80 obj.fun.call(obj); |
| 81 } |
| 82 |
| 83 function testCall_Apply() { |
| 84 debugger; |
| 85 obj.fun.apply(obj); |
| 86 } |
| 87 |
| 88 function testCall_Variable() { |
| 89 var functionName = "fun"; |
| 90 debugger; |
| 91 obj[functionName](); |
| 92 } |
| 93 |
| 94 function testCall_Fun2() { |
| 95 debugger; |
| 96 obj.fun2(); |
| 97 } |
| 98 |
| 99 function testCall_InternStrings() { |
| 100 var cache = { "fun": "fun" }; |
| 101 var functionName = "fu" + "n"; |
| 102 debugger; |
| 103 obj[cache[functionName]](); |
| 104 } |
| 105 |
| 106 function testCall_ViaFunRef() { |
| 107 var functionName = "fu" + "n"; |
| 108 var funRef = obj[functionName]; |
| 109 debugger; |
| 110 funRef(); |
| 111 } |
| 112 |
| 113 // bug 2888 |
| 114 function testCall_RuntimeVariable1() { |
| 115 var functionName = "fu" + "n"; |
| 116 debugger; |
| 117 obj[functionName](); |
| 118 } |
| 119 |
| 120 // bug 2888 |
| 121 function testCall_RuntimeVariable2() { |
| 122 var functionName = "un".replace(/u/, "fu"); |
| 123 debugger; |
| 124 obj[functionName](); |
| 125 } |
| 126 |
| 127 // bug 2888 |
| 128 function testCall_RuntimeVariable3() { |
| 129 var expr = "fu" + "n"; |
| 130 const functionName = expr; |
| 131 assertEquals("fun", functionName); |
| 132 debugger; |
| 133 obj[functionName](); |
| 134 } |
| 135 |
| 136 var functionsCalled = 0; |
| 137 for (var n in this) { |
| 138 if (n.substr(0, 4) != 'test' || typeof this[n] !== "function") { |
| 139 continue; |
| 140 } |
| 141 state = 1; |
| 142 print("Running " + n + "..."); |
| 143 this[n](); |
| 144 ++functionsCalled; |
| 145 assertNull(exception, n); |
| 146 assertEquals(3, state, n); |
| 147 assertEquals(functionsCalled, count, n); |
| 148 } |
| 149 |
| 150 assertEquals(11, functionsCalled); |
76 | 151 |
77 // Get rid of the debug event listener. | 152 // Get rid of the debug event listener. |
78 Debug.setListener(null); | 153 Debug.setListener(null); |
OLD | NEW |