Revision: 4419
Author: [email protected]
Date: Wed Apr 14 07:53:00 2010
Log: Make a namespace for LiveEdit

Review URL: http://codereview.chromium.org/1549041
http://code.google.com/p/v8/source/detail?r=4419

Modified:
 /branches/bleeding_edge/src/debug-debugger.js
 /branches/bleeding_edge/src/liveedit-debugger.js
 /branches/bleeding_edge/test/mjsunit/debug-liveedit-1.js
 /branches/bleeding_edge/test/mjsunit/debug-liveedit-2.js
 /branches/bleeding_edge/test/mjsunit/debug-liveedit-check-stack.js
/branches/bleeding_edge/test/mjsunit/debug-liveedit-patch-positions-replace.js
 /branches/bleeding_edge/test/mjsunit/debug-liveedit-patch-positions.js

=======================================
--- /branches/bleeding_edge/src/debug-debugger.js       Thu Apr  8 05:37:10 2010
+++ /branches/bleeding_edge/src/debug-debugger.js       Wed Apr 14 07:53:00 2010
@@ -1970,7 +1970,7 @@


DebugCommandProcessor.prototype.changeLiveRequest_ = function(request, response) {
-  if (!Debug.LiveEditChangeScript) {
+  if (!Debug.LiveEdit) {
     return response.failed('LiveEdit feature is not supported');
   }
   if (!request.arguments) {
@@ -2010,7 +2010,7 @@
       return;
     }
     invocation = function() {
-      return Debug.LiveEditChangeScript(the_script, change_pos, change_len,
+      return Debug.LiveEdit.ApplyPatch(the_script, change_pos, change_len,
           new_string, change_log);
     }
   }
@@ -2018,7 +2018,7 @@
   try {
     invocation();
   } catch (e) {
-    if (e instanceof Debug.LiveEditChangeScript.Failure) {
+    if (e instanceof Debug.LiveEdit.Failure) {
       // Let's treat it as a "success" so that body with change_log will be
       // sent back. "change_log" will have "failure" field set.
       change_log.push( { failure: true, message: e.toString() } );
=======================================
--- /branches/bleeding_edge/src/liveedit-debugger.js Thu Apr 8 05:37:10 2010 +++ /branches/bleeding_edge/src/liveedit-debugger.js Wed Apr 14 07:53:00 2010
@@ -28,6 +28,10 @@
 // LiveEdit feature implementation. The script should be executed after
 // debug-debugger.js.

+// A LiveEdit namespace is declared inside a single function constructor.
+Debug.LiveEdit = new function() {
+
+// TODO(LiveEdit): restore indentation below

 // Changes script text and recompiles all relevant functions if possible.
 // The change is always a substring (change_pos, change_pos + change_len)
@@ -44,13 +48,9 @@
 // @param {Script} script that is being changed
// @param {Array} change_log a list that collects engineer-readable description
 //     of what happened.
-Debug.LiveEditChangeScript = function(script, change_pos, change_len, new_str,
+function ApplyPatch(script, change_pos, change_len, new_str,
     change_log) {

-  // So far the function works as namespace.
-  var liveedit = Debug.LiveEditChangeScript;
-  var Assert = liveedit.Assert;
-
   // Fully compiles source string as a script. Returns Array of
   // FunctionCompileInfo -- a descriptions of all functions of the script.
// Elements of array are ordered by start positions of functions (from top
@@ -68,7 +68,7 @@
     var compile_info = new Array();
     var old_index_map = new Array();
     for (var i = 0; i < raw_compile_info.length; i++) {
- compile_info.push(new liveedit.FunctionCompileInfo(raw_compile_info[i]));
+        compile_info.push(new FunctionCompileInfo(raw_compile_info[i]));
         old_index_map.push(i);
     }

@@ -222,7 +222,7 @@
   var shared_infos = new Array();

   for (var i = 0; i < shared_raw_list.length; i++) {
-    shared_infos.push(new liveedit.SharedInfoWrapper(shared_raw_list[i]));
+    shared_infos.push(new SharedInfoWrapper(shared_raw_list[i]));
   }

   // Gather compile information about old version of script.
@@ -233,7 +233,7 @@
   try {
     new_compile_info = DebugGatherCompileInfo(new_source);
   } catch (e) {
- throw new liveedit.Failure("Failed to compile new version of script: " + e);
+    throw new Failure("Failed to compile new version of script: " + e);
   }

// An index of a single function, that is going to have its code replaced.
@@ -250,7 +250,7 @@
   // Check that function being patched has the same expectations in a new
   // version. Otherwise we cannot safely patch its behavior and should
   // choose the outer function instead.
-  while (!liveedit.CompareFunctionExpectations(
+  while (!CompareFunctionExpectations(
       old_compile_info[function_being_patched],
       new_compile_info[function_being_patched])) {

@@ -262,12 +262,12 @@
   }

   // Check that function being patched is not currently on stack.
-  liveedit.CheckStackActivations(
+  CheckStackActivations(
       [ FindFunctionInfo(function_being_patched) ], change_log );


   // Committing all changes.
-  var old_script_name = liveedit.CreateNameForOldScript(script);
+  var old_script_name = CreateNameForOldScript(script);

   // Update the script text and create a new script representing an old
   // version of the script.
@@ -320,8 +320,10 @@
     LinkToOldScript(FindFunctionInfo(i), old_script);
   }
 }
-
-Debug.LiveEditChangeScript.Assert = function(condition, message) {
+// Function is public.
+this.ApplyPatch = ApplyPatch;
+
+function Assert(condition, message) {
   if (!condition) {
     if (message) {
       throw "Assert " + message;
@@ -333,7 +335,7 @@

 // An object describing function compilation details. Its index fields
 // apply to indexes inside array that stores these objects.
-Debug.LiveEditChangeScript.FunctionCompileInfo = function(raw_array) {
+function FunctionCompileInfo(raw_array) {
   this.function_name = raw_array[0];
   this.start_position = raw_array[1];
   this.end_position = raw_array[2];
@@ -345,8 +347,7 @@
   this.raw_array = raw_array;
 }

-// A structure describing SharedFunctionInfo.
-Debug.LiveEditChangeScript.SharedInfoWrapper = function(raw_array) {
+function SharedInfoWrapper(raw_array) {
   this.function_name = raw_array[0];
   this.start_position = raw_array[1];
   this.end_position = raw_array[2];
@@ -355,15 +356,14 @@
 }

 // Adds a suffix to script name to mark that it is old version.
-Debug.LiveEditChangeScript.CreateNameForOldScript = function(script) {
+function CreateNameForOldScript(script) {
   // TODO(635): try better than this; support several changes.
   return script.name + " (old)";
 }

 // Compares a function interface old and new version, whether it
 // changed or not.
-Debug.LiveEditChangeScript.CompareFunctionExpectations =
-    function(function_info1, function_info2) {
+function CompareFunctionExpectations(function_info1, function_info2) {
   // Check that function has the same number of parameters (there may exist
   // an adapter, that won't survive function parameter number change).
   if (function_info1.param_num != function_info2.param_num) {
@@ -384,14 +384,14 @@
   // will not properly work with existing scopes.
   return scope_info1.toString() == scope_info2.toString();
 }
+
+// Minifier forward declaration.
+var FunctionPatchabilityStatus;

 // For array of wrapped shared function infos checks that none of them
 // have activations on stack (of any thread). Throws a Failure exception
 // if this proves to be false.
-Debug.LiveEditChangeScript.CheckStackActivations = function(shared_wrapper_list,
-                                                            change_log) {
-  var liveedit = Debug.LiveEditChangeScript;
-
+function CheckStackActivations(shared_wrapper_list, change_log) {
   var shared_list = new Array();
   for (var i = 0; i < shared_wrapper_list.length; i++) {
     shared_list[i] = shared_wrapper_list[i].info;
@@ -399,22 +399,22 @@
   var result = %LiveEditCheckAndDropActivations(shared_list, true);
   if (result[shared_list.length]) {
     // Extra array element may contain error message.
-    throw new liveedit.Failure(result[shared_list.length]);
-  }
-
+    throw new Failure(result[shared_list.length]);
+  }
+
   var problems = new Array();
   var dropped = new Array();
   for (var i = 0; i < shared_list.length; i++) {
     var shared = shared_wrapper_list[i];
- if (result[i] == liveedit.FunctionPatchabilityStatus.REPLACED_ON_ACTIVE_STACK) {
+    if (result[i] == FunctionPatchabilityStatus.REPLACED_ON_ACTIVE_STACK) {
       dropped.push({ name: shared.function_name } );
- } else if (result[i] != liveedit.FunctionPatchabilityStatus.AVAILABLE_FOR_PATCH) { + } else if (result[i] != FunctionPatchabilityStatus.AVAILABLE_FOR_PATCH) {
       var description = {
           name: shared.function_name,
           start_pos: shared.start_position,
           end_pos: shared.end_position,
           replace_problem:
-              liveedit.FunctionPatchabilityStatus.SymbolName(result[i])
+              FunctionPatchabilityStatus.SymbolName(result[i])
       };
       problems.push(description);
     }
@@ -424,12 +424,12 @@
   }
   if (problems.length > 0) {
     change_log.push( { functions_on_stack: problems } );
-    throw new liveedit.Failure("Blocked by functions on stack");
+    throw new Failure("Blocked by functions on stack");
   }
 }

 // A copy of the FunctionPatchabilityStatus enum from liveedit.h
-Debug.LiveEditChangeScript.FunctionPatchabilityStatus = {
+var FunctionPatchabilityStatus = {
     AVAILABLE_FOR_PATCH: 1,
     BLOCKED_ON_ACTIVE_STACK: 2,
     BLOCKED_ON_OTHER_STACK: 3,
@@ -437,9 +437,8 @@
     REPLACED_ON_ACTIVE_STACK: 5
 }

-Debug.LiveEditChangeScript.FunctionPatchabilityStatus.SymbolName =
-    function(code) {
-  var enum = Debug.LiveEditChangeScript.FunctionPatchabilityStatus;
+FunctionPatchabilityStatus.SymbolName = function(code) {
+  var enum = FunctionPatchabilityStatus;
   for (name in enum) {
     if (enum[name] == code) {
       return name;
@@ -450,35 +449,38 @@

 // A logical failure in liveedit process. This means that change_log
 // is valid and consistent description of what happened.
-Debug.LiveEditChangeScript.Failure = function(message) {
+function Failure(message) {
   this.message = message;
 }
-
-Debug.LiveEditChangeScript.Failure.prototype.toString = function() {
+// Function (constructor) is public.
+this.Failure = Failure;
+
+Failure.prototype.toString = function() {
   return "LiveEdit Failure: " + this.message;
 }

 // A testing entry.
-Debug.LiveEditChangeScript.GetPcFromSourcePos = function(func, source_pos) {
+function GetPcFromSourcePos(func, source_pos) {
   return %GetFunctionCodePositionFromSource(func, source_pos);
 }
-
-// A LiveEdit namespace is declared inside a single function constructor.
-Debug.LiveEdit = new function() {
-  var LiveEdit = this;
-
+// Function is public.
+this.GetPcFromSourcePos = GetPcFromSourcePos;
+
+// TODO(LiveEdit): restore indentation above

   // LiveEdit main entry point: changes a script text to a new string.
-  LiveEdit.SetScriptSource = function(script, new_source, change_log) {
+  function SetScriptSource(script, new_source, change_log) {
     var old_source = script.source;
     var diff = FindSimpleDiff(old_source, new_source);
     if (!diff) {
       return;
     }
-    Debug.LiveEditChangeScript(script, diff.change_pos, diff.old_len,
+    ApplyPatch(script, diff.change_pos, diff.old_len,
new_source.substring(diff.change_pos, diff.change_pos + diff.new_len),
         change_log);
   }
+  // Function is public.
+  this.SetScriptSource = SetScriptSource;


   // Finds a difference between 2 strings in form of a single chunk.
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-liveedit-1.js Fri Mar 5 14:08:58 2010 +++ /branches/bleeding_edge/test/mjsunit/debug-liveedit-1.js Wed Apr 14 07:53:00 2010
@@ -43,6 +43,6 @@
 var new_animal_patch = "Cap' + 'y' + 'bara";

 var change_log = new Array();
-Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_animal_patch, change_log); +Debug.LiveEdit.ApplyPatch(script, patch_pos, orig_animal.length, new_animal_patch, change_log);

 assertEquals("Capybara", ChooseAnimal());
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-liveedit-2.js Fri Mar 5 14:08:58 2010 +++ /branches/bleeding_edge/test/mjsunit/debug-liveedit-2.js Wed Apr 14 07:53:00 2010
@@ -58,7 +58,7 @@
 // because old value of parameter "p" was not saved.
 // Instead it patches ChooseAnimal.
 var change_log = new Array();
-Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_animal_patch, change_log); +Debug.LiveEdit.ApplyPatch(script, patch_pos, orig_animal.length, new_animal_patch, change_log);
 print("Change log: " + JSON.stringify(change_log) + "\n");

 var new_closure = ChooseAnimal(19);
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-liveedit-check-stack.js Tue Apr 6 10:58:28 2010 +++ /branches/bleeding_edge/test/mjsunit/debug-liveedit-check-stack.js Wed Apr 14 07:53:00 2010
@@ -60,7 +60,7 @@
     // Runs in debugger context.
     var change_log = new Array();
     try {
- Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_animal_patch, change_log); + Debug.LiveEdit.ApplyPatch(script, patch_pos, orig_animal.length, new_animal_patch, change_log);
     } finally {
       print("Change log: " + JSON.stringify(change_log) + "\n");
     }
@@ -76,7 +76,7 @@
     try {
       f();
     } catch (e) {
-      if (e instanceof Debug.LiveEditChangeScript.Failure) {
+      if (e instanceof Debug.LiveEdit.Failure) {
         holder[0] = e;
       } else {
         throw e;
=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-liveedit-patch-positions-replace.js Mon Mar 15 14:06:51 2010 +++ /branches/bleeding_edge/test/mjsunit/debug-liveedit-patch-positions-replace.js Wed Apr 14 07:53:00 2010
@@ -59,7 +59,7 @@

 var change_log = new Array();
 function Changer() {
- Debug.LiveEditChangeScript(script, patch_pos, orig_body.length, new_body_patch, change_log); + Debug.LiveEdit.ApplyPatch(script, patch_pos, orig_body.length, new_body_patch, change_log);
   print("Change log: " + JSON.stringify(change_log) + "\n");
 }

=======================================
--- /branches/bleeding_edge/test/mjsunit/debug-liveedit-patch-positions.js Mon Mar 15 14:06:51 2010 +++ /branches/bleeding_edge/test/mjsunit/debug-liveedit-patch-positions.js Wed Apr 14 07:53:00 2010
@@ -62,7 +62,7 @@
 function ReadPCMap(func, positions) {
   var res = new Array();
   for (var i = 0; i < positions.length; i++) {
- res.push(Debug.LiveEditChangeScript.GetPcFromSourcePos(func, positions[i]));
+    res.push(Debug.LiveEdit.GetPcFromSourcePos(func, positions[i]));
   }
   return res;
 }
@@ -80,7 +80,7 @@
 var new_animal_patch = "'Capybara'";

 var change_log = new Array();
-Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_animal_patch, change_log); +Debug.LiveEdit.ApplyPatch(script, patch_pos, orig_animal.length, new_animal_patch, change_log);
 print("Change log: " + JSON.stringify(change_log) + "\n");

 var res = ChooseAnimal();

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to