Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 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 GetScriptBreakPoints; | 30 var GetScriptBreakPoints; |
| 31 var GlobalArray = global.Array; | 31 var GlobalArray = global.Array; |
| 32 var MathFloor = global.Math.floor; | 32 var MathFloor = global.Math.floor; |
| 33 var MathMax = global.Math.max; | |
| 33 var SyntaxError = global.SyntaxError; | 34 var SyntaxError = global.SyntaxError; |
| 34 | 35 |
| 35 utils.Import(function(from) { | 36 utils.Import(function(from) { |
| 36 GetScriptBreakPoints = from.GetScriptBreakPoints; | 37 GetScriptBreakPoints = from.GetScriptBreakPoints; |
| 37 }); | 38 }); |
| 38 | 39 |
| 39 // ------------------------------------------------------------------- | 40 // ------------------------------------------------------------------- |
| 40 | 41 |
| 41 // Forward declaration for minifier. | 42 // Forward declaration for minifier. |
| 42 var FunctionStatus; | 43 var FunctionStatus; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 73 if (e instanceof SyntaxError) { | 74 if (e instanceof SyntaxError) { |
| 74 var details = { | 75 var details = { |
| 75 type: "liveedit_compile_error", | 76 type: "liveedit_compile_error", |
| 76 syntaxErrorMessage: e.message | 77 syntaxErrorMessage: e.message |
| 77 }; | 78 }; |
| 78 CopyErrorPositionToDetails(e, details); | 79 CopyErrorPositionToDetails(e, details); |
| 79 failure.details = details; | 80 failure.details = details; |
| 80 } | 81 } |
| 81 throw failure; | 82 throw failure; |
| 82 } | 83 } |
| 84 | |
| 85 var max_function_literal_id = | |
| 86 MathMax.apply(null, new_compile_info.map(i => i.function_literal_id)); | |
|
Toon Verwaest
2016/12/06 21:10:14
What about just +new_compile_info.reduce((a,b)=>a>
jochen (gone - plz use gerrit)
2016/12/07 15:57:00
why does this make the stack grow like crazy?
Toon Verwaest
2016/12/08 07:31:30
.apply with a possibly huge array? Don't they all
jochen (gone - plz use gerrit)
2016/12/08 12:31:14
k
| |
| 87 | |
| 83 var root_new_node = BuildCodeInfoTree(new_compile_info); | 88 var root_new_node = BuildCodeInfoTree(new_compile_info); |
| 84 | 89 |
| 85 // Link recompiled script data with other data. | 90 // Link recompiled script data with other data. |
| 86 FindCorrespondingFunctions(root_old_node, root_new_node); | 91 FindCorrespondingFunctions(root_old_node, root_new_node); |
| 87 | 92 |
| 88 // Prepare to-do lists. | 93 // Prepare to-do lists. |
| 89 var replace_code_list = new GlobalArray(); | 94 var replace_code_list = new GlobalArray(); |
| 90 var link_to_old_script_list = new GlobalArray(); | 95 var link_to_old_script_list = new GlobalArray(); |
| 91 var link_to_original_script_list = new GlobalArray(); | 96 var link_to_original_script_list = new GlobalArray(); |
| 92 var update_positions_list = new GlobalArray(); | 97 var update_positions_list = new GlobalArray(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 // Create an old script only if there are function that should be linked | 184 // Create an old script only if there are function that should be linked |
| 180 // to old version. | 185 // to old version. |
| 181 if (link_to_old_script_list.length == 0) { | 186 if (link_to_old_script_list.length == 0) { |
| 182 %LiveEditReplaceScript(script, new_source, null); | 187 %LiveEditReplaceScript(script, new_source, null); |
| 183 old_script = UNDEFINED; | 188 old_script = UNDEFINED; |
| 184 } else { | 189 } else { |
| 185 var old_script_name = CreateNameForOldScript(script); | 190 var old_script_name = CreateNameForOldScript(script); |
| 186 | 191 |
| 187 // Update the script text and create a new script representing an old | 192 // Update the script text and create a new script representing an old |
| 188 // version of the script. | 193 // version of the script. |
| 189 old_script = %LiveEditReplaceScript(script, new_source, | 194 old_script = %LiveEditReplaceScript(script, new_source, old_script_name); |
| 190 old_script_name); | |
| 191 | 195 |
| 192 var link_to_old_script_report = new GlobalArray(); | 196 var link_to_old_script_report = new GlobalArray(); |
| 193 change_log.push( { linked_to_old_script: link_to_old_script_report } ); | 197 change_log.push( { linked_to_old_script: link_to_old_script_report } ); |
| 194 | 198 |
| 195 // We need to link to old script all former nested functions. | 199 // We need to link to old script all former nested functions. |
| 196 for (var i = 0; i < link_to_old_script_list.length; i++) { | 200 for (var i = 0; i < link_to_old_script_list.length; i++) { |
| 197 LinkToOldScript(link_to_old_script_list[i], old_script, | 201 LinkToOldScript(link_to_old_script_list[i], old_script, |
| 198 link_to_old_script_report); | 202 link_to_old_script_report); |
| 199 } | 203 } |
| 200 | 204 |
| 201 preview_description.created_script_name = old_script_name; | 205 preview_description.created_script_name = old_script_name; |
| 202 } | 206 } |
| 203 | 207 |
| 204 // Link to an actual script all the functions that we are going to use. | |
| 205 for (var i = 0; i < link_to_original_script_list.length; i++) { | |
| 206 %LiveEditFunctionSetScript( | |
| 207 link_to_original_script_list[i].info.shared_function_info, script); | |
| 208 } | |
| 209 | |
| 210 for (var i = 0; i < replace_code_list.length; i++) { | 208 for (var i = 0; i < replace_code_list.length; i++) { |
| 211 PatchFunctionCode(replace_code_list[i], change_log); | 209 PatchFunctionCode(replace_code_list[i], change_log); |
| 212 } | 210 } |
| 213 | 211 |
| 214 var position_patch_report = new GlobalArray(); | 212 var position_patch_report = new GlobalArray(); |
| 215 change_log.push( {position_patched: position_patch_report} ); | 213 change_log.push( {position_patched: position_patch_report} ); |
| 216 | 214 |
| 217 for (var i = 0; i < update_positions_list.length; i++) { | 215 for (var i = 0; i < update_positions_list.length; i++) { |
| 218 // TODO(LiveEdit): take into account whether it's source_changed or | 216 // TODO(LiveEdit): take into account whether it's source_changed or |
| 219 // unchanged and whether positions changed at all. | 217 // unchanged and whether positions changed at all. |
| 220 PatchPositions(update_positions_list[i], diff_array, | 218 PatchPositions(update_positions_list[i], diff_array, |
| 221 position_patch_report); | 219 position_patch_report); |
| 222 | 220 |
| 223 if (update_positions_list[i].live_shared_function_infos) { | 221 if (update_positions_list[i].live_shared_function_infos) { |
| 224 update_positions_list[i].live_shared_function_infos. | 222 var new_function_literal_id = |
| 225 forEach(function (info) { | 223 update_positions_list[i] |
| 226 %LiveEditFunctionSourceUpdated(info.raw_array); | 224 .corresponding_node.info.function_literal_id; |
| 227 }); | 225 update_positions_list[i].live_shared_function_infos.forEach(function( |
| 226 info) { | |
| 227 %LiveEditFunctionSourceUpdated( | |
| 228 info.raw_array, new_function_literal_id); | |
| 229 }); | |
| 228 } | 230 } |
| 229 } | 231 } |
| 230 | 232 |
| 233 %LiveEditFixupScript(script, max_function_literal_id); | |
| 234 | |
| 235 // Link to an actual script all the functions that we are going to use. | |
|
Toon Verwaest
2016/12/06 21:10:14
Link all the function we're going to use to an act
jochen (gone - plz use gerrit)
2016/12/07 15:57:00
done
| |
| 236 for (var i = 0; i < link_to_original_script_list.length; i++) { | |
| 237 %LiveEditFunctionSetScript( | |
| 238 link_to_original_script_list[i].info.shared_function_info, script); | |
| 239 } | |
| 240 | |
| 231 break_points_restorer(pos_translator, old_script); | 241 break_points_restorer(pos_translator, old_script); |
| 232 | 242 |
| 233 preview_description.updated = true; | 243 preview_description.updated = true; |
| 234 return preview_description; | 244 return preview_description; |
| 235 } | 245 } |
| 236 | 246 |
| 237 // Fully compiles source string as a script. Returns Array of | 247 // Fully compiles source string as a script. Returns Array of |
| 238 // FunctionCompileInfo -- a descriptions of all functions of the script. | 248 // FunctionCompileInfo -- a descriptions of all functions of the script. |
| 239 // Elements of array are ordered by start positions of functions (from top | 249 // Elements of array are ordered by start positions of functions (from top |
| 240 // to bottom) in the source. Fields outer_index and next_sibling_index help | 250 // to bottom) in the source. Fields outer_index and next_sibling_index help |
| (...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 // An object describing function compilation details. Its index fields | 848 // An object describing function compilation details. Its index fields |
| 839 // apply to indexes inside array that stores these objects. | 849 // apply to indexes inside array that stores these objects. |
| 840 function FunctionCompileInfo(raw_array) { | 850 function FunctionCompileInfo(raw_array) { |
| 841 this.function_name = raw_array[0]; | 851 this.function_name = raw_array[0]; |
| 842 this.start_position = raw_array[1]; | 852 this.start_position = raw_array[1]; |
| 843 this.end_position = raw_array[2]; | 853 this.end_position = raw_array[2]; |
| 844 this.param_num = raw_array[3]; | 854 this.param_num = raw_array[3]; |
| 845 this.scope_info = raw_array[4]; | 855 this.scope_info = raw_array[4]; |
| 846 this.outer_index = raw_array[5]; | 856 this.outer_index = raw_array[5]; |
| 847 this.shared_function_info = raw_array[6]; | 857 this.shared_function_info = raw_array[6]; |
| 858 this.function_literal_id = raw_array[8]; | |
| 848 this.next_sibling_index = null; | 859 this.next_sibling_index = null; |
| 849 this.raw_array = raw_array; | 860 this.raw_array = raw_array; |
| 850 } | 861 } |
| 851 | 862 |
| 852 function SharedInfoWrapper(raw_array) { | 863 function SharedInfoWrapper(raw_array) { |
| 853 this.function_name = raw_array[0]; | 864 this.function_name = raw_array[0]; |
| 854 this.start_position = raw_array[1]; | 865 this.start_position = raw_array[1]; |
| 855 this.end_position = raw_array[2]; | 866 this.end_position = raw_array[2]; |
| 856 this.info = raw_array[3]; | 867 this.info = raw_array[3]; |
| 857 this.raw_array = raw_array; | 868 this.raw_array = raw_array; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1115 | 1126 |
| 1116 LiveEdit.TestApi = { | 1127 LiveEdit.TestApi = { |
| 1117 PosTranslator: PosTranslator, | 1128 PosTranslator: PosTranslator, |
| 1118 CompareStrings: CompareStrings, | 1129 CompareStrings: CompareStrings, |
| 1119 ApplySingleChunkPatch: ApplySingleChunkPatch | 1130 ApplySingleChunkPatch: ApplySingleChunkPatch |
| 1120 }; | 1131 }; |
| 1121 | 1132 |
| 1122 global.Debug.LiveEdit = LiveEdit; | 1133 global.Debug.LiveEdit = LiveEdit; |
| 1123 | 1134 |
| 1124 }) | 1135 }) |
| OLD | NEW |