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

Side by Side Diff: src/inspector/debugger-script.js

Issue 2449213002: [inspector] migrate scriptParsed and getCompiledScripts to native (Closed)
Patch Set: addressed 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 33
34 var DebuggerScript = {}; 34 var DebuggerScript = {};
35 35
36 /** 36 /**
37 * @param {?CompileEvent} eventData 37 * @param {?CompileEvent} eventData
38 */ 38 */
39 DebuggerScript.getAfterCompileScript = function(eventData) 39 DebuggerScript.getAfterCompileScript = function(eventData)
40 { 40 {
41 var script = eventData.script().value(); 41 var script = eventData.script().value();
42 if (!script.is_debugger_script) 42 if (!script.is_debugger_script)
43 return DebuggerScript._formatScript(eventData.script().value()); 43 return script;
44 return null; 44 return null;
45 } 45 }
46 46
47 /** @type {!Map<!ScopeType, string>} */ 47 /** @type {!Map<!ScopeType, string>} */
48 DebuggerScript._scopeTypeNames = new Map(); 48 DebuggerScript._scopeTypeNames = new Map();
49 DebuggerScript._scopeTypeNames.set(ScopeType.Global, "global"); 49 DebuggerScript._scopeTypeNames.set(ScopeType.Global, "global");
50 DebuggerScript._scopeTypeNames.set(ScopeType.Local, "local"); 50 DebuggerScript._scopeTypeNames.set(ScopeType.Local, "local");
51 DebuggerScript._scopeTypeNames.set(ScopeType.With, "with"); 51 DebuggerScript._scopeTypeNames.set(ScopeType.With, "with");
52 DebuggerScript._scopeTypeNames.set(ScopeType.Closure, "closure"); 52 DebuggerScript._scopeTypeNames.set(ScopeType.Closure, "closure");
53 DebuggerScript._scopeTypeNames.set(ScopeType.Catch, "catch"); 53 DebuggerScript._scopeTypeNames.set(ScopeType.Catch, "catch");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 if (!contextData) 134 if (!contextData)
135 return 0; 135 return 0;
136 var match = contextData.match(/^[^,]*,([^,]*),.*$/); 136 var match = contextData.match(/^[^,]*,([^,]*),.*$/);
137 if (!match) 137 if (!match)
138 return 0; 138 return 0;
139 return parseInt(match[1], 10) || 0; 139 return parseInt(match[1], 10) || 0;
140 } 140 }
141 141
142 /** 142 /**
143 * @param {string|undefined} contextData
144 * @return {string}
145 */
146 DebuggerScript._executionContextAuxData = function(contextData)
147 {
148 if (!contextData)
149 return "";
150 var match = contextData.match(/^[^,]*,[^,]*,(.*)$/);
151 return match ? match[1] : "";
152 }
153
154 /**
155 * @param {string} contextGroupId
156 * @return {!Array<!FormattedScript>}
157 */
158 DebuggerScript.getScripts = function(contextGroupId)
159 {
160 var result = [];
161 var scripts = Debug.scripts();
162 var contextDataPrefix = null;
163 if (contextGroupId)
164 contextDataPrefix = contextGroupId + ",";
165 for (var i = 0; i < scripts.length; ++i) {
166 var script = scripts[i];
167 if (contextDataPrefix) {
168 if (!script.context_data)
169 continue;
170 // Context data is a string in the following format:
171 // <contextGroupId>,<contextId>,<auxData>
172 if (script.context_data.indexOf(contextDataPrefix) !== 0)
173 continue;
174 }
175 if (script.is_debugger_script)
176 continue;
177 result.push(DebuggerScript._formatScript(script));
178 }
179 return result;
180 }
181
182 /**
183 * @param {!Script} script
184 * @return {!FormattedScript}
185 */
186 DebuggerScript._formatScript = function(script)
187 {
188 var lineEnds = script.line_ends;
189 var lineCount = lineEnds.length;
190 var endLine = script.line_offset + lineCount - 1;
191 var endColumn;
192 // V8 will not count last line if script source ends with \n.
193 if (script.source[script.source.length - 1] === '\n') {
194 endLine += 1;
195 endColumn = 0;
196 } else {
197 if (lineCount === 1)
198 endColumn = script.source.length + script.column_offset;
199 else
200 endColumn = script.source.length - (lineEnds[lineCount - 2] + 1);
201 }
202 return {
203 id: script.id,
204 name: script.nameOrSourceURL(),
205 sourceURL: script.source_url,
206 sourceMappingURL: script.source_mapping_url,
207 source: script.source,
208 startLine: script.line_offset,
209 startColumn: script.column_offset,
210 endLine: endLine,
211 endColumn: endColumn,
212 executionContextId: DebuggerScript._executionContextId(script.context_da ta),
213 // Note that we cannot derive aux data from context id because of compil ation cache.
214 executionContextAuxData: DebuggerScript._executionContextAuxData(script. context_data)
215 };
216 }
217
218 /**
219 * @param {!ExecutionState} execState 143 * @param {!ExecutionState} execState
220 * @param {!BreakpointInfo} info 144 * @param {!BreakpointInfo} info
221 * @return {string|undefined} 145 * @return {string|undefined}
222 */ 146 */
223 DebuggerScript.setBreakpoint = function(execState, info) 147 DebuggerScript.setBreakpoint = function(execState, info)
224 { 148 {
225 var breakId = Debug.setScriptBreakPointById(info.sourceID, info.lineNumber, info.columnNumber, info.condition, undefined, Debug.BreakPositionAlignment.State ment); 149 var breakId = Debug.setScriptBreakPointById(info.sourceID, info.lineNumber, info.columnNumber, info.condition, undefined, Debug.BreakPositionAlignment.State ment);
226 var locations = Debug.findBreakPointActualLocations(breakId); 150 var locations = Debug.findBreakPointActualLocations(breakId);
227 if (!locations.length) 151 if (!locations.length)
228 return undefined; 152 return undefined;
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 break; 564 break;
641 } 565 }
642 return result; 566 return result;
643 } 567 }
644 568
645 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr ors in the cache we disable it. 569 // We never resolve Mirror by its handle so to avoid memory leaks caused by Mirr ors in the cache we disable it.
646 ToggleMirrorCache(false); 570 ToggleMirrorCache(false);
647 571
648 return DebuggerScript; 572 return DebuggerScript;
649 })(); 573 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698