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

Side by Side Diff: test/mjsunit/debug-liveedit-check-stack.js

Issue 1118007: LiveEdit: implement frame dropping (Closed)
Patch Set: adding rule to mjsunit.status Created 10 years, 8 months 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 | « src/x64/debug-x64.cc ('k') | test/mjsunit/mjsunit.status » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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
(...skipping 12 matching lines...) Expand all
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
29 // Get the Debug object exposed from the debug context global object. 29 // Get the Debug object exposed from the debug context global object.
30 30
31 Debug = debug.Debug 31 Debug = debug.Debug
32 32
33 eval( 33 unique_id = 1;
34 "function ChooseAnimal(callback) {\n " + 34
35 " callback();\n" + 35 function TestBase(name) {
36 " return 'Cat';\n" + 36 print("TestBase constructor: " + name);
37 "}\n" 37
38 ); 38 this.ChooseAnimal = eval(
39 "/* " + unique_id + "*/\n" +
40 "(function ChooseAnimal(callback) {\n " +
41 " callback();\n" +
42 " return 'Cat';\n" +
43 "})\n"
44 );
45 // Prevents eval script caching.
46 unique_id++;
47
48 var script = Debug.findScript(this.ChooseAnimal);
49
50 var orig_animal = "'Cat'";
51 var patch_pos = script.source.indexOf(orig_animal);
52 var new_animal_patch = "'Capybara'";
53
54 var got_exception = false;
55 var successfully_changed = false;
56
57 // Should be called from Debug context.
58 this.ScriptChanger = function() {
59 assertEquals(false, successfully_changed, "applying patch second time");
60 // Runs in debugger context.
61 var change_log = new Array();
62 try {
63 Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_anim al_patch, change_log);
64 } finally {
65 print("Change log: " + JSON.stringify(change_log) + "\n");
66 }
67 successfully_changed = true;
68 };
69 }
39 70
40 function Noop() {} 71 function Noop() {}
41 var res = ChooseAnimal(Noop);
42 72
43 assertEquals("Cat", res); 73 function WrapInCatcher(f, holder) {
44 74 return function() {
45 var script = Debug.findScript(ChooseAnimal); 75 delete holder[0];
46 76 try {
47 var orig_animal = "'Cat'"; 77 f();
48 var patch_pos = script.source.indexOf(orig_animal); 78 } catch (e) {
49 var new_animal_patch = "'Capybara'"; 79 if (e instanceof Debug.LiveEditChangeScript.Failure) {
50 80 holder[0] = e;
51 var got_exception = false; 81 } else {
52 var successfully_changed = false; 82 throw e;
53 83 }
54 function Changer() {
55 // Never try the same patch again.
56 assertEquals(false, successfully_changed);
57 var change_log = new Array();
58 try {
59 Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_animal _patch, change_log);
60 successfully_changed = true;
61 } catch (e) {
62 if (e instanceof Debug.LiveEditChangeScript.Failure) {
63 got_exception = true;
64 print(e);
65 } else {
66 throw e;
67 } 84 }
68 } 85 };
69 print("Change log: " + JSON.stringify(change_log) + "\n");
70 } 86 }
71 87
72 var new_res = ChooseAnimal(Changer); 88 function WrapInNativeCall(f) {
73 // Function must be not pached. 89 return function() {
74 assertEquals("Cat", new_res); 90 return Debug.ExecuteInDebugContext(f, true);
91 };
92 }
75 93
76 assertEquals(true, got_exception); 94 function WrapInDebuggerCall(f) {
95 return function() {
96 return Debug.ExecuteInDebugContext(f, false);
97 };
98 }
77 99
78 // This time it should succeed. 100 function WrapInRestartProof(f) {
79 Changer(); 101 var already_called = false;
102 return function() {
103 if (already_called) {
104 return;
105 }
106 already_called = true;
107 f();
108 }
109 }
80 110
81 new_res = ChooseAnimal(Noop); 111 function WrapInConstructor(f) {
82 // Function must be not pached. 112 return function() {
83 assertEquals("Capybara", new_res); 113 return new function() {
114 f();
115 };
116 }
117 }
84 118
119
120 // A series of tests. In each test we call ChooseAnimal function that calls
121 // a callback that attempts to modify the function on the fly.
122
123 test = new TestBase("First test ChooseAnimal without edit");
124 assertEquals("Cat", test.ChooseAnimal(Noop));
125
126 test = new TestBase("Test without function on stack");
127 test.ScriptChanger();
128 assertEquals("Capybara", test.ChooseAnimal(Noop));
129
130 test = new TestBase("Test with function on stack");
131 assertEquals("Capybara", test.ChooseAnimal(WrapInDebuggerCall(WrapInRestartProof (test.ScriptChanger))));
132
133
134 test = new TestBase("Test with function on stack and with constructor frame");
135 assertEquals("Capybara", test.ChooseAnimal(WrapInConstructor(WrapInDebuggerCall( WrapInRestartProof(test.ScriptChanger)))));
136
137 test = new TestBase("Test with C++ frame above ChooseAnimal frame");
138 exception_holder = {};
139 assertEquals("Cat", test.ChooseAnimal(WrapInNativeCall(WrapInDebuggerCall(WrapIn Catcher(test.ScriptChanger, exception_holder)))));
140 assertTrue(!!exception_holder[0]);
141
OLDNEW
« no previous file with comments | « src/x64/debug-x64.cc ('k') | test/mjsunit/mjsunit.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698