OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 // Flags: --expose-debug-as debug |
| 29 // Get the Debug object exposed from the debug context global object. |
| 30 |
| 31 // Scenario: some function is being edited; the outer function has to have its |
| 32 // positions patched. Accoring to a special markup of function text |
| 33 // corresponding byte-code PCs should conicide before change and after it. |
| 34 |
| 35 Debug = debug.Debug |
| 36 |
| 37 eval( |
| 38 "function F1() { return 5; }\n" + |
| 39 "function ChooseAnimal(/*$*/ ) {\n" + |
| 40 "/*$*/ var x = F1(/*$*/ );\n" + |
| 41 "/*$*/ var res/*$*/ =/*$*/ (function() { return 'Cat'; } )();\n" + |
| 42 "/*$*/ var y/*$*/ = F2(/*$*/ F1()/*$*/ , F1(/*$*/ )/*$*/ );\n" + |
| 43 "/*$*/ if (/*$*/ x.toString(/*$*/ )) { /*$*/ y = 3;/*$*/ } else {/*$*/ y =
8;/*$*/ }\n" + |
| 44 "/*$*/ var z = /*$*/ x * y;\n" + |
| 45 "/*$*/ return/*$*/ res/*$*/ + z;/*$*/ }\n" + |
| 46 "function F2(x, y) { return x + y; }" |
| 47 ); |
| 48 |
| 49 // Find all *$* markers in text of the function and read corresponding statement |
| 50 // PCs. |
| 51 function ReadMarkerPositions(func) { |
| 52 var text = func.toString(); |
| 53 var positions = new Array(); |
| 54 var match; |
| 55 var pattern = /\/\*\$\*\//g; |
| 56 while ((match = pattern.exec(text)) != null) { |
| 57 positions.push(match.index); |
| 58 } |
| 59 return positions; |
| 60 } |
| 61 |
| 62 function ReadPCMap(func, positions) { |
| 63 var res = new Array(); |
| 64 for (var i = 0; i < positions.length; i++) { |
| 65 res.push(Debug.LiveEditChangeScript.GetPcFromSourcePos(func, positions[i])); |
| 66 } |
| 67 return res; |
| 68 } |
| 69 |
| 70 var res = ChooseAnimal(); |
| 71 assertEquals("Cat15", res); |
| 72 |
| 73 var markerPositionsBefore = ReadMarkerPositions(ChooseAnimal); |
| 74 var pcArrayBefore = ReadPCMap(ChooseAnimal, markerPositionsBefore); |
| 75 |
| 76 var script = Debug.findScript(ChooseAnimal); |
| 77 |
| 78 var orig_animal = "'Cat'"; |
| 79 var patch_pos = script.source.indexOf(orig_animal); |
| 80 var new_animal_patch = "'Capybara'"; |
| 81 |
| 82 var change_log = new Array(); |
| 83 Debug.LiveEditChangeScript(script, patch_pos, orig_animal.length, new_animal_pat
ch, change_log); |
| 84 print("Change log: " + JSON.stringify(change_log) + "\n"); |
| 85 |
| 86 var res = ChooseAnimal(); |
| 87 assertEquals("Capybara15", res); |
| 88 |
| 89 var markerPositionsAfter = ReadMarkerPositions(ChooseAnimal); |
| 90 var pcArrayAfter = ReadPCMap(ChooseAnimal, markerPositionsAfter); |
| 91 |
| 92 assertArrayEquals(pcArrayBefore, pcArrayAfter); |
| 93 |
OLD | NEW |