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

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

Issue 119108: Add more debugging information to scripts compiled through eval (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 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 | Annotate | Revision Log
« no previous file with comments | « src/objects-inl.h ('k') | test/mjsunit/mirror-script.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 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 current_source = ''; // Current source compiled. 35 var current_source = ''; // Current source being compiled.
36 var source_count = 0; // Total number of scource sompiled. 36 var source_count = 0; // Total number of scources compiled.
37 var host_compilations = 0; // Number of scources compiled through the API.
38 var eval_compilations = 0; // Number of scources compiled through eval.
39 var json_compilations = 0; // Number of scources compiled through JSON.parse.
37 40
38 41
39 function compileSource(source) { 42 function compileSource(source) {
40 current_source = source; 43 current_source = source;
41 eval(current_source); 44 eval(current_source);
42 source_count++; 45 source_count++;
43 } 46 }
44 47
45 48
46 function listener(event, exec_state, event_data, data) { 49 function listener(event, exec_state, event_data, data) {
47 try { 50 try {
48 if (event == Debug.DebugEvent.BeforeCompile || 51 if (event == Debug.DebugEvent.BeforeCompile ||
49 event == Debug.DebugEvent.AfterCompile) { 52 event == Debug.DebugEvent.AfterCompile) {
50 // Count the events. 53 // Count the events.
51 if (event == Debug.DebugEvent.BeforeCompile) { 54 if (event == Debug.DebugEvent.BeforeCompile) {
52 before_compile_count++; 55 before_compile_count++;
53 } else { 56 } else {
54 after_compile_count++; 57 after_compile_count++;
58 switch (event_data.script().compilationType()) {
59 case Debug.ScriptCompilationType.Host:
60 host_compilations++;
61 break;
62 case Debug.ScriptCompilationType.Eval:
63 eval_compilations++;
64 break;
65 case Debug.ScriptCompilationType.JSON:
66 json_compilations++;
67 break;
68 }
55 } 69 }
56 70
57 // If the compiled source contains 'eval' there will be additional compile 71 // If the compiled source contains 'eval' there will be additional compile
58 // events for the source inside eval. 72 // events for the source inside eval.
59 if (current_source.indexOf('eval') == 0) { 73 if (current_source.indexOf('eval') == 0) {
60 // For source with 'eval' there will be compile events with substrings 74 // For source with 'eval' there will be compile events with substrings
61 // as well as with with the exact source. 75 // as well as with with the exact source.
62 assertTrue(current_source.indexOf(event_data.script().source()) >= 0); 76 assertTrue(current_source.indexOf(event_data.script().source()) >= 0);
77 } else if (current_source.indexOf('JSON.parse') == 0) {
78 // For JSON the JSON source will be in parentheses.
79 var s = event_data.script().source();
80 if (s[0] == '(') {
81 s = s.substring(1, s.length - 2);
82 }
83 assertTrue(current_source.indexOf(s) >= 0);
63 } else { 84 } else {
64 // 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
65 // exact source. 86 // exact source.
66 assertEquals(current_source, event_data.script().source()); 87 assertEquals(current_source, event_data.script().source());
67 } 88 }
68 // Check that script context is included into the event message. 89 // Check that script context is included into the event message.
69 var json = event_data.toJSONProtocol(); 90 var json = event_data.toJSONProtocol();
70 var msg = eval('(' + json + ')'); 91 var msg = eval('(' + json + ')');
71 assertTrue('context' in msg.body.script); 92 assertTrue('context' in msg.body.script);
72 } 93 }
73 } catch (e) { 94 } catch (e) {
74 exception = e 95 exception = e
75 } 96 }
76 }; 97 };
77 98
78 99
79 // Add the debug event listener. 100 // Add the debug event listener.
80 Debug.setListener(listener); 101 Debug.setListener(listener);
81 102
82 // Compile different sources. 103 // Compile different sources.
83 compileSource('a=1'); 104 compileSource('a=1');
84 compileSource('function(){}'); 105 compileSource('function(){}');
85 compileSource('eval("a=2")'); 106 compileSource('eval("a=2")');
86 source_count++; // Using eval causes additional compilation event. 107 source_count++; // Using eval causes additional compilation event.
87 compileSource('eval("eval(\'function(){return a;}\')")'); 108 compileSource('eval("eval(\'function(){return a;}\')")');
88 source_count += 2; // Using eval causes additional compilation event. 109 source_count += 2; // Using eval causes additional compilation event.
110 compileSource('JSON.parse("{a:1,b:2}")');
111 source_count++; // Using JSON.parse causes additional compilation event.
89 112
90 // Make sure that the debug event listener was invoked. 113 // Make sure that the debug event listener was invoked.
91 assertFalse(exception, "exception in listener") 114 assertFalse(exception, "exception in listener")
92 115
93 // Number of before and after compile events should be the same. 116 // Number of before and after compile events should be the same.
94 assertEquals(before_compile_count, after_compile_count); 117 assertEquals(before_compile_count, after_compile_count);
95 118
96 // Check the actual number of events. 119 // Check the actual number of events (no compilation through the API as all
120 // source compiled through eval except for one JSON.parse call).
97 assertEquals(source_count, after_compile_count); 121 assertEquals(source_count, after_compile_count);
122 assertEquals(0, host_compilations);
123 assertEquals(source_count - 1, eval_compilations);
124 assertEquals(1, json_compilations);
98 125
99 Debug.setListener(null); 126 Debug.setListener(null);
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | test/mjsunit/mirror-script.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698