Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: test/mjsunit/debug-setbreakpoint.js

Issue 2566093002: [debug-wrapper] migrate some scope related tests (Closed)
Patch Set: address comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/mjsunit/debug-scopes.js ('k') | test/mjsunit/es6/debug-blockscopes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // Simple function which stores the last debug event.
33 var listenerComplete = false;
34 var exception = false;
35 var f_script_id = 0;
36 var g_script_id = 0;
37 var h_script_id = 0;
38 var f_line = 0;
39 var g_line = 0;
40 var h_line = 0;
41
42 function listener(event, exec_state, event_data, data) {
43 try {
44 if (event == Debug.DebugEvent.Break) {
45 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value());
46 Debug.setBreakPoint(exec_state.evaluateGlobal("h").value());
47 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1);
48 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(), 1);
49 Debug.setBreakPoint(exec_state.evaluateGlobal("f").value(),
50 undefined, undefined, "i == 1");
51
52 Debug.setScriptBreakPointByName("test");
53 Debug.setScriptBreakPointByName("test", 1);
54 Debug.setScriptBreakPointByName("test", 1, 1);
55
56 Debug.setScriptBreakPointByName(f_script_id, f_line);
57 Debug.setScriptBreakPointByName(g_script_id, g_line);
58 Debug.setScriptBreakPointByName(h_script_id, h_line);
59
60 // Indicate that all was processed.
61 listenerComplete = true;
62 }
63 } catch (e) {
64 exception = e
65 };
66 };
67
68 // Add the debug event listener.
69 Debug.setListener(listener);
70
71 function f() {
72 a=1
73 };
74
75 function g() {
76 // Comment.
77 f();
78 };
79
80 eval('function h(){}');
81 eval('function sourceUrlFunc() { a = 2; }\n//# sourceURL=sourceUrlScript');
82
83 o = {a:function(){},b:function(){}}
84
85 // Check the script ids for the test functions.
86 f_script_id = Debug.findScript(f).id;
87 g_script_id = Debug.findScript(g).id;
88 h_script_id = Debug.findScript(h).id;
89 sourceURL_script_id = Debug.findScript(sourceUrlFunc).id;
90
91 assertTrue(f_script_id > 0, "invalid script id for f");
92 assertTrue(g_script_id > 0, "invalid script id for g");
93 assertTrue(h_script_id > 0, "invalid script id for h");
94 assertTrue(sourceURL_script_id > 0, "invalid script id for sourceUrlFunc");
95 assertEquals(f_script_id, g_script_id);
96
97 // Get the source line for the test functions.
98 f_line = Debug.findFunctionSourceLocation(f).line;
99 g_line = Debug.findFunctionSourceLocation(g).line;
100 h_line = Debug.findFunctionSourceLocation(h).line;
101 assertTrue(f_line > 0, "invalid line for f");
102 assertTrue(g_line > 0, "invalid line for g");
103 assertTrue(f_line < g_line);
104 assertEquals(h_line, 0, "invalid line for h");
105
106 // Set a break point and call to invoke the debug event listener.
107 Debug.setBreakPoint(g, 0, 0);
108 g();
109
110 // Make sure that the debug event listener was invoked.
111 assertTrue(listenerComplete, "listener did not run to completion: " + exception) ;
112
113 // Try setting breakpoint by url specified in sourceURL
114
115 var breakListenerCalled = false;
116
117 function breakListener(event) {
118 if (event == Debug.DebugEvent.Break)
119 breakListenerCalled = true;
120 }
121
122 Debug.setBreakPoint(sourceUrlFunc);
123
124 Debug.setListener(breakListener);
125
126 sourceUrlFunc();
127
128 assertTrue(breakListenerCalled, "Break listener not called on breakpoint set by sourceURL");
129
130
131 // Breakpoint in a script with no statements test case. If breakpoint is set
132 // to the script body, its actual position is taken from the nearest statement
133 // below or like in this case is reset to the very end of the script.
134 // Unless some precautions made, this position becomes out-of-range and
135 // we get an exception.
136
137 // Gets a script of 'i1' function and sets the breakpoint at line #4 which
138 // should be empty.
139 function SetBreakpointInI1Script() {
140 var i_script = Debug.findScript(i1);
141 assertTrue(!!i_script, "invalid script for i1");
142 Debug.setScriptBreakPoint(Debug.ScriptBreakPointType.ScriptId,
143 i_script.id, 4);
144 }
145
146 // Creates the eval script and tries to set the breakpoint.
147 // The tricky part is that the script function must be strongly reachable at the
148 // moment. Since there's no way of simply getting the pointer to the function,
149 // we run this code while the script function is being activated on stack.
150 eval('SetBreakpointInI1Script()\nfunction i1(){}\n\n\n\nfunction i2(){}\n');
OLDNEW
« no previous file with comments | « test/mjsunit/debug-scopes.js ('k') | test/mjsunit/es6/debug-blockscopes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698