Index: test/mjsunit/debug-liveedit-2.js |
diff --git a/test/mjsunit/debug-liveedit-2.js b/test/mjsunit/debug-liveedit-2.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..70ff5a6b8e8b062cf7929f7ebbd4bdc463242045 |
--- /dev/null |
+++ b/test/mjsunit/debug-liveedit-2.js |
@@ -0,0 +1,39 @@ |
+// Flags: --expose-debug-as debug |
+// Get the Debug object exposed from the debug context global object. |
+ |
+Debug = debug.Debug |
+ |
+eval( |
+ "function ChooseAnimal(p) { " + |
+ " if (p == 7) {" + // Use p |
+ " return;" + |
+ " }" + |
+ " return function Chooser() {" + |
+ " return 'Cat';" + |
+ " };" + |
+ "}" |
+); |
+ |
+var old_closure = ChooseAnimal(19); |
+ |
+assertEquals("Cat", old_closure()); |
+ |
+var script = Debug.findScript(ChooseAnimal); |
+ |
+var orig_animal = "'Cat'"; |
+var patch_pos = script.source.indexOf(orig_animal); |
+var new_animal_patch = "'Capybara' + p"; |
+ |
+// We patch innermost function "Chooser". |
+// However, this does not actually patch existing "Chooser" instances, |
+// because old value of parameter "p" was not saved. |
+// Instead it patches ChooseAnimal. |
+Debug.change_script_live(script, patch_pos, orig_animal.length, new_animal_patch); |
+ |
+var new_closure = ChooseAnimal(19); |
+// New instance of closure is patched. |
+assertEquals("Capybara19", new_closure()); |
+ |
+// Old instance of closure is not patched. |
+assertEquals("Cat", old_closure()); |
+ |