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 19 matching lines...) Expand all Loading... |
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 compile_error_count = 0; | 35 var compile_error_count = 0; |
36 var current_source = ''; // Current source being compiled. | 36 var current_source = ''; // Current source being compiled. |
37 var source_count = 0; // Total number of scources compiled. | 37 var source_count = 0; // Total number of scources compiled. |
38 var host_compilations = 0; // Number of scources compiled through the API. | 38 var host_compilations = 0; // Number of scources compiled through the API. |
39 var eval_compilations = 0; // Number of scources compiled through eval. | 39 var eval_compilations = 0; // Number of scources compiled through eval. |
40 | 40 var mute_listener = false; |
41 | 41 |
42 function compileSource(source) { | 42 function compileSource(source) { |
43 current_source = source; | 43 current_source = source; |
44 eval(current_source); | 44 eval(current_source); |
45 source_count++; | 45 source_count++; |
46 } | 46 } |
47 | 47 |
| 48 function safeEval(code) { |
| 49 try { |
| 50 mute_listener = true; |
| 51 return eval('(' + code + ')'); |
| 52 } catch (e) { |
| 53 assertEquals(void 0, e); |
| 54 return undefined; |
| 55 } finally { |
| 56 mute_listener = false; |
| 57 } |
| 58 } |
48 | 59 |
49 function listener(event, exec_state, event_data, data) { | 60 function listener(event, exec_state, event_data, data) { |
| 61 if (mute_listener) return; |
50 try { | 62 try { |
51 if (event == Debug.DebugEvent.BeforeCompile || | 63 if (event == Debug.DebugEvent.BeforeCompile || |
52 event == Debug.DebugEvent.AfterCompile || | 64 event == Debug.DebugEvent.AfterCompile || |
53 event == Debug.DebugEvent.CompileError) { | 65 event == Debug.DebugEvent.CompileError) { |
54 // Count the events. | 66 // Count the events. |
55 if (event == Debug.DebugEvent.BeforeCompile) { | 67 if (event == Debug.DebugEvent.BeforeCompile) { |
56 before_compile_count++; | 68 before_compile_count++; |
57 } else if (event == Debug.DebugEvent.AfterCompile) { | 69 } else if (event == Debug.DebugEvent.AfterCompile) { |
58 after_compile_count++; | 70 after_compile_count++; |
59 switch (event_data.script().compilationType()) { | 71 switch (event_data.script().compilationType()) { |
(...skipping 14 matching lines...) Expand all Loading... |
74 // For source with 'eval' there will be compile events with substrings | 86 // For source with 'eval' there will be compile events with substrings |
75 // as well as with with the exact source. | 87 // as well as with with the exact source. |
76 assertTrue(current_source.indexOf(event_data.script().source()) >= 0); | 88 assertTrue(current_source.indexOf(event_data.script().source()) >= 0); |
77 } else { | 89 } else { |
78 // For source without 'eval' there will be a compile events with the | 90 // For source without 'eval' there will be a compile events with the |
79 // exact source. | 91 // exact source. |
80 assertEquals(current_source, event_data.script().source()); | 92 assertEquals(current_source, event_data.script().source()); |
81 } | 93 } |
82 // Check that script context is included into the event message. | 94 // Check that script context is included into the event message. |
83 var json = event_data.toJSONProtocol(); | 95 var json = event_data.toJSONProtocol(); |
84 var msg = eval('(' + json + ')'); | 96 var msg = safeEval(json); |
85 assertTrue('context' in msg.body.script); | 97 assertTrue('context' in msg.body.script); |
86 | 98 |
87 // Check that we pick script name from //# sourceURL, iff present | 99 // Check that we pick script name from //# sourceURL, iff present |
88 if (event == Debug.DebugEvent.AfterCompile) { | 100 if (event == Debug.DebugEvent.AfterCompile) { |
89 assertEquals(current_source.indexOf('sourceURL') >= 0 ? | 101 assertEquals(current_source.indexOf('sourceURL') >= 0 ? |
90 'myscript.js' : undefined, | 102 'myscript.js' : undefined, |
91 event_data.script().name()); | 103 event_data.script().name()); |
92 } | 104 } |
93 } | 105 } |
94 } catch (e) { | 106 } catch (e) { |
(...skipping 28 matching lines...) Expand all Loading... |
123 assertEquals(before_compile_count, after_compile_count + compile_error_count); | 135 assertEquals(before_compile_count, after_compile_count + compile_error_count); |
124 assertEquals(compile_error_count, 1); | 136 assertEquals(compile_error_count, 1); |
125 | 137 |
126 // Check the actual number of events (no compilation through the API as all | 138 // Check the actual number of events (no compilation through the API as all |
127 // source compiled through eval). | 139 // source compiled through eval). |
128 assertEquals(source_count, after_compile_count); | 140 assertEquals(source_count, after_compile_count); |
129 assertEquals(0, host_compilations); | 141 assertEquals(0, host_compilations); |
130 assertEquals(source_count, eval_compilations); | 142 assertEquals(source_count, eval_compilations); |
131 | 143 |
132 Debug.setListener(null); | 144 Debug.setListener(null); |
OLD | NEW |