OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // LiveEdit feature implementation. The script should be executed after | 5 // LiveEdit feature implementation. The script should be executed after |
6 // debug-debugger.js. | 6 // debug-debugger.js. |
7 | 7 |
8 // A LiveEdit namespace. It contains functions that modifies JavaScript code | 8 // A LiveEdit namespace. It contains functions that modifies JavaScript code |
9 // according to changes of script source (if possible). | 9 // according to changes of script source (if possible). |
10 // | 10 // |
11 // When new script source is put in, the difference is calculated textually, | 11 // When new script source is put in, the difference is calculated textually, |
12 // in form of list of delete/add/change chunks. The functions that include | 12 // in form of list of delete/add/change chunks. The functions that include |
13 // change chunk(s) get recompiled, or their enclosing functions are | 13 // change chunk(s) get recompiled, or their enclosing functions are |
14 // recompiled instead. | 14 // recompiled instead. |
15 // If the function may not be recompiled (e.g. it was completely erased in new | 15 // If the function may not be recompiled (e.g. it was completely erased in new |
16 // version of the script) it remains unchanged, but the code that could | 16 // version of the script) it remains unchanged, but the code that could |
17 // create a new instance of this function goes away. An old version of script | 17 // create a new instance of this function goes away. An old version of script |
18 // is created to back up this obsolete function. | 18 // is created to back up this obsolete function. |
19 // All unchanged functions have their positions updated accordingly. | 19 // All unchanged functions have their positions updated accordingly. |
20 // | 20 // |
21 // LiveEdit namespace is declared inside a single function constructor. | 21 // LiveEdit namespace is declared inside a single function constructor. |
22 | 22 |
23 "use strict"; | 23 "use strict"; |
24 | 24 |
25 Debug.LiveEdit = new function() { | 25 Debug.LiveEdit = new function() { |
26 | 26 |
27 // Forward declaration for minifier. | 27 // Forward declaration for minifier. |
28 var FunctionStatus; | 28 var FunctionStatus; |
29 | 29 |
30 var NEEDS_STEP_IN_PROPERTY_NAME = "stack_update_needs_step_in"; | |
31 | |
32 // Applies the change to the script. | 30 // Applies the change to the script. |
33 // The change is in form of list of chunks encoded in a single array as | 31 // The change is in form of list of chunks encoded in a single array as |
34 // a series of triplets (pos1_start, pos1_end, pos2_end) | 32 // a series of triplets (pos1_start, pos1_end, pos2_end) |
35 function ApplyPatchMultiChunk(script, diff_array, new_source, preview_only, | 33 function ApplyPatchMultiChunk(script, diff_array, new_source, preview_only, |
36 change_log) { | 34 change_log) { |
37 | 35 |
38 var old_source = script.source; | 36 var old_source = script.source; |
39 | 37 |
40 // Gather compile information about old version of script. | 38 // Gather compile information about old version of script. |
41 var old_compile_info = GatherCompileInfo(old_source, script); | 39 var old_compile_info = GatherCompileInfo(old_source, script); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 140 } |
143 } | 141 } |
144 | 142 |
145 // We haven't changed anything before this line yet. | 143 // We haven't changed anything before this line yet. |
146 // Committing all changes. | 144 // Committing all changes. |
147 | 145 |
148 // Check that function being patched is not currently on stack or drop them. | 146 // Check that function being patched is not currently on stack or drop them. |
149 var dropped_functions_number = | 147 var dropped_functions_number = |
150 CheckStackActivations(replaced_function_infos, change_log); | 148 CheckStackActivations(replaced_function_infos, change_log); |
151 | 149 |
| 150 // Our current implementation requires client to manually issue "step in" |
| 151 // command for correct stack state if the stack was modified. |
152 preview_description.stack_modified = dropped_functions_number != 0; | 152 preview_description.stack_modified = dropped_functions_number != 0; |
153 | 153 |
154 // Our current implementation requires client to manually issue "step in" | |
155 // command for correct stack state. | |
156 preview_description[NEEDS_STEP_IN_PROPERTY_NAME] = | |
157 preview_description.stack_modified; | |
158 | |
159 // Start with breakpoints. Convert their line/column positions and | 154 // Start with breakpoints. Convert their line/column positions and |
160 // temporary remove. | 155 // temporary remove. |
161 var break_points_restorer = TemporaryRemoveBreakPoints(script, change_log); | 156 var break_points_restorer = TemporaryRemoveBreakPoints(script, change_log); |
162 | 157 |
163 var old_script; | 158 var old_script; |
164 | 159 |
165 // Create an old script only if there are function that should be linked | 160 // Create an old script only if there are function that should be linked |
166 // to old version. | 161 // to old version. |
167 if (link_to_old_script_list.length == 0) { | 162 if (link_to_old_script_list.length == 0) { |
168 %LiveEditReplaceScript(script, new_source, null); | 163 %LiveEditReplaceScript(script, new_source, null); |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 function DescribePositions(node) { | 1091 function DescribePositions(node) { |
1097 return { | 1092 return { |
1098 start_position: node.info.start_position, | 1093 start_position: node.info.start_position, |
1099 end_position: node.info.end_position | 1094 end_position: node.info.end_position |
1100 }; | 1095 }; |
1101 } | 1096 } |
1102 | 1097 |
1103 return ProcessOldNode(old_code_tree); | 1098 return ProcessOldNode(old_code_tree); |
1104 } | 1099 } |
1105 | 1100 |
1106 // Restarts call frame and returns value similar to what LiveEdit returns. | |
1107 function RestartFrame(frame_mirror) { | |
1108 var result = frame_mirror.restart(); | |
1109 if (IS_STRING(result)) { | |
1110 throw new Failure("Failed to restart frame: " + result); | |
1111 } | |
1112 var result = {}; | |
1113 result[NEEDS_STEP_IN_PROPERTY_NAME] = true; | |
1114 return result; | |
1115 } | |
1116 // Function is public. | |
1117 this.RestartFrame = RestartFrame; | |
1118 | |
1119 // Functions are public for tests. | 1101 // Functions are public for tests. |
1120 this.TestApi = { | 1102 this.TestApi = { |
1121 PosTranslator: PosTranslator, | 1103 PosTranslator: PosTranslator, |
1122 CompareStrings: CompareStrings, | 1104 CompareStrings: CompareStrings, |
1123 ApplySingleChunkPatch: ApplySingleChunkPatch | 1105 ApplySingleChunkPatch: ApplySingleChunkPatch |
1124 }; | 1106 }; |
1125 }; | 1107 }; |
OLD | NEW |