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

Side by Side Diff: src/liveedit-debugger.js

Issue 1652008: LiveEdit: calculate a real script difference (Closed)
Patch Set: static assert Created 10 years, 8 months 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/liveedit.cc ('k') | src/runtime.h » ('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 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 18 matching lines...) Expand all
29 // debug-debugger.js. 29 // debug-debugger.js.
30 30
31 // A LiveEdit namespace is declared inside a single function constructor. 31 // A LiveEdit namespace is declared inside a single function constructor.
32 Debug.LiveEdit = new function() { 32 Debug.LiveEdit = new function() {
33 33
34 // Changes script text and recompiles all relevant functions if possible. 34 // Changes script text and recompiles all relevant functions if possible.
35 // The change is always a substring (change_pos, change_pos + change_len) 35 // The change is always a substring (change_pos, change_pos + change_len)
36 // being replaced with a completely different string new_str. 36 // being replaced with a completely different string new_str.
37 // 37 //
38 // Only one function will have its Code changed in result of this function. 38 // Only one function will have its Code changed in result of this function.
39 // All nested functions (should they have any instances at the moment) are lef t 39 // All nested functions (should they have any instances at the moment) are
40 // unchanged and re-linked to a newly created script instance representing old 40 // left unchanged and re-linked to a newly created script instance
41 // version of the source. (Generally speaking, 41 // representing old version of the source. (Generally speaking,
42 // during the change all nested functions are erased and completely different 42 // during the change all nested functions are erased and completely different
43 // set of nested functions are introduced.) All other functions just have 43 // set of nested functions are introduced.) All other functions just have
44 // their positions updated. 44 // their positions updated.
45 // 45 //
46 // @param {Script} script that is being changed 46 // @param {Script} script that is being changed
47 // @param {Array} change_log a list that collects engineer-readable descriptio n 47 // @param {Array} change_log a list that collects engineer-readable
48 // of what happened. 48 // description of what happened.
49 function ApplyPatch(script, change_pos, change_len, new_str, 49 function ApplyPatch(script, change_pos, change_len, new_str,
50 change_log) { 50 change_log) {
51 51
52 // Fully compiles source string as a script. Returns Array of 52 // Fully compiles source string as a script. Returns Array of
53 // FunctionCompileInfo -- a descriptions of all functions of the script. 53 // FunctionCompileInfo -- a descriptions of all functions of the script.
54 // Elements of array are ordered by start positions of functions (from top 54 // Elements of array are ordered by start positions of functions (from top
55 // to bottom) in the source. Fields outer_index and next_sibling_index help 55 // to bottom) in the source. Fields outer_index and next_sibling_index help
56 // to navigate the nesting structure of functions. 56 // to navigate the nesting structure of functions.
57 // 57 //
58 // The script is used for compilation, because it produces code that 58 // The script is used for compilation, because it produces code that
59 // needs to be linked with some particular script (for nested functions). 59 // needs to be linked with some particular script (for nested functions).
60 function DebugGatherCompileInfo(source) { 60 function DebugGatherCompileInfo(source) {
61 // Get function info, elements are partially sorted (it is a tree 61 // Get function info, elements are partially sorted (it is a tree of
62 // of nested functions serialized as parent followed by serialized childre n. 62 // nested functions serialized as parent followed by serialized children.
63 var raw_compile_info = %LiveEditGatherCompileInfo(script, source); 63 var raw_compile_info = %LiveEditGatherCompileInfo(script, source);
64 64
65 // Sort function infos by start position field. 65 // Sort function infos by start position field.
66 var compile_info = new Array(); 66 var compile_info = new Array();
67 var old_index_map = new Array(); 67 var old_index_map = new Array();
68 for (var i = 0; i < raw_compile_info.length; i++) { 68 for (var i = 0; i < raw_compile_info.length; i++) {
69 compile_info.push(new FunctionCompileInfo(raw_compile_info[i])); 69 compile_info.push(new FunctionCompileInfo(raw_compile_info[i]));
70 old_index_map.push(i); 70 old_index_map.push(i);
71 } 71 }
72 72
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 compile_info[previous_sibling].next_sibling_index = -1; 110 compile_info[previous_sibling].next_sibling_index = -1;
111 } 111 }
112 } 112 }
113 113
114 ResetIndexes(-1, -1); 114 ResetIndexes(-1, -1);
115 Assert(current_index == compile_info.length); 115 Assert(current_index == compile_info.length);
116 116
117 return compile_info; 117 return compile_info;
118 } 118 }
119 119
120 // Given a positions, finds a function that fully includes the entire change . 120 // Given a positions, finds a function that fully includes the entire
121 // change.
121 function FindChangedFunction(compile_info, offset, len) { 122 function FindChangedFunction(compile_info, offset, len) {
122 // First condition: function should start before the change region. 123 // First condition: function should start before the change region.
123 // Function #0 (whole-script function) always does, but we want 124 // Function #0 (whole-script function) always does, but we want
124 // one, that is later in this list. 125 // one, that is later in this list.
125 var index = 0; 126 var index = 0;
126 while (index + 1 < compile_info.length && 127 while (index + 1 < compile_info.length &&
127 compile_info[index + 1].start_position <= offset) { 128 compile_info[index + 1].start_position <= offset) {
128 index++; 129 index++;
129 } 130 }
130 // Now we are at the last function that begins before the change 131 // Now we are at the last function that begins before the change
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Check that function being patched is not currently on stack. 263 // Check that function being patched is not currently on stack.
263 CheckStackActivations( 264 CheckStackActivations(
264 [ FindFunctionInfo(function_being_patched) ], change_log ); 265 [ FindFunctionInfo(function_being_patched) ], change_log );
265 266
266 267
267 // Committing all changes. 268 // Committing all changes.
268 var old_script_name = CreateNameForOldScript(script); 269 var old_script_name = CreateNameForOldScript(script);
269 270
270 // Update the script text and create a new script representing an old 271 // Update the script text and create a new script representing an old
271 // version of the script. 272 // version of the script.
272 var old_script = %LiveEditReplaceScript(script, new_source, old_script_name) ; 273 var old_script = %LiveEditReplaceScript(script, new_source,
274 old_script_name);
273 275
274 PatchCode(new_compile_info[function_being_patched], 276 PatchCode(new_compile_info[function_being_patched],
275 FindFunctionInfo(function_being_patched)); 277 FindFunctionInfo(function_being_patched));
276 278
277 var position_patch_report = new Array(); 279 var position_patch_report = new Array();
278 change_log.push( {position_patched: position_patch_report} ); 280 change_log.push( {position_patched: position_patch_report} );
279 281
280 var position_change_array = [ change_pos, 282 var position_change_array = [ change_pos,
281 change_pos + change_len_old, 283 change_pos + change_len_old,
282 change_pos + change_len_new ]; 284 change_pos + change_len_new ];
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 var diff = FindSimpleDiff(old_source, new_source); 472 var diff = FindSimpleDiff(old_source, new_source);
471 if (!diff) { 473 if (!diff) {
472 return; 474 return;
473 } 475 }
474 ApplyPatch(script, diff.change_pos, diff.old_len, 476 ApplyPatch(script, diff.change_pos, diff.old_len,
475 new_source.substring(diff.change_pos, diff.change_pos + diff.new_len), 477 new_source.substring(diff.change_pos, diff.change_pos + diff.new_len),
476 change_log); 478 change_log);
477 } 479 }
478 // Function is public. 480 // Function is public.
479 this.SetScriptSource = SetScriptSource; 481 this.SetScriptSource = SetScriptSource;
482
483 function CompareStringsLinewise(s1, s2) {
484 return %LiveEditCompareStringsLinewise(s1, s2);
485 }
486 // Function is public (for tests).
487 this.CompareStringsLinewise = CompareStringsLinewise;
480 488
481 489
482 // Finds a difference between 2 strings in form of a single chunk. 490 // Finds a difference between 2 strings in form of a single chunk.
483 // This is a temporary solution. We should calculate a read diff instead. 491 // This is a temporary solution. We should calculate a read diff instead.
484 function FindSimpleDiff(old_source, new_source) { 492 function FindSimpleDiff(old_source, new_source) {
485 var change_pos; 493 var change_pos;
486 var old_len; 494 var old_len;
487 var new_len; 495 var new_len;
488 496
489 // A find range block. Whenever control leaves it, it should set 3 local 497 // A find range block. Whenever control leaves it, it should set 3 local
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 544 }
537 545
538 if (old_len == 0 && new_len == 0) { 546 if (old_len == 0 && new_len == 0) {
539 // no change 547 // no change
540 return; 548 return;
541 } 549 }
542 550
543 return { "change_pos": change_pos, "old_len": old_len, "new_len": new_len }; 551 return { "change_pos": change_pos, "old_len": old_len, "new_len": new_len };
544 } 552 }
545 } 553 }
OLDNEW
« no previous file with comments | « src/liveedit.cc ('k') | src/runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698