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

Side by Side Diff: src/debug/liveedit.js

Issue 2577063002: Reland of "Store SharedFunctionInfos of a Script in a FixedArray indexed by their ID" (Closed)
Patch Set: fix Created 4 years 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/debug/liveedit.cc ('k') | src/factory.cc » ('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 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
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
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
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;
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 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 } else if (old_children[old_index].status != 661 } else if (old_children[old_index].status !=
652 FunctionStatus.UNCHANGED) { 662 FunctionStatus.UNCHANGED) {
653 ProcessNode(old_children[old_index], 663 ProcessNode(old_children[old_index],
654 new_children[new_index]); 664 new_children[new_index]);
655 if (old_children[old_index].status == FunctionStatus.DAMAGED) { 665 if (old_children[old_index].status == FunctionStatus.DAMAGED) {
656 unmatched_new_nodes_list.push( 666 unmatched_new_nodes_list.push(
657 old_children[old_index].corresponding_node); 667 old_children[old_index].corresponding_node);
658 old_children[old_index].corresponding_node = UNDEFINED; 668 old_children[old_index].corresponding_node = UNDEFINED;
659 old_node.status = FunctionStatus.CHANGED; 669 old_node.status = FunctionStatus.CHANGED;
660 } 670 }
671 } else {
672 ProcessNode(old_children[old_index], new_children[new_index]);
661 } 673 }
662 } else { 674 } else {
663 old_children[old_index].status = FunctionStatus.DAMAGED; 675 old_children[old_index].status = FunctionStatus.DAMAGED;
664 old_children[old_index].status_explanation = 676 old_children[old_index].status_explanation =
665 "No corresponding function in new script found"; 677 "No corresponding function in new script found";
666 old_node.status = FunctionStatus.CHANGED; 678 old_node.status = FunctionStatus.CHANGED;
667 unmatched_new_nodes_list.push(new_children[new_index]); 679 unmatched_new_nodes_list.push(new_children[new_index]);
668 textually_unmatched_new_nodes_list.push(new_children[new_index]); 680 textually_unmatched_new_nodes_list.push(new_children[new_index]);
669 } 681 }
670 new_index++; 682 new_index++;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // An object describing function compilation details. Its index fields 766 // An object describing function compilation details. Its index fields
755 // apply to indexes inside array that stores these objects. 767 // apply to indexes inside array that stores these objects.
756 function FunctionCompileInfo(raw_array) { 768 function FunctionCompileInfo(raw_array) {
757 this.function_name = raw_array[0]; 769 this.function_name = raw_array[0];
758 this.start_position = raw_array[1]; 770 this.start_position = raw_array[1];
759 this.end_position = raw_array[2]; 771 this.end_position = raw_array[2];
760 this.param_num = raw_array[3]; 772 this.param_num = raw_array[3];
761 this.scope_info = raw_array[4]; 773 this.scope_info = raw_array[4];
762 this.outer_index = raw_array[5]; 774 this.outer_index = raw_array[5];
763 this.shared_function_info = raw_array[6]; 775 this.shared_function_info = raw_array[6];
776 this.function_literal_id = raw_array[8];
764 this.next_sibling_index = null; 777 this.next_sibling_index = null;
765 this.raw_array = raw_array; 778 this.raw_array = raw_array;
766 } 779 }
767 780
768 function SharedInfoWrapper(raw_array) { 781 function SharedInfoWrapper(raw_array) {
769 this.function_name = raw_array[0]; 782 this.function_name = raw_array[0];
770 this.start_position = raw_array[1]; 783 this.start_position = raw_array[1];
771 this.end_position = raw_array[2]; 784 this.end_position = raw_array[2];
772 this.info = raw_array[3]; 785 this.info = raw_array[3];
773 this.raw_array = raw_array; 786 this.raw_array = raw_array;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 1044
1032 LiveEdit.TestApi = { 1045 LiveEdit.TestApi = {
1033 PosTranslator: PosTranslator, 1046 PosTranslator: PosTranslator,
1034 CompareStrings: CompareStrings, 1047 CompareStrings: CompareStrings,
1035 ApplySingleChunkPatch: ApplySingleChunkPatch 1048 ApplySingleChunkPatch: ApplySingleChunkPatch
1036 }; 1049 };
1037 1050
1038 global.Debug.LiveEdit = LiveEdit; 1051 global.Debug.LiveEdit = LiveEdit;
1039 1052
1040 }) 1053 })
OLDNEW
« no previous file with comments | « src/debug/liveedit.cc ('k') | src/factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698