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