| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 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 Debug = debug.Debug | 30 Debug = debug.Debug; |
| 31 | 31 |
| 32 var exception = false; // Exception in debug event listener. | 32 var exception = false; // Exception in debug event listener. |
| 33 var before_compile_count = 0; | 33 var before_compile_count = 0; |
| 34 var after_compile_count = 0; | 34 var after_compile_count = 0; |
| 35 var current_source = ''; // Current source being compiled. | 35 var current_source = ''; // Current source being compiled. |
| 36 var source_count = 0; // Total number of scources compiled. | 36 var source_count = 0; // Total number of scources compiled. |
| 37 var host_compilations = 0; // Number of scources compiled through the API. | 37 var host_compilations = 0; // Number of scources compiled through the API. |
| 38 var eval_compilations = 0; // Number of scources compiled through eval. | 38 var eval_compilations = 0; // Number of scources compiled through eval. |
| 39 | 39 |
| 40 | 40 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 var json = event_data.toJSONProtocol(); | 79 var json = event_data.toJSONProtocol(); |
| 80 var msg = eval('(' + json + ')'); | 80 var msg = eval('(' + json + ')'); |
| 81 assertTrue('context' in msg.body.script); | 81 assertTrue('context' in msg.body.script); |
| 82 | 82 |
| 83 // Check that we pick script name from //@ sourceURL, iff present | 83 // Check that we pick script name from //@ sourceURL, iff present |
| 84 assertEquals(current_source.indexOf('sourceURL') >= 0 ? | 84 assertEquals(current_source.indexOf('sourceURL') >= 0 ? |
| 85 'myscript.js' : undefined, | 85 'myscript.js' : undefined, |
| 86 event_data.script().name()); | 86 event_data.script().name()); |
| 87 } | 87 } |
| 88 } catch (e) { | 88 } catch (e) { |
| 89 exception = e | 89 exception = e; |
| 90 } | 90 } |
| 91 }; | 91 } |
| 92 | 92 |
| 93 | 93 |
| 94 // Add the debug event listener. | 94 // Add the debug event listener. |
| 95 Debug.setListener(listener); | 95 Debug.setListener(listener); |
| 96 | 96 |
| 97 // Compile different sources. | 97 // Compile different sources. |
| 98 compileSource('a=1'); | 98 compileSource('a=1'); |
| 99 compileSource('(function(){})'); | 99 compileSource('(function(){})'); |
| 100 compileSource('eval("a=2")'); | 100 compileSource('eval("a=2")'); |
| 101 source_count++; // Using eval causes additional compilation event. | 101 source_count++; // Using eval causes additional compilation event. |
| 102 compileSource('eval("eval(\'(function(){return a;})\')")'); | 102 compileSource('eval("eval(\'(function(){return a;})\')")'); |
| 103 source_count += 2; // Using eval causes additional compilation event. | 103 source_count += 2; // Using eval causes additional compilation event. |
| 104 compileSource('JSON.parse(\'{"a":1,"b":2}\')'); | 104 compileSource('JSON.parse(\'{"a":1,"b":2}\')'); |
| 105 // Using JSON.parse does not causes additional compilation events. | 105 // Using JSON.parse does not causes additional compilation events. |
| 106 compileSource('x=1; //@ sourceURL=myscript.js'); | 106 compileSource('x=1; //@ sourceURL=myscript.js'); |
| 107 | 107 |
| 108 // Make sure that the debug event listener was invoked. | 108 // Make sure that the debug event listener was invoked. |
| 109 assertFalse(exception, "exception in listener") | 109 assertFalse(exception, "exception in listener"); |
| 110 | 110 |
| 111 // Number of before and after compile events should be the same. | 111 // Number of before and after compile events should be the same. |
| 112 assertEquals(before_compile_count, after_compile_count); | 112 assertEquals(before_compile_count, after_compile_count); |
| 113 | 113 |
| 114 // Check the actual number of events (no compilation through the API as all | 114 // Check the actual number of events (no compilation through the API as all |
| 115 // source compiled through eval). | 115 // source compiled through eval). |
| 116 assertEquals(source_count, after_compile_count); | 116 assertEquals(source_count, after_compile_count); |
| 117 assertEquals(0, host_compilations); | 117 assertEquals(0, host_compilations); |
| 118 assertEquals(source_count, eval_compilations); | 118 assertEquals(source_count, eval_compilations); |
| 119 | 119 |
| 120 Debug.setListener(null); | 120 Debug.setListener(null); |
| OLD | NEW |