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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/Script.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 /** 25 /**
26 * @implements {WebInspector.ContentProvider} 26 * @implements {Common.ContentProvider}
27 * @unrestricted 27 * @unrestricted
28 */ 28 */
29 WebInspector.Script = class extends WebInspector.SDKObject { 29 SDK.Script = class extends SDK.SDKObject {
30 /** 30 /**
31 * @param {!WebInspector.DebuggerModel} debuggerModel 31 * @param {!SDK.DebuggerModel} debuggerModel
32 * @param {string} scriptId 32 * @param {string} scriptId
33 * @param {string} sourceURL 33 * @param {string} sourceURL
34 * @param {number} startLine 34 * @param {number} startLine
35 * @param {number} startColumn 35 * @param {number} startColumn
36 * @param {number} endLine 36 * @param {number} endLine
37 * @param {number} endColumn 37 * @param {number} endColumn
38 * @param {!Protocol.Runtime.ExecutionContextId} executionContextId 38 * @param {!Protocol.Runtime.ExecutionContextId} executionContextId
39 * @param {string} hash 39 * @param {string} hash
40 * @param {boolean} isContentScript 40 * @param {boolean} isContentScript
41 * @param {boolean} isLiveEdit 41 * @param {boolean} isLiveEdit
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 var sourceURLIndex = source.lastIndexOf('//# sourceURL='); 80 var sourceURLIndex = source.lastIndexOf('//# sourceURL=');
81 if (sourceURLIndex === -1) { 81 if (sourceURLIndex === -1) {
82 sourceURLIndex = source.lastIndexOf('//@ sourceURL='); 82 sourceURLIndex = source.lastIndexOf('//@ sourceURL=');
83 if (sourceURLIndex === -1) 83 if (sourceURLIndex === -1)
84 return source; 84 return source;
85 } 85 }
86 var sourceURLLineIndex = source.lastIndexOf('\n', sourceURLIndex); 86 var sourceURLLineIndex = source.lastIndexOf('\n', sourceURLIndex);
87 if (sourceURLLineIndex === -1) 87 if (sourceURLLineIndex === -1)
88 return source; 88 return source;
89 var sourceURLLine = source.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; 89 var sourceURLLine = source.substr(sourceURLLineIndex + 1).split('\n', 1)[0];
90 if (sourceURLLine.search(WebInspector.Script.sourceURLRegex) === -1) 90 if (sourceURLLine.search(SDK.Script.sourceURLRegex) === -1)
91 return source; 91 return source;
92 return source.substr(0, sourceURLLineIndex) + source.substr(sourceURLLineInd ex + sourceURLLine.length + 1); 92 return source.substr(0, sourceURLLineIndex) + source.substr(sourceURLLineInd ex + sourceURLLine.length + 1);
93 } 93 }
94 94
95 /** 95 /**
96 * @param {!WebInspector.Script} script 96 * @param {!SDK.Script} script
97 * @param {string} source 97 * @param {string} source
98 */ 98 */
99 static _reportDeprecatedCommentIfNeeded(script, source) { 99 static _reportDeprecatedCommentIfNeeded(script, source) {
100 var consoleModel = script.target().consoleModel; 100 var consoleModel = script.target().consoleModel;
101 if (!consoleModel) 101 if (!consoleModel)
102 return; 102 return;
103 var linesToCheck = 5; 103 var linesToCheck = 5;
104 var offset = source.lastIndexOf('\n'); 104 var offset = source.lastIndexOf('\n');
105 while (linesToCheck && offset !== -1) { 105 while (linesToCheck && offset !== -1) {
106 offset = source.lastIndexOf('\n', offset - 1); 106 offset = source.lastIndexOf('\n', offset - 1);
107 --linesToCheck; 107 --linesToCheck;
108 } 108 }
109 offset = offset !== -1 ? offset : 0; 109 offset = offset !== -1 ? offset : 0;
110 var sourceTail = source.substr(offset); 110 var sourceTail = source.substr(offset);
111 if (sourceTail.length > 5000) 111 if (sourceTail.length > 5000)
112 return; 112 return;
113 if (sourceTail.search(/^[\040\t]*\/\/@ source(mapping)?url=/mi) === -1) 113 if (sourceTail.search(/^[\040\t]*\/\/@ source(mapping)?url=/mi) === -1)
114 return; 114 return;
115 var text = WebInspector.UIString( 115 var text = Common.UIString(
116 '\'//@ sourceURL\' and \'//@ sourceMappingURL\' are deprecated, please u se \'//# sourceURL=\' and \'//# sourceMappingURL=\' instead.'); 116 '\'//@ sourceURL\' and \'//@ sourceMappingURL\' are deprecated, please u se \'//# sourceURL=\' and \'//# sourceMappingURL=\' instead.');
117 var msg = new WebInspector.ConsoleMessage( 117 var msg = new SDK.ConsoleMessage(
118 script.target(), WebInspector.ConsoleMessage.MessageSource.JS, WebInspec tor.ConsoleMessage.MessageLevel.Warning, 118 script.target(), SDK.ConsoleMessage.MessageSource.JS, SDK.ConsoleMessage .MessageLevel.Warning,
119 text, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, 119 text, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined,
120 script.scriptId); 120 script.scriptId);
121 consoleModel.addMessage(msg); 121 consoleModel.addMessage(msg);
122 } 122 }
123 123
124 /** 124 /**
125 * @return {boolean} 125 * @return {boolean}
126 */ 126 */
127 isContentScript() { 127 isContentScript() {
128 return this._isContentScript; 128 return this._isContentScript;
129 } 129 }
130 130
131 /** 131 /**
132 * @return {?WebInspector.ExecutionContext} 132 * @return {?SDK.ExecutionContext}
133 */ 133 */
134 executionContext() { 134 executionContext() {
135 return this.target().runtimeModel.executionContext(this._executionContextId) ; 135 return this.target().runtimeModel.executionContext(this._executionContextId) ;
136 } 136 }
137 137
138 /** 138 /**
139 * @return {boolean} 139 * @return {boolean}
140 */ 140 */
141 isLiveEdit() { 141 isLiveEdit() {
142 return this._isLiveEdit; 142 return this._isLiveEdit;
143 } 143 }
144 144
145 /** 145 /**
146 * @override 146 * @override
147 * @return {string} 147 * @return {string}
148 */ 148 */
149 contentURL() { 149 contentURL() {
150 return this.sourceURL; 150 return this.sourceURL;
151 } 151 }
152 152
153 /** 153 /**
154 * @override 154 * @override
155 * @return {!WebInspector.ResourceType} 155 * @return {!Common.ResourceType}
156 */ 156 */
157 contentType() { 157 contentType() {
158 return WebInspector.resourceTypes.Script; 158 return Common.resourceTypes.Script;
159 } 159 }
160 160
161 /** 161 /**
162 * @override 162 * @override
163 * @return {!Promise<?string>} 163 * @return {!Promise<?string>}
164 */ 164 */
165 requestContent() { 165 requestContent() {
166 if (this._source) 166 if (this._source)
167 return Promise.resolve(this._source); 167 return Promise.resolve(this._source);
168 if (!this.scriptId) 168 if (!this.scriptId)
169 return Promise.resolve(/** @type {?string} */ ('')); 169 return Promise.resolve(/** @type {?string} */ (''));
170 170
171 var callback; 171 var callback;
172 var promise = new Promise(fulfill => callback = fulfill); 172 var promise = new Promise(fulfill => callback = fulfill);
173 this.target().debuggerAgent().getScriptSource(this.scriptId, didGetScriptSou rce.bind(this)); 173 this.target().debuggerAgent().getScriptSource(this.scriptId, didGetScriptSou rce.bind(this));
174 return promise; 174 return promise;
175 175
176 /** 176 /**
177 * @this {WebInspector.Script} 177 * @this {SDK.Script}
178 * @param {?Protocol.Error} error 178 * @param {?Protocol.Error} error
179 * @param {string} source 179 * @param {string} source
180 */ 180 */
181 function didGetScriptSource(error, source) { 181 function didGetScriptSource(error, source) {
182 if (!error) { 182 if (!error) {
183 WebInspector.Script._reportDeprecatedCommentIfNeeded(this, source); 183 SDK.Script._reportDeprecatedCommentIfNeeded(this, source);
184 this._source = WebInspector.Script._trimSourceURLComment(source); 184 this._source = SDK.Script._trimSourceURLComment(source);
185 } else { 185 } else {
186 this._source = ''; 186 this._source = '';
187 } 187 }
188 callback(this._source); 188 callback(this._source);
189 } 189 }
190 } 190 }
191 191
192 /** 192 /**
193 * @override 193 * @override
194 * @param {string} query 194 * @param {string} query
195 * @param {boolean} caseSensitive 195 * @param {boolean} caseSensitive
196 * @param {boolean} isRegex 196 * @param {boolean} isRegex
197 * @param {function(!Array.<!Protocol.Debugger.SearchMatch>)} callback 197 * @param {function(!Array.<!Protocol.Debugger.SearchMatch>)} callback
198 */ 198 */
199 searchInContent(query, caseSensitive, isRegex, callback) { 199 searchInContent(query, caseSensitive, isRegex, callback) {
200 /** 200 /**
201 * @param {?Protocol.Error} error 201 * @param {?Protocol.Error} error
202 * @param {!Array.<!Protocol.Debugger.SearchMatch>} searchMatches 202 * @param {!Array.<!Protocol.Debugger.SearchMatch>} searchMatches
203 */ 203 */
204 function innerCallback(error, searchMatches) { 204 function innerCallback(error, searchMatches) {
205 if (error) { 205 if (error) {
206 console.error(error); 206 console.error(error);
207 callback([]); 207 callback([]);
208 return; 208 return;
209 } 209 }
210 var result = []; 210 var result = [];
211 for (var i = 0; i < searchMatches.length; ++i) { 211 for (var i = 0; i < searchMatches.length; ++i) {
212 var searchMatch = 212 var searchMatch =
213 new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNu mber, searchMatches[i].lineContent); 213 new Common.ContentProvider.SearchMatch(searchMatches[i].lineNumber, searchMatches[i].lineContent);
214 result.push(searchMatch); 214 result.push(searchMatch);
215 } 215 }
216 callback(result || []); 216 callback(result || []);
217 } 217 }
218 218
219 if (this.scriptId) { 219 if (this.scriptId) {
220 // Script failed to parse. 220 // Script failed to parse.
221 this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSe nsitive, isRegex, innerCallback); 221 this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSe nsitive, isRegex, innerCallback);
222 } else { 222 } else {
223 callback([]); 223 callback([]);
224 } 224 }
225 } 225 }
226 226
227 /** 227 /**
228 * @param {string} source 228 * @param {string} source
229 * @return {string} 229 * @return {string}
230 */ 230 */
231 _appendSourceURLCommentIfNeeded(source) { 231 _appendSourceURLCommentIfNeeded(source) {
232 if (!this.hasSourceURL) 232 if (!this.hasSourceURL)
233 return source; 233 return source;
234 return source + '\n //# sourceURL=' + this.sourceURL; 234 return source + '\n //# sourceURL=' + this.sourceURL;
235 } 235 }
236 236
237 /** 237 /**
238 * @param {string} newSource 238 * @param {string} newSource
239 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=, !Arr ay.<!Protocol.Debugger.CallFrame>=, !Protocol.Runtime.StackTrace=, boolean=)} ca llback 239 * @param {function(?Protocol.Error, !Protocol.Runtime.ExceptionDetails=, !Arr ay.<!Protocol.Debugger.CallFrame>=, !Protocol.Runtime.StackTrace=, boolean=)} ca llback
240 */ 240 */
241 editSource(newSource, callback) { 241 editSource(newSource, callback) {
242 /** 242 /**
243 * @this {WebInspector.Script} 243 * @this {SDK.Script}
244 * @param {?Protocol.Error} error 244 * @param {?Protocol.Error} error
245 * @param {!Array.<!Protocol.Debugger.CallFrame>=} callFrames 245 * @param {!Array.<!Protocol.Debugger.CallFrame>=} callFrames
246 * @param {boolean=} stackChanged 246 * @param {boolean=} stackChanged
247 * @param {!Protocol.Runtime.StackTrace=} asyncStackTrace 247 * @param {!Protocol.Runtime.StackTrace=} asyncStackTrace
248 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails 248 * @param {!Protocol.Runtime.ExceptionDetails=} exceptionDetails
249 */ 249 */
250 function didEditScriptSource(error, callFrames, stackChanged, asyncStackTrac e, exceptionDetails) { 250 function didEditScriptSource(error, callFrames, stackChanged, asyncStackTrac e, exceptionDetails) {
251 if (!error && !exceptionDetails) 251 if (!error && !exceptionDetails)
252 this._source = newSource; 252 this._source = newSource;
253 var needsStepIn = !!stackChanged; 253 var needsStepIn = !!stackChanged;
254 callback(error, exceptionDetails, callFrames, asyncStackTrace, needsStepIn ); 254 callback(error, exceptionDetails, callFrames, asyncStackTrace, needsStepIn );
255 } 255 }
256 256
257 newSource = WebInspector.Script._trimSourceURLComment(newSource); 257 newSource = SDK.Script._trimSourceURLComment(newSource);
258 // We append correct sourceURL to script for consistency only. It's not actu ally needed for things to work correctly. 258 // We append correct sourceURL to script for consistency only. It's not actu ally needed for things to work correctly.
259 newSource = this._appendSourceURLCommentIfNeeded(newSource); 259 newSource = this._appendSourceURLCommentIfNeeded(newSource);
260 260
261 if (this.scriptId) 261 if (this.scriptId)
262 this.target().debuggerAgent().setScriptSource( 262 this.target().debuggerAgent().setScriptSource(
263 this.scriptId, newSource, undefined, didEditScriptSource.bind(this)); 263 this.scriptId, newSource, undefined, didEditScriptSource.bind(this));
264 else 264 else
265 callback('Script failed to parse'); 265 callback('Script failed to parse');
266 } 266 }
267 267
268 /** 268 /**
269 * @param {number} lineNumber 269 * @param {number} lineNumber
270 * @param {number=} columnNumber 270 * @param {number=} columnNumber
271 * @return {!WebInspector.DebuggerModel.Location} 271 * @return {!SDK.DebuggerModel.Location}
272 */ 272 */
273 rawLocation(lineNumber, columnNumber) { 273 rawLocation(lineNumber, columnNumber) {
274 return new WebInspector.DebuggerModel.Location(this.debuggerModel, this.scri ptId, lineNumber, columnNumber || 0); 274 return new SDK.DebuggerModel.Location(this.debuggerModel, this.scriptId, lin eNumber, columnNumber || 0);
275 } 275 }
276 276
277 /** 277 /**
278 * @return {boolean} 278 * @return {boolean}
279 */ 279 */
280 isInlineScript() { 280 isInlineScript() {
281 var startsAtZero = !this.lineOffset && !this.columnOffset; 281 var startsAtZero = !this.lineOffset && !this.columnOffset;
282 return !!this.sourceURL && !startsAtZero; 282 return !!this.sourceURL && !startsAtZero;
283 } 283 }
284 284
285 /** 285 /**
286 * @param {string} sourceMapURL 286 * @param {string} sourceMapURL
287 */ 287 */
288 addSourceMapURL(sourceMapURL) { 288 addSourceMapURL(sourceMapURL) {
289 if (this.sourceMapURL) 289 if (this.sourceMapURL)
290 return; 290 return;
291 this.sourceMapURL = sourceMapURL; 291 this.sourceMapURL = sourceMapURL;
292 this.dispatchEventToListeners(WebInspector.Script.Events.SourceMapURLAdded, this.sourceMapURL); 292 this.dispatchEventToListeners(SDK.Script.Events.SourceMapURLAdded, this.sour ceMapURL);
293 } 293 }
294 294
295 /** 295 /**
296 * @return {boolean} 296 * @return {boolean}
297 */ 297 */
298 isAnonymousScript() { 298 isAnonymousScript() {
299 return !this.sourceURL; 299 return !this.sourceURL;
300 } 300 }
301 301
302 /** 302 /**
303 * @return {boolean} 303 * @return {boolean}
304 */ 304 */
305 isInlineScriptWithSourceURL() { 305 isInlineScriptWithSourceURL() {
306 return !!this.hasSourceURL && this.isInlineScript(); 306 return !!this.hasSourceURL && this.isInlineScript();
307 } 307 }
308 308
309 /** 309 /**
310 * @param {!Array<!Protocol.Debugger.ScriptPosition>} positions 310 * @param {!Array<!Protocol.Debugger.ScriptPosition>} positions
311 * @return {!Promise<boolean>} 311 * @return {!Promise<boolean>}
312 */ 312 */
313 setBlackboxedRanges(positions) { 313 setBlackboxedRanges(positions) {
314 return new Promise(setBlackboxedRanges.bind(this)); 314 return new Promise(setBlackboxedRanges.bind(this));
315 315
316 /** 316 /**
317 * @param {function(?)} fulfill 317 * @param {function(?)} fulfill
318 * @param {function(*)} reject 318 * @param {function(*)} reject
319 * @this {WebInspector.Script} 319 * @this {SDK.Script}
320 */ 320 */
321 function setBlackboxedRanges(fulfill, reject) { 321 function setBlackboxedRanges(fulfill, reject) {
322 this.target().debuggerAgent().setBlackboxedRanges(this.scriptId, positions , callback); 322 this.target().debuggerAgent().setBlackboxedRanges(this.scriptId, positions , callback);
323 /** 323 /**
324 * @param {?Protocol.Error} error 324 * @param {?Protocol.Error} error
325 */ 325 */
326 function callback(error) { 326 function callback(error) {
327 if (error) 327 if (error)
328 console.error(error); 328 console.error(error);
329 fulfill(!error); 329 fulfill(!error);
330 } 330 }
331 } 331 }
332 } 332 }
333 }; 333 };
334 334
335 /** @enum {symbol} */ 335 /** @enum {symbol} */
336 WebInspector.Script.Events = { 336 SDK.Script.Events = {
337 ScriptEdited: Symbol('ScriptEdited'), 337 ScriptEdited: Symbol('ScriptEdited'),
338 SourceMapURLAdded: Symbol('SourceMapURLAdded') 338 SourceMapURLAdded: Symbol('SourceMapURLAdded')
339 }; 339 };
340 340
341 WebInspector.Script.sourceURLRegex = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$ /m; 341 SDK.Script.sourceURLRegex = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698