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 // Flags: --expose-debug-as debug | |
29 // Get the Debug object exposed from the debug context global object. | |
30 Debug = debug.Debug | |
31 | |
32 function DebuggerStatement() { | |
33 debugger; | |
34 } | |
35 | |
36 function TestCase(fun) { | |
37 var exception = false; | |
38 var codeSnippet = undefined; | |
39 var resultPositions = undefined; | |
40 | |
41 function listener(event, exec_state, event_data, data) { | |
42 try { | |
43 if (event == Debug.DebugEvent.Break) { | |
44 Debug.setListener(null); | |
45 | |
46 var secondFrame = exec_state.frame(1); | |
47 codeSnippet = secondFrame.sourceLineText(); | |
48 resultPositions = secondFrame.stepInPositions(); | |
49 } | |
50 } catch (e) { | |
51 exception = e | |
52 } | |
53 } | |
54 | |
55 Debug.setListener(listener); | |
56 | |
57 fun(); | |
58 | |
59 Debug.setListener(null); | |
60 | |
61 assertTrue(!exception, exception); | |
62 | |
63 var expectedPositions = {}; | |
64 var markPattern = new RegExp("/\\*#\\*/", "g"); | |
65 | |
66 var matchResult; | |
67 while ( (matchResult = markPattern.exec(codeSnippet)) ) { | |
68 expectedPositions[matchResult.index] = true; | |
69 } | |
70 | |
71 print(codeSnippet); | |
72 | |
73 var decoratedResult = codeSnippet; | |
74 | |
75 function replaceStringRange(s, pos, substitute) { | |
76 return s.substring(0, pos) + substitute + | |
77 s.substring(pos + substitute.length); | |
78 } | |
79 | |
80 var markLength = 5; | |
81 var unexpectedPositionFound = false; | |
82 | |
83 for (var i = 0; i < resultPositions.length; i++) { | |
84 var col = resultPositions[i].position.column - markLength; | |
85 if (expectedPositions[col]) { | |
86 delete expectedPositions[col]; | |
87 decoratedResult = replaceStringRange(decoratedResult, col, "*YES*"); | |
88 } else { | |
89 decoratedResult = replaceStringRange(decoratedResult, col, "!BAD!"); | |
90 unexpectedPositionFound = true; | |
91 } | |
92 } | |
93 | |
94 print(decoratedResult); | |
95 | |
96 for (var n in expectedPositions) { | |
97 assertTrue(false, "Some positions are not reported: " + decoratedResult); | |
98 break; | |
99 } | |
100 assertFalse(unexpectedPositionFound, "Found unexpected position: " + | |
101 decoratedResult); | |
102 } | |
103 | |
104 | |
105 // Test cases. | |
106 | |
107 // Method calls. | |
108 var fun = function() { | |
109 var data = { | |
110 a: function() {} | |
111 }; | |
112 var res = [ DebuggerStatement(), data./*#*/a(), data[/*#*/String("a")]/*#*/(), data["a"]/*#*/(), data.a, data["a"] ]; | |
Yang
2013/08/06 09:33:26
80 char limit.
| |
113 }; | |
114 TestCase(fun); | |
115 | |
116 // Function call on a value. | |
117 var fun = function() { | |
118 function g(p) { | |
119 return g; | |
120 } | |
121 var res = [ DebuggerStatement(), /*#*/g(2), /*#*/g(2)/*#*/(3), /*#*/g(0)/*#*/( 0)/*#*/(g) ]; | |
122 }; | |
123 TestCase(fun); | |
124 | |
125 // Local function call, closure function call, | |
126 // local function construction call. | |
127 var fun = (function(p) { | |
128 return function() { | |
129 function f(a, b) { | |
130 } | |
131 var res = /*#*/f(DebuggerStatement(), /*#*/p(/*#*/new f())); | |
132 }; | |
133 })(Object); | |
134 TestCase(fun); | |
135 | |
136 // Global function, global object construction. | |
137 var fun = (function(p) { | |
138 return function() { | |
139 var res = [ DebuggerStatement(), Math./*#*/abs(4), /*#*/new Object()./*#*/to String() ]; | |
140 }; | |
141 })(Object); | |
142 TestCase(fun); | |
OLD | NEW |