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.js. | 6 // debug.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 // |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 (function(global, utils) { | 23 (function(global, utils) { |
24 "use strict"; | 24 "use strict"; |
25 | 25 |
26 // ------------------------------------------------------------------- | 26 // ------------------------------------------------------------------- |
27 // Imports | 27 // Imports |
28 | 28 |
29 var FindScriptSourcePosition = global.Debug.findScriptSourcePosition; | 29 var FindScriptSourcePosition = global.Debug.findScriptSourcePosition; |
30 var GlobalArray = global.Array; | 30 var GlobalArray = global.Array; |
31 var MathFloor = global.Math.floor; | 31 var MathFloor = global.Math.floor; |
32 var MathMax = global.Math.max; | |
33 var SyntaxError = global.SyntaxError; | 32 var SyntaxError = global.SyntaxError; |
34 | 33 |
35 // ------------------------------------------------------------------- | 34 // ------------------------------------------------------------------- |
36 | 35 |
37 // Forward declaration for minifier. | 36 // Forward declaration for minifier. |
38 var FunctionStatus; | 37 var FunctionStatus; |
39 | 38 |
40 // Applies the change to the script. | 39 // Applies the change to the script. |
41 // The change is in form of list of chunks encoded in a single array as | 40 // The change is in form of list of chunks encoded in a single array as |
42 // a series of triplets (pos1_start, pos1_end, pos2_end) | 41 // a series of triplets (pos1_start, pos1_end, pos2_end) |
(...skipping 26 matching lines...) Expand all Loading... |
69 if (e instanceof SyntaxError) { | 68 if (e instanceof SyntaxError) { |
70 var details = { | 69 var details = { |
71 type: "liveedit_compile_error", | 70 type: "liveedit_compile_error", |
72 syntaxErrorMessage: e.message | 71 syntaxErrorMessage: e.message |
73 }; | 72 }; |
74 CopyErrorPositionToDetails(e, details); | 73 CopyErrorPositionToDetails(e, details); |
75 failure.details = details; | 74 failure.details = details; |
76 } | 75 } |
77 throw failure; | 76 throw failure; |
78 } | 77 } |
79 | |
80 var max_function_literal_id = new_compile_info.reduce( | |
81 (max, info) => MathMax(max, info.function_literal_id), 0); | |
82 | |
83 var root_new_node = BuildCodeInfoTree(new_compile_info); | 78 var root_new_node = BuildCodeInfoTree(new_compile_info); |
84 | 79 |
85 // Link recompiled script data with other data. | 80 // Link recompiled script data with other data. |
86 FindCorrespondingFunctions(root_old_node, root_new_node); | 81 FindCorrespondingFunctions(root_old_node, root_new_node); |
87 | 82 |
88 // Prepare to-do lists. | 83 // Prepare to-do lists. |
89 var replace_code_list = new GlobalArray(); | 84 var replace_code_list = new GlobalArray(); |
90 var link_to_old_script_list = new GlobalArray(); | 85 var link_to_old_script_list = new GlobalArray(); |
91 var link_to_original_script_list = new GlobalArray(); | 86 var link_to_original_script_list = new GlobalArray(); |
92 var update_positions_list = new GlobalArray(); | 87 var update_positions_list = new GlobalArray(); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // Create an old script only if there are function that should be linked | 170 // Create an old script only if there are function that should be linked |
176 // to old version. | 171 // to old version. |
177 if (link_to_old_script_list.length == 0) { | 172 if (link_to_old_script_list.length == 0) { |
178 %LiveEditReplaceScript(script, new_source, null); | 173 %LiveEditReplaceScript(script, new_source, null); |
179 old_script = UNDEFINED; | 174 old_script = UNDEFINED; |
180 } else { | 175 } else { |
181 var old_script_name = CreateNameForOldScript(script); | 176 var old_script_name = CreateNameForOldScript(script); |
182 | 177 |
183 // Update the script text and create a new script representing an old | 178 // Update the script text and create a new script representing an old |
184 // version of the script. | 179 // version of the script. |
185 old_script = %LiveEditReplaceScript(script, new_source, old_script_name); | 180 old_script = %LiveEditReplaceScript(script, new_source, |
| 181 old_script_name); |
186 | 182 |
187 var link_to_old_script_report = new GlobalArray(); | 183 var link_to_old_script_report = new GlobalArray(); |
188 change_log.push( { linked_to_old_script: link_to_old_script_report } ); | 184 change_log.push( { linked_to_old_script: link_to_old_script_report } ); |
189 | 185 |
190 // We need to link to old script all former nested functions. | 186 // We need to link to old script all former nested functions. |
191 for (var i = 0; i < link_to_old_script_list.length; i++) { | 187 for (var i = 0; i < link_to_old_script_list.length; i++) { |
192 LinkToOldScript(link_to_old_script_list[i], old_script, | 188 LinkToOldScript(link_to_old_script_list[i], old_script, |
193 link_to_old_script_report); | 189 link_to_old_script_report); |
194 } | 190 } |
195 | 191 |
196 preview_description.created_script_name = old_script_name; | 192 preview_description.created_script_name = old_script_name; |
197 } | 193 } |
198 | 194 |
| 195 // Link to an actual script all the functions that we are going to use. |
| 196 for (var i = 0; i < link_to_original_script_list.length; i++) { |
| 197 %LiveEditFunctionSetScript( |
| 198 link_to_original_script_list[i].info.shared_function_info, script); |
| 199 } |
| 200 |
199 for (var i = 0; i < replace_code_list.length; i++) { | 201 for (var i = 0; i < replace_code_list.length; i++) { |
200 PatchFunctionCode(replace_code_list[i], change_log); | 202 PatchFunctionCode(replace_code_list[i], change_log); |
201 } | 203 } |
202 | 204 |
203 var position_patch_report = new GlobalArray(); | 205 var position_patch_report = new GlobalArray(); |
204 change_log.push( {position_patched: position_patch_report} ); | 206 change_log.push( {position_patched: position_patch_report} ); |
205 | 207 |
206 for (var i = 0; i < update_positions_list.length; i++) { | 208 for (var i = 0; i < update_positions_list.length; i++) { |
207 // TODO(LiveEdit): take into account whether it's source_changed or | 209 // TODO(LiveEdit): take into account whether it's source_changed or |
208 // unchanged and whether positions changed at all. | 210 // unchanged and whether positions changed at all. |
209 PatchPositions(update_positions_list[i], diff_array, | 211 PatchPositions(update_positions_list[i], diff_array, |
210 position_patch_report); | 212 position_patch_report); |
211 | 213 |
212 if (update_positions_list[i].live_shared_function_infos) { | 214 if (update_positions_list[i].live_shared_function_infos) { |
213 var new_function_literal_id = | 215 update_positions_list[i].live_shared_function_infos. |
214 update_positions_list[i] | 216 forEach(function (info) { |
215 .corresponding_node.info.function_literal_id; | 217 %LiveEditFunctionSourceUpdated(info.raw_array); |
216 update_positions_list[i].live_shared_function_infos.forEach(function( | 218 }); |
217 info) { | |
218 %LiveEditFunctionSourceUpdated( | |
219 info.raw_array, new_function_literal_id); | |
220 }); | |
221 } | 219 } |
222 } | 220 } |
223 | 221 |
224 %LiveEditFixupScript(script, max_function_literal_id); | |
225 | |
226 // Link all the functions we're going to use to an actual script. | |
227 for (var i = 0; i < link_to_original_script_list.length; i++) { | |
228 %LiveEditFunctionSetScript( | |
229 link_to_original_script_list[i].info.shared_function_info, script); | |
230 } | |
231 | |
232 preview_description.updated = true; | 222 preview_description.updated = true; |
233 return preview_description; | 223 return preview_description; |
234 } | 224 } |
235 | 225 |
236 // Fully compiles source string as a script. Returns Array of | 226 // Fully compiles source string as a script. Returns Array of |
237 // FunctionCompileInfo -- a descriptions of all functions of the script. | 227 // FunctionCompileInfo -- a descriptions of all functions of the script. |
238 // Elements of array are ordered by start positions of functions (from top | 228 // Elements of array are ordered by start positions of functions (from top |
239 // to bottom) in the source. Fields outer_index and next_sibling_index help | 229 // to bottom) in the source. Fields outer_index and next_sibling_index help |
240 // to navigate the nesting structure of functions. | 230 // to navigate the nesting structure of functions. |
241 // | 231 // |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 // An object describing function compilation details. Its index fields | 754 // An object describing function compilation details. Its index fields |
765 // apply to indexes inside array that stores these objects. | 755 // apply to indexes inside array that stores these objects. |
766 function FunctionCompileInfo(raw_array) { | 756 function FunctionCompileInfo(raw_array) { |
767 this.function_name = raw_array[0]; | 757 this.function_name = raw_array[0]; |
768 this.start_position = raw_array[1]; | 758 this.start_position = raw_array[1]; |
769 this.end_position = raw_array[2]; | 759 this.end_position = raw_array[2]; |
770 this.param_num = raw_array[3]; | 760 this.param_num = raw_array[3]; |
771 this.scope_info = raw_array[4]; | 761 this.scope_info = raw_array[4]; |
772 this.outer_index = raw_array[5]; | 762 this.outer_index = raw_array[5]; |
773 this.shared_function_info = raw_array[6]; | 763 this.shared_function_info = raw_array[6]; |
774 this.function_literal_id = raw_array[8]; | |
775 this.next_sibling_index = null; | 764 this.next_sibling_index = null; |
776 this.raw_array = raw_array; | 765 this.raw_array = raw_array; |
777 } | 766 } |
778 | 767 |
779 function SharedInfoWrapper(raw_array) { | 768 function SharedInfoWrapper(raw_array) { |
780 this.function_name = raw_array[0]; | 769 this.function_name = raw_array[0]; |
781 this.start_position = raw_array[1]; | 770 this.start_position = raw_array[1]; |
782 this.end_position = raw_array[2]; | 771 this.end_position = raw_array[2]; |
783 this.info = raw_array[3]; | 772 this.info = raw_array[3]; |
784 this.raw_array = raw_array; | 773 this.raw_array = raw_array; |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1042 | 1031 |
1043 LiveEdit.TestApi = { | 1032 LiveEdit.TestApi = { |
1044 PosTranslator: PosTranslator, | 1033 PosTranslator: PosTranslator, |
1045 CompareStrings: CompareStrings, | 1034 CompareStrings: CompareStrings, |
1046 ApplySingleChunkPatch: ApplySingleChunkPatch | 1035 ApplySingleChunkPatch: ApplySingleChunkPatch |
1047 }; | 1036 }; |
1048 | 1037 |
1049 global.Debug.LiveEdit = LiveEdit; | 1038 global.Debug.LiveEdit = LiveEdit; |
1050 | 1039 |
1051 }) | 1040 }) |
OLD | NEW |