Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 10 matching lines...) Expand all Loading... | |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Flags: --expose-debug-as debug | 28 // Flags: --expose-debug-as debug |
| 29 // Get the Debug object exposed from the debug context global object. | 29 // Get the Debug object exposed from the debug context global object. |
| 30 | 30 |
| 31 // In this test case we edit a script so that techincally function text | |
| 32 // hasen't been changed. However actually function became one level more nested | |
| 33 // and must be recompiled because it uses variable from outer scope. | |
| 34 | |
| 35 | |
| 36 Debug = debug.Debug | 31 Debug = debug.Debug |
| 37 | 32 |
| 38 var function_z_text = | 33 function Test(old_expression, new_expression) { |
| 39 " function Z() {\n" | 34 eval("var t1 =1;\n" + |
| 40 + " return 2 + p;\n" | 35 "function ChooseAnimal() {\n" + |
| 41 + " }\n"; | 36 " return " + old_expression + ";\n" + |
| 37 "}\n" + | |
| 38 "var t2 =1;\n"); | |
| 42 | 39 |
| 43 eval( | 40 assertEquals("Cat", ChooseAnimal()); |
| 44 "function Factory(p) {\n" | |
| 45 + "return (\n" | |
| 46 + function_z_text | |
| 47 + ");\n" | |
| 48 + "}\n" | |
| 49 ); | |
| 50 | 41 |
| 51 var z6 = Factory(6); | 42 var script = Debug.findScript(ChooseAnimal); |
| 52 assertEquals(8, z6()); | |
| 53 | 43 |
| 54 var script = Debug.findScript(Factory); | 44 var patch_pos = script.source.indexOf(old_expression); |
| 45 var new_animal_patch = new_expression; | |
| 55 | 46 |
| 56 var new_source = script.source.replace(function_z_text, "function Intermediate() {\nreturn (\n" + function_z_text + ")\n;\n}\n"); | 47 var change_log = new Array(); |
| 57 print("new source: " + new_source); | 48 Debug.LiveEdit.TestApi.ApplySingleChunkPatch(script, patch_pos, old_expressi on.length, new_expression, change_log); |
|
Yang
2012/10/23 16:10:31
Please keep the 80-char limit.
Peter Rybin
2012/11/11 03:28:47
Done.
| |
| 49 assertEquals("Capybara", ChooseAnimal()); | |
| 50 } | |
| 58 | 51 |
| 59 var change_log = new Array(); | 52 // Check that old literal boilerplate was reset. |
| 60 var result = Debug.LiveEdit.SetScriptSource(script, new_source, false, change_lo g); | 53 Test("['Cat'][0]", "['Capybara'][0]"); |
| 61 print("Result: " + JSON.stringify(result) + "\n"); | 54 Test("['Cat'][0]", "{a:'Capybara'}.a"); |
| 62 print("Change log: " + JSON.stringify(change_log) + "\n"); | |
| 63 | 55 |
| 64 assertEquals(8, z6()); | 56 // No literals -> 1 literal. |
| 57 Test("'Cat'", "['Capybara'][0]"); | |
| 65 | 58 |
| 66 var z100 = Factory(100)(); | 59 // No literals -> 2 literals. |
| 60 Test("'Cat'", "['Capy'][0] + {a:'bara'}.a"); | |
| 67 | 61 |
| 68 assertEquals(102, z100()); | 62 // 1 literal -> no literals. |
| 63 Test("['Cat'][0]", "'Capybara'"); | |
| 69 | 64 |
| 65 // 2 literals -> no literals. | |
| 66 Test("['Ca'][0] + {a:'t'}.a", "'Capybara'"); | |
| 70 | 67 |
| 68 // No literals -> regexp. | |
| 69 Test("'Cat'", "(/.A.Y.A.A/i).exec('Capybara')[0]"); | |
| 70 | |
| 71 // Array literal -> regexp. | |
| 72 Test("['Cat'][0]", "(/.A.Y.A.A/i).exec('Capybara')[0]"); | |
| 73 | |
| 74 // No literals -> regexp. | |
| 75 Test("(/.A./i).exec('Cat')[0]", "{c:'Capybara'}.c"); | |
|
Yang
2012/10/23 16:10:31
the test for regexp -> no literals seems to be mis
Peter Rybin
2012/11/11 03:28:47
This description was totally misleading anyway. I
| |
| OLD | NEW |