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

Side by Side Diff: test/debugger/debug/debug-set-variable-value.js

Issue 2512963002: [debug-wrapper] Migrate more tests (Closed)
Patch Set: Rebase 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/debugger/debug/debug-script.js ('k') | test/debugger/debug/es6/debug-function-scopes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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
29 28
30 // Get the Debug object exposed from the debug context global object.
31 var Debug = debug.Debug; 29 var Debug = debug.Debug;
32 var DebugCommandProcessor = debug.DebugCommandProcessor;
33 30
34 // Accepts a function/closure 'fun' that must have a debugger statement inside. 31 // Accepts a function/closure 'fun' that must have a debugger statement inside.
35 // A variable 'variable_name' must be initialized before debugger statement 32 // A variable 'variable_name' must be initialized before debugger statement
36 // and returned after the statement. The test will alter variable value when 33 // and returned after the statement. The test will alter variable value when
37 // on debugger statement and check that returned value reflects the change. 34 // on debugger statement and check that returned value reflects the change.
38 function RunPauseTest(scope_number, expected_old_result, variable_name, 35 function RunPauseTest(scope_number, expected_old_result, variable_name,
39 new_value, expected_new_result, fun) { 36 new_value, expected_new_result, fun) {
40 var actual_old_result = fun(); 37 var actual_old_result = fun();
41 assertEquals(expected_old_result, actual_old_result); 38 assertEquals(expected_old_result, actual_old_result);
42 39
(...skipping 28 matching lines...) Expand all
71 } 68 }
72 69
73 if (exception != null) { 70 if (exception != null) {
74 assertUnreachable("Exception in listener\n" + exception.stack); 71 assertUnreachable("Exception in listener\n" + exception.stack);
75 } 72 }
76 assertTrue(listener_called); 73 assertTrue(listener_called);
77 74
78 assertEquals(expected_new_result, actual_new_result); 75 assertEquals(expected_new_result, actual_new_result);
79 } 76 }
80 77
81 // Accepts a closure 'fun' that returns a variable from its outer scope.
82 // The test changes the value of variable via the handle to function and checks
83 // that the return value changed accordingly.
84 function RunClosureTest(scope_number, expected_old_result, variable_name,
85 new_value, expected_new_result, fun) {
86 var actual_old_result = fun();
87 assertEquals(expected_old_result, actual_old_result);
88
89 var fun_mirror = Debug.MakeMirror(fun);
90
91 var scope = fun_mirror.scope(scope_number);
92 scope.setVariableValue(variable_name, new_value);
93
94 var actual_new_result = fun();
95
96 assertEquals(expected_new_result, actual_new_result);
97 }
98
99 78
100 function ClosureTestCase(scope_index, old_result, variable_name, new_value, 79 function ClosureTestCase(scope_index, old_result, variable_name, new_value,
101 new_result, success_expected, factory) { 80 new_result, success_expected, factory) {
102 this.scope_index_ = scope_index; 81 this.scope_index_ = scope_index;
103 this.old_result_ = old_result; 82 this.old_result_ = old_result;
104 this.variable_name_ = variable_name; 83 this.variable_name_ = variable_name;
105 this.new_value_ = new_value; 84 this.new_value_ = new_value;
106 this.new_result_ = new_result; 85 this.new_result_ = new_result;
107 this.success_expected_ = success_expected; 86 this.success_expected_ = success_expected;
108 this.factory_ = factory; 87 this.factory_ = factory;
109 } 88 }
110 89
111 ClosureTestCase.prototype.run_pause_test = function() { 90 ClosureTestCase.prototype.run_pause_test = function() {
112 var th = this; 91 var th = this;
113 var fun = this.factory_(true); 92 var fun = this.factory_(true);
114 this.run_and_catch_(function() { 93 this.run_and_catch_(function() {
115 RunPauseTest(th.scope_index_ + 1, th.old_result_, th.variable_name_, 94 RunPauseTest(th.scope_index_ + 1, th.old_result_, th.variable_name_,
116 th.new_value_, th.new_result_, fun); 95 th.new_value_, th.new_result_, fun);
117 }); 96 });
118 } 97 }
119 98
120 ClosureTestCase.prototype.run_closure_test = function() {
121 var th = this;
122 var fun = this.factory_(false);
123 this.run_and_catch_(function() {
124 RunClosureTest(th.scope_index_, th.old_result_, th.variable_name_,
125 th.new_value_, th.new_result_, fun);
126 });
127 }
128
129 ClosureTestCase.prototype.run_and_catch_ = function(runnable) { 99 ClosureTestCase.prototype.run_and_catch_ = function(runnable) {
130 if (this.success_expected_) { 100 if (this.success_expected_) {
131 runnable(); 101 runnable();
132 } else { 102 } else {
133 assertThrows(runnable); 103 assertThrows(runnable);
134 } 104 }
135 } 105 }
136 106
137 107
138 // Test scopes visible from closures. 108 // Test scopes visible from closures.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 175 }
206 } 176 }
207 })(); 177 })();
208 }) 178 })
209 ]; 179 ];
210 180
211 for (var i = 0; i < closure_test_cases.length; i++) { 181 for (var i = 0; i < closure_test_cases.length; i++) {
212 closure_test_cases[i].run_pause_test(); 182 closure_test_cases[i].run_pause_test();
213 } 183 }
214 184
215 for (var i = 0; i < closure_test_cases.length; i++) {
216 closure_test_cases[i].run_closure_test();
217 }
218
219 185
220 // Test local scope. 186 // Test local scope.
221 187
222 RunPauseTest(0, 'HelloYou', 'u', 'We', 'HelloWe', (function Factory() { 188 RunPauseTest(0, 'HelloYou', 'u', 'We', 'HelloWe', (function Factory() {
223 return function() { 189 return function() {
224 var u = "You"; 190 var u = "You";
225 var v = "Hello"; 191 var v = "Hello";
226 debugger; 192 debugger;
227 return v + u; 193 return v + u;
228 } 194 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 return void p; 249 return void p;
284 } 250 }
285 debugger; 251 debugger;
286 return p; 252 return p;
287 } 253 }
288 return A(5); 254 return A(5);
289 } 255 }
290 })()); 256 })());
291 257
292 258
293 // Test value description protocol JSON
294
295 assertEquals(true, DebugCommandProcessor.resolveValue_({value: true}));
296
297 assertSame(null, DebugCommandProcessor.resolveValue_({type: "null"}));
298 assertSame(undefined,
299 DebugCommandProcessor.resolveValue_({type: "undefined"}));
300
301 assertSame("123", DebugCommandProcessor.resolveValue_(
302 {type: "string", stringDescription: "123"}));
303 assertSame(123, DebugCommandProcessor.resolveValue_(
304 {type: "number", stringDescription: "123"}));
305
306 assertSame(Number, DebugCommandProcessor.resolveValue_(
307 {handle: Debug.MakeMirror(Number).handle()}));
308 assertSame(RunClosureTest, DebugCommandProcessor.resolveValue_(
309 {handle: Debug.MakeMirror(RunClosureTest).handle()}));
310
311
312 // Test script-scope variable. 259 // Test script-scope variable.
313 let abc = 12; 260 let abc = 12;
314 { 261 {
315 let exception; 262 let exception;
316 function listener(event, exec_state) { 263 function listener(event, exec_state) {
317 try { 264 try {
318 if (event == Debug.DebugEvent.Break) { 265 if (event == Debug.DebugEvent.Break) {
319 let scope_count = exec_state.frame().scopeCount(); 266 let scope_count = exec_state.frame().scopeCount();
320 let script_scope = exec_state.frame().scope(scope_count - 2); 267 let script_scope = exec_state.frame().scope(scope_count - 2);
321 assertTrue(script_scope.isScope());
322 assertEquals(debug.ScopeType.Script, script_scope.scopeType()); 268 assertEquals(debug.ScopeType.Script, script_scope.scopeType());
323 script_scope.setVariableValue('abc', 42); 269 script_scope.setVariableValue('abc', 42);
324 } 270 }
325 } catch(e) { exception = e } 271 } catch(e) { exception = e }
326 } 272 }
327 273
328 Debug.setListener(listener); 274 Debug.setListener(listener);
329 assertEquals(12, abc); 275 assertEquals(12, abc);
330 debugger; 276 debugger;
331 assertEquals(42, abc); 277 assertEquals(42, abc);
332 278
333 if (exception != null) { 279 if (exception != null) {
334 assertUnreachable("Exception in listener\n" + exception.stack); 280 assertUnreachable("Exception in listener\n" + exception.stack);
335 } 281 }
336 } 282 }
337 283
338 Debug.setListener(null); 284 Debug.setListener(null);
OLDNEW
« no previous file with comments | « test/debugger/debug/debug-script.js ('k') | test/debugger/debug/es6/debug-function-scopes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698