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

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

Issue 2497973002: [debug-wrapper] Further extend the debug wrapper (Closed)
Patch Set: Address comments Created 4 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
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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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
29 // Get the Debug object exposed from the debug context global object.
30 Debug = debug.Debug 28 Debug = debug.Debug
31 29
32 var exception = false; // Exception in debug event listener. 30 var exception = false; // Exception in debug event listener.
33 var before_compile_count = 0;
34 var after_compile_count = 0; 31 var after_compile_count = 0;
35 var compile_error_count = 0; 32 var compile_error_count = 0;
36 var current_source = ''; // Current source being compiled. 33 var current_source = ''; // Current source being compiled.
37 var source_count = 0; // Total number of scources compiled. 34 var source_count = 0; // Total number of scources compiled.
38 var host_compilations = 0; // Number of scources compiled through the API.
39 var eval_compilations = 0; // Number of scources compiled through eval.
40 var mute_listener = false; 35 var mute_listener = false;
41 36
42 function compileSource(source) { 37 function compileSource(source) {
43 current_source = source; 38 current_source = source;
44 eval(current_source); 39 eval(current_source);
45 source_count++; 40 source_count++;
46 } 41 }
47 42
48 function safeEval(code) { 43 function safeEval(code) {
49 try { 44 try {
50 mute_listener = true; 45 mute_listener = true;
51 return eval('(' + code + ')'); 46 return eval('(' + code + ')');
52 } catch (e) { 47 } catch (e) {
53 assertEquals(void 0, e); 48 assertEquals(void 0, e);
54 return undefined; 49 return undefined;
55 } finally { 50 } finally {
56 mute_listener = false; 51 mute_listener = false;
57 } 52 }
58 } 53 }
59 54
60 function listener(event, exec_state, event_data, data) { 55 function listener(event, exec_state, event_data, data) {
61 if (mute_listener) return; 56 if (mute_listener) return;
62 try { 57 try {
63 if (event == Debug.DebugEvent.BeforeCompile || 58 if (event == Debug.DebugEvent.BeforeCompile ||
64 event == Debug.DebugEvent.AfterCompile || 59 event == Debug.DebugEvent.AfterCompile ||
65 event == Debug.DebugEvent.CompileError) { 60 event == Debug.DebugEvent.CompileError) {
66 // Count the events. 61 // Count the events.
67 if (event == Debug.DebugEvent.BeforeCompile) { 62 if (event == Debug.DebugEvent.AfterCompile) {
68 before_compile_count++;
69 } else if (event == Debug.DebugEvent.AfterCompile) {
70 after_compile_count++; 63 after_compile_count++;
71 switch (event_data.script().compilationType()) { 64 } else if (event == Debug.DebugEvent.CompileError) {
72 case Debug.ScriptCompilationType.Host:
73 host_compilations++;
74 break;
75 case Debug.ScriptCompilationType.Eval:
76 eval_compilations++;
77 break;
78 }
79 } else {
80 compile_error_count++; 65 compile_error_count++;
81 } 66 }
82 67
83 // If the compiled source contains 'eval' there will be additional compile 68 // If the compiled source contains 'eval' there will be additional compile
84 // events for the source inside eval. 69 // events for the source inside eval.
85 if (current_source.indexOf('eval') == 0) { 70 if (current_source.indexOf('eval') == 0) {
86 // For source with 'eval' there will be compile events with substrings 71 // For source with 'eval' there will be compile events with substrings
87 // as well as with with the exact source. 72 // as well as with with the exact source.
88 assertTrue(current_source.indexOf(event_data.script().source()) >= 0); 73 assertTrue(current_source.indexOf(event_data.script().source()) >= 0);
89 } else { 74 } else {
90 // For source without 'eval' there will be a compile events with the 75 // For source without 'eval' there will be a compile events with the
91 // exact source. 76 // exact source.
92 assertEquals(current_source, event_data.script().source()); 77 assertEquals(current_source, event_data.script().source());
93 } 78 }
94 // Check that script context is included into the event message.
95 var json = event_data.toJSONProtocol();
96 var msg = safeEval(json);
97 assertTrue('context' in msg.body.script);
98 79
99 // Check that we pick script name from //# sourceURL, iff present 80 // Check that we pick script name from //# sourceURL, iff present
100 if (event == Debug.DebugEvent.AfterCompile) { 81 if (event == Debug.DebugEvent.AfterCompile) {
101 assertEquals(current_source.indexOf('sourceURL') >= 0 ? 82 assertEquals(current_source.indexOf('sourceURL') >= 0 ?
102 'myscript.js' : undefined, 83 'myscript.js' : undefined,
103 event_data.script().name()); 84 event_data.script().name());
104 } 85 }
105 } 86 }
106 } catch (e) { 87 } catch (e) {
107 exception = e 88 exception = e
(...skipping 17 matching lines...) Expand all
125 106
126 try { 107 try {
127 compileSource('}'); 108 compileSource('}');
128 } catch(e) { 109 } catch(e) {
129 } 110 }
130 111
131 // Make sure that the debug event listener was invoked. 112 // Make sure that the debug event listener was invoked.
132 assertFalse(exception, "exception in listener") 113 assertFalse(exception, "exception in listener")
133 114
134 // Number of before and after + error events should be the same. 115 // Number of before and after + error events should be the same.
135 assertEquals(before_compile_count, after_compile_count + compile_error_count);
136 assertEquals(compile_error_count, 1); 116 assertEquals(compile_error_count, 1);
137 117
138 // Check the actual number of events (no compilation through the API as all 118 // Check the actual number of events (no compilation through the API as all
139 // source compiled through eval). 119 // source compiled through eval).
140 assertEquals(source_count, after_compile_count); 120 assertEquals(source_count, after_compile_count);
141 assertEquals(0, host_compilations);
142 assertEquals(source_count, eval_compilations);
143 121
144 Debug.setListener(null); 122 Debug.setListener(null);
OLDNEW
« no previous file with comments | « test/debugger/debug/debug-breakpoints.js ('k') | test/debugger/debug/debug-enable-disable-breakpoints.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698