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

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

Issue 642863007: [V8] Send AfterCompile and CompileError messages in debug scope (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/debug-clearbreakpointgroup.js ('k') | test/mjsunit/debug-evaluate-with-context.js » ('j') | 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 19 matching lines...) Expand all
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 var ignore_events = false;
40 41
41 42
42 function compileSource(source) { 43 function compileSource(source) {
43 current_source = source; 44 current_source = source;
44 eval(current_source); 45 eval(current_source);
45 source_count++; 46 source_count++;
46 } 47 }
47 48
48 49
49 function listener(event, exec_state, event_data, data) { 50 function listener(event, exec_state, event_data, data) {
51 if (ignore_events) return;
50 try { 52 try {
51 if (event == Debug.DebugEvent.BeforeCompile || 53 if (event == Debug.DebugEvent.BeforeCompile ||
52 event == Debug.DebugEvent.AfterCompile || 54 event == Debug.DebugEvent.AfterCompile ||
53 event == Debug.DebugEvent.CompileError) { 55 event == Debug.DebugEvent.CompileError) {
54 // Count the events. 56 // Count the events.
55 if (event == Debug.DebugEvent.BeforeCompile) { 57 if (event == Debug.DebugEvent.BeforeCompile) {
56 before_compile_count++; 58 before_compile_count++;
57 } else if (event == Debug.DebugEvent.AfterCompile) { 59 } else if (event == Debug.DebugEvent.AfterCompile) {
58 after_compile_count++; 60 after_compile_count++;
59 switch (event_data.script().compilationType()) { 61 switch (event_data.script().compilationType()) {
(...skipping 14 matching lines...) Expand all
74 // For source with 'eval' there will be compile events with substrings 76 // For source with 'eval' there will be compile events with substrings
75 // as well as with with the exact source. 77 // as well as with with the exact source.
76 assertTrue(current_source.indexOf(event_data.script().source()) >= 0); 78 assertTrue(current_source.indexOf(event_data.script().source()) >= 0);
77 } else { 79 } else {
78 // For source without 'eval' there will be a compile events with the 80 // For source without 'eval' there will be a compile events with the
79 // exact source. 81 // exact source.
80 assertEquals(current_source, event_data.script().source()); 82 assertEquals(current_source, event_data.script().source());
81 } 83 }
82 // Check that script context is included into the event message. 84 // Check that script context is included into the event message.
83 var json = event_data.toJSONProtocol(); 85 var json = event_data.toJSONProtocol();
86 ignore_events = true;
84 var msg = eval('(' + json + ')'); 87 var msg = eval('(' + json + ')');
88 ignore_events = false;
85 assertTrue('context' in msg.body.script); 89 assertTrue('context' in msg.body.script);
86 90
87 // Check that we pick script name from //# sourceURL, iff present 91 // Check that we pick script name from //# sourceURL, iff present
88 if (event == Debug.DebugEvent.AfterCompile) { 92 if (event == Debug.DebugEvent.AfterCompile) {
89 assertEquals(current_source.indexOf('sourceURL') >= 0 ? 93 assertEquals(current_source.indexOf('sourceURL') >= 0 ?
90 'myscript.js' : undefined, 94 'myscript.js' : undefined,
91 event_data.script().name()); 95 event_data.script().name());
92 } 96 }
93 } 97 }
94 } catch (e) { 98 } catch (e) {
(...skipping 15 matching lines...) Expand all
110 compileSource('JSON.parse(\'{"a":1,"b":2}\')'); 114 compileSource('JSON.parse(\'{"a":1,"b":2}\')');
111 // Using JSON.parse does not causes additional compilation events. 115 // Using JSON.parse does not causes additional compilation events.
112 compileSource('x=1; //# sourceURL=myscript.js'); 116 compileSource('x=1; //# sourceURL=myscript.js');
113 117
114 try { 118 try {
115 compileSource('}'); 119 compileSource('}');
116 } catch(e) { 120 } catch(e) {
117 } 121 }
118 122
119 // Make sure that the debug event listener was invoked. 123 // Make sure that the debug event listener was invoked.
120 assertFalse(exception, "exception in listener") 124 assertFalse(exception, "exception in listener");
121 125
122 // Number of before and after + error events should be the same. 126 // Number of before and after + error events should be the same.
123 assertEquals(before_compile_count, after_compile_count + compile_error_count); 127 assertEquals(before_compile_count, after_compile_count + compile_error_count);
124 assertEquals(compile_error_count, 1); 128 assertEquals(compile_error_count, 1);
125 129
126 // Check the actual number of events (no compilation through the API as all 130 // Check the actual number of events (no compilation through the API as all
127 // source compiled through eval). 131 // source compiled through eval).
128 assertEquals(source_count, after_compile_count); 132 assertEquals(source_count, after_compile_count);
129 assertEquals(0, host_compilations); 133 assertEquals(0, host_compilations);
130 assertEquals(source_count, eval_compilations); 134 assertEquals(source_count, eval_compilations);
131 135
132 Debug.setListener(null); 136 Debug.setListener(null);
OLDNEW
« no previous file with comments | « test/mjsunit/debug-clearbreakpointgroup.js ('k') | test/mjsunit/debug-evaluate-with-context.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698