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 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 assertTrue(current_source.indexOf(s) >= 0); | 83 assertTrue(current_source.indexOf(s) >= 0); |
84 } else { | 84 } else { |
85 // For source without 'eval' there will be a compile events with the | 85 // For source without 'eval' there will be a compile events with the |
86 // exact source. | 86 // exact source. |
87 assertEquals(current_source, event_data.script().source()); | 87 assertEquals(current_source, event_data.script().source()); |
88 } | 88 } |
89 // Check that script context is included into the event message. | 89 // Check that script context is included into the event message. |
90 var json = event_data.toJSONProtocol(); | 90 var json = event_data.toJSONProtocol(); |
91 var msg = eval('(' + json + ')'); | 91 var msg = eval('(' + json + ')'); |
92 assertTrue('context' in msg.body.script); | 92 assertTrue('context' in msg.body.script); |
| 93 |
| 94 // Check that we pick script name from //@ sourceURL, iff present |
| 95 assertEquals(current_source.indexOf('sourceURL') >= 0 ? |
| 96 'myscript.js' : undefined, |
| 97 event_data.script().name()); |
93 } | 98 } |
94 } catch (e) { | 99 } catch (e) { |
95 exception = e | 100 exception = e |
96 } | 101 } |
97 }; | 102 }; |
98 | 103 |
99 | 104 |
100 // Add the debug event listener. | 105 // Add the debug event listener. |
101 Debug.setListener(listener); | 106 Debug.setListener(listener); |
102 | 107 |
103 // Compile different sources. | 108 // Compile different sources. |
104 compileSource('a=1'); | 109 compileSource('a=1'); |
105 compileSource('(function(){})'); | 110 compileSource('(function(){})'); |
106 compileSource('eval("a=2")'); | 111 compileSource('eval("a=2")'); |
107 source_count++; // Using eval causes additional compilation event. | 112 source_count++; // Using eval causes additional compilation event. |
108 compileSource('eval("eval(\'(function(){return a;})\')")'); | 113 compileSource('eval("eval(\'(function(){return a;})\')")'); |
109 source_count += 2; // Using eval causes additional compilation event. | 114 source_count += 2; // Using eval causes additional compilation event. |
110 compileSource('JSON.parse(\'{"a":1,"b":2}\')'); | 115 compileSource('JSON.parse(\'{"a":1,"b":2}\')'); |
111 source_count++; // Using JSON.parse causes additional compilation event. | 116 source_count++; // Using JSON.parse causes additional compilation event. |
| 117 compileSource('x=1; //@ sourceURL=myscript.js'); |
112 | 118 |
113 // Make sure that the debug event listener was invoked. | 119 // Make sure that the debug event listener was invoked. |
114 assertFalse(exception, "exception in listener") | 120 assertFalse(exception, "exception in listener") |
115 | 121 |
116 // Number of before and after compile events should be the same. | 122 // Number of before and after compile events should be the same. |
117 assertEquals(before_compile_count, after_compile_count); | 123 assertEquals(before_compile_count, after_compile_count); |
118 | 124 |
119 // Check the actual number of events (no compilation through the API as all | 125 // Check the actual number of events (no compilation through the API as all |
120 // source compiled through eval except for one JSON.parse call). | 126 // source compiled through eval except for one JSON.parse call). |
121 assertEquals(source_count, after_compile_count); | 127 assertEquals(source_count, after_compile_count); |
122 assertEquals(0, host_compilations); | 128 assertEquals(0, host_compilations); |
123 assertEquals(source_count - 1, eval_compilations); | 129 assertEquals(source_count - 1, eval_compilations); |
124 assertEquals(1, json_compilations); | 130 assertEquals(1, json_compilations); |
125 | 131 |
126 Debug.setListener(null); | 132 Debug.setListener(null); |
OLD | NEW |