Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: test/mjsunit/debug-compile-event.js

Issue 264333007: Add OnCompileError handler and v8::CompileError debug event (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/test-debug.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
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 compile_error_count = 0;
35 var current_source = ''; // Current source being compiled. 36 var current_source = ''; // Current source being compiled.
36 var source_count = 0; // Total number of scources compiled. 37 var source_count = 0; // Total number of scources compiled.
37 var host_compilations = 0; // Number of scources compiled through the API. 38 var host_compilations = 0; // Number of scources compiled through the API.
38 var eval_compilations = 0; // Number of scources compiled through eval. 39 var eval_compilations = 0; // Number of scources compiled through eval.
39 40
40 41
41 function compileSource(source) { 42 function compileSource(source) {
42 current_source = source; 43 current_source = source;
43 eval(current_source); 44 eval(current_source);
44 source_count++; 45 source_count++;
45 } 46 }
46 47
47 48
48 function listener(event, exec_state, event_data, data) { 49 function listener(event, exec_state, event_data, data) {
49 try { 50 try {
50 if (event == Debug.DebugEvent.BeforeCompile || 51 if (event == Debug.DebugEvent.BeforeCompile ||
51 event == Debug.DebugEvent.AfterCompile) { 52 event == Debug.DebugEvent.AfterCompile ||
53 event == Debug.DebugEvent.CompileError) {
52 // Count the events. 54 // Count the events.
53 if (event == Debug.DebugEvent.BeforeCompile) { 55 if (event == Debug.DebugEvent.BeforeCompile) {
54 before_compile_count++; 56 before_compile_count++;
55 } else { 57 } else if (event == Debug.DebugEvent.AfterCompile) {
56 after_compile_count++; 58 after_compile_count++;
57 switch (event_data.script().compilationType()) { 59 switch (event_data.script().compilationType()) {
58 case Debug.ScriptCompilationType.Host: 60 case Debug.ScriptCompilationType.Host:
59 host_compilations++; 61 host_compilations++;
60 break; 62 break;
61 case Debug.ScriptCompilationType.Eval: 63 case Debug.ScriptCompilationType.Eval:
62 eval_compilations++; 64 eval_compilations++;
63 break; 65 break;
64 } 66 }
67 } else {
68 compile_error_count++;
65 } 69 }
66 70
67 // If the compiled source contains 'eval' there will be additional compile 71 // If the compiled source contains 'eval' there will be additional compile
68 // events for the source inside eval. 72 // events for the source inside eval.
69 if (current_source.indexOf('eval') == 0) { 73 if (current_source.indexOf('eval') == 0) {
70 // For source with 'eval' there will be compile events with substrings 74 // For source with 'eval' there will be compile events with substrings
71 // as well as with with the exact source. 75 // as well as with with the exact source.
72 assertTrue(current_source.indexOf(event_data.script().source()) >= 0); 76 assertTrue(current_source.indexOf(event_data.script().source()) >= 0);
73 } else { 77 } else {
74 // For source without 'eval' there will be a compile events with the 78 // For source without 'eval' there will be a compile events with the
(...skipping 23 matching lines...) Expand all
98 compileSource('a=1'); 102 compileSource('a=1');
99 compileSource('(function(){})'); 103 compileSource('(function(){})');
100 compileSource('eval("a=2")'); 104 compileSource('eval("a=2")');
101 source_count++; // Using eval causes additional compilation event. 105 source_count++; // Using eval causes additional compilation event.
102 compileSource('eval("eval(\'(function(){return a;})\')")'); 106 compileSource('eval("eval(\'(function(){return a;})\')")');
103 source_count += 2; // Using eval causes additional compilation event. 107 source_count += 2; // Using eval causes additional compilation event.
104 compileSource('JSON.parse(\'{"a":1,"b":2}\')'); 108 compileSource('JSON.parse(\'{"a":1,"b":2}\')');
105 // Using JSON.parse does not causes additional compilation events. 109 // Using JSON.parse does not causes additional compilation events.
106 compileSource('x=1; //# sourceURL=myscript.js'); 110 compileSource('x=1; //# sourceURL=myscript.js');
107 111
112 try {
113 compileSource('}');
114 } catch(e) {
115 }
116
108 // Make sure that the debug event listener was invoked. 117 // Make sure that the debug event listener was invoked.
109 assertFalse(exception, "exception in listener") 118 assertFalse(exception, "exception in listener")
110 119
111 // Number of before and after compile events should be the same. 120 // Number of before and after + error events should be the same.
112 assertEquals(before_compile_count, after_compile_count); 121 assertEquals(before_compile_count, after_compile_count + compile_error_count);
122 assertEquals(compile_error_count, 1);
113 123
114 // Check the actual number of events (no compilation through the API as all 124 // Check the actual number of events (no compilation through the API as all
115 // source compiled through eval). 125 // source compiled through eval).
116 assertEquals(source_count, after_compile_count); 126 assertEquals(source_count, after_compile_count);
117 assertEquals(0, host_compilations); 127 assertEquals(0, host_compilations);
118 assertEquals(source_count, eval_compilations); 128 assertEquals(source_count, eval_compilations);
119 129
120 Debug.setListener(null); 130 Debug.setListener(null);
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698