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

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

Issue 11415042: Issue 2399 part 1: In debugger allow modifying local variable values (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: follow codereview Created 8 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 | Annotate | Revision Log
« no previous file with comments | « src/runtime.cc ('k') | no next file » | 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 2012 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
30 // Get the Debug object exposed from the debug context global object.
31 var Debug = debug.Debug;
32
33 // Accepts a function/closure 'fun' that must have a debugger statement inside.
34 // A variable 'variable_name' must be initialized before debugger statement
35 // and returned after the statement. The test will alter variable value when
36 // on debugger statement and check that returned value reflects the change.
37 function RunPauseTest(scope_number, variable_name, expected_new_value, fun) {
38 var old_value = fun();
39
40 var listener_delegate;
41 var listener_called = false;
42 var exception = null;
43
44 function listener_delegate(exec_state) {
45 var scope = exec_state.frame(0).scope(scope_number);
46 scope.setVariableValue(variable_name, expected_new_value);
47 }
48
49 function listener(event, exec_state, event_data, data) {
50 try {
51 if (event == Debug.DebugEvent.Break) {
52 listener_called = true;
53 listener_delegate(exec_state);
54 }
55 } catch (e) {
56 exception = e;
57 }
58 }
59
60 // Add the debug event listener.
61 Debug.setListener(listener);
62
63 var actual_new_value;
64 try {
65 actual_new_value = fun();
66 } finally {
67 Debug.setListener(null);
68 }
69
70 if (exception != null) {
71 assertUnreachable("Exception: " + exception);
72 }
73 assertTrue(listener_called);
74
75 assertTrue(old_value != actual_new_value);
76 assertTrue(expected_new_value == actual_new_value);
77 }
78
79 // Accepts a closure 'fun' that returns a variable from it's outer scope.
80 // The test changes the value of variable via the handle to function and checks
81 // that the return value changed accordingly.
82 function RunClosureTest(scope_number, variable_name, expected_new_value, fun) {
83 var old_value = fun();
84
85 var fun_mirror = Debug.MakeMirror(fun);
86
87 var scope = fun_mirror.scope(scope_number);
88 scope.setVariableValue(variable_name, expected_new_value);
89
90 var actual_new_value = fun();
91
92 assertTrue(old_value != actual_new_value);
93 assertTrue(expected_new_value == actual_new_value);
94 }
95
96 // Test changing variable value when in pause
97 RunPauseTest(1, 'v1', 5, (function Factory() {
98 var v1 = 'cat';
99 return function() {
100 debugger;
101 return v1;
102 }
103 })());
104
105 RunPauseTest(1, 'v2', 11, (function Factory(v2) {
106 return function() {
107 debugger;
108 return v2;
109 }
110 })('dog'));
111
112 RunPauseTest(3, 'foo', 77, (function Factory() {
113 var foo = "capybara";
114 return (function() {
115 var bar = "fish";
116 try {
117 throw {name: "test exception"};
118 } catch (e) {
119 return function() {
120 debugger;
121 bar = "beast";
122 return foo;
123 }
124 }
125 })();
126 })());
127
128
129
130 // Test changing variable value in closure by handle
131 RunClosureTest(0, 'v1', 5, (function Factory() {
132 var v1 = 'cat';
133 return function() {
134 return v1;
135 }
136 })());
137
138 RunClosureTest(0, 'v2', 11, (function Factory(v2) {
139 return function() {
140 return v2;
141 }
142 })('dog'));
143
144 RunClosureTest(2, 'foo', 77, (function Factory() {
145 var foo = "capybara";
146 return (function() {
147 var bar = "fish";
148 try {
149 throw {name: "test exception"};
150 } catch (e) {
151 return function() {
152 bar = "beast";
153 return foo;
154 }
155 }
156 })();
157 })());
158
159
160 // Test value description protocol JSON
161 assertEquals(true, Debug.TestApi.CommandProcessorResolveValue({value: true}));
162
163 assertSame(null, Debug.TestApi.CommandProcessorResolveValue({type: "null"}));
164 assertSame(undefined,
165 Debug.TestApi.CommandProcessorResolveValue({type: "undefined"}));
166
167 assertSame("123", Debug.TestApi.CommandProcessorResolveValue(
168 {type: "string", stringDescription: "123"}));
169 assertSame(123, Debug.TestApi.CommandProcessorResolveValue(
170 {type: "number", stringDescription: "123"}));
171
172 assertSame(Number, Debug.TestApi.CommandProcessorResolveValue(
173 {handle: Debug.MakeMirror(Number).handle()}));
174 assertSame(RunClosureTest, Debug.TestApi.CommandProcessorResolveValue(
175 {handle: Debug.MakeMirror(RunClosureTest).handle()}));
176
OLDNEW
« no previous file with comments | « src/runtime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698