OLD | NEW |
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 | |
26 /** | 25 /** |
27 * @constructor | |
28 * @extends {WebInspector.SDKObject} | |
29 * @implements {WebInspector.ContentProvider} | 26 * @implements {WebInspector.ContentProvider} |
30 * @param {!WebInspector.DebuggerModel} debuggerModel | 27 * @unrestricted |
31 * @param {string} scriptId | |
32 * @param {string} sourceURL | |
33 * @param {number} startLine | |
34 * @param {number} startColumn | |
35 * @param {number} endLine | |
36 * @param {number} endColumn | |
37 * @param {!RuntimeAgent.ExecutionContextId} executionContextId | |
38 * @param {string} hash | |
39 * @param {boolean} isContentScript | |
40 * @param {boolean} isLiveEdit | |
41 * @param {string=} sourceMapURL | |
42 * @param {boolean=} hasSourceURL | |
43 */ | 28 */ |
44 WebInspector.Script = function(debuggerModel, scriptId, sourceURL, startLine, st
artColumn, endLine, endColumn, executionContextId, hash, isContentScript, isLive
Edit, sourceMapURL, hasSourceURL) | 29 WebInspector.Script = class extends WebInspector.SDKObject { |
45 { | 30 /** |
46 WebInspector.SDKObject.call(this, debuggerModel.target()); | 31 * @param {!WebInspector.DebuggerModel} debuggerModel |
| 32 * @param {string} scriptId |
| 33 * @param {string} sourceURL |
| 34 * @param {number} startLine |
| 35 * @param {number} startColumn |
| 36 * @param {number} endLine |
| 37 * @param {number} endColumn |
| 38 * @param {!RuntimeAgent.ExecutionContextId} executionContextId |
| 39 * @param {string} hash |
| 40 * @param {boolean} isContentScript |
| 41 * @param {boolean} isLiveEdit |
| 42 * @param {string=} sourceMapURL |
| 43 * @param {boolean=} hasSourceURL |
| 44 */ |
| 45 constructor( |
| 46 debuggerModel, |
| 47 scriptId, |
| 48 sourceURL, |
| 49 startLine, |
| 50 startColumn, |
| 51 endLine, |
| 52 endColumn, |
| 53 executionContextId, |
| 54 hash, |
| 55 isContentScript, |
| 56 isLiveEdit, |
| 57 sourceMapURL, |
| 58 hasSourceURL) { |
| 59 super(debuggerModel.target()); |
47 this.debuggerModel = debuggerModel; | 60 this.debuggerModel = debuggerModel; |
48 this.scriptId = scriptId; | 61 this.scriptId = scriptId; |
49 this.sourceURL = sourceURL; | 62 this.sourceURL = sourceURL; |
50 this.lineOffset = startLine; | 63 this.lineOffset = startLine; |
51 this.columnOffset = startColumn; | 64 this.columnOffset = startColumn; |
52 this.endLine = endLine; | 65 this.endLine = endLine; |
53 this.endColumn = endColumn; | 66 this.endColumn = endColumn; |
54 this._executionContextId = executionContextId; | 67 this._executionContextId = executionContextId; |
55 this.hash = hash; | 68 this.hash = hash; |
56 this._isContentScript = isContentScript; | 69 this._isContentScript = isContentScript; |
57 this._isLiveEdit = isLiveEdit; | 70 this._isLiveEdit = isLiveEdit; |
58 this.sourceMapURL = sourceMapURL; | 71 this.sourceMapURL = sourceMapURL; |
59 this.hasSourceURL = hasSourceURL; | 72 this.hasSourceURL = hasSourceURL; |
60 }; | 73 } |
61 | 74 |
62 /** @enum {symbol} */ | 75 /** |
63 WebInspector.Script.Events = { | 76 * @param {string} source |
64 ScriptEdited: Symbol("ScriptEdited"), | 77 * @return {string} |
65 SourceMapURLAdded: Symbol("SourceMapURLAdded") | 78 */ |
66 }; | 79 static _trimSourceURLComment(source) { |
67 | 80 var sourceURLIndex = source.lastIndexOf('//# sourceURL='); |
68 WebInspector.Script.sourceURLRegex = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$
/m; | |
69 | |
70 /** | |
71 * @param {string} source | |
72 * @return {string} | |
73 */ | |
74 WebInspector.Script._trimSourceURLComment = function(source) | |
75 { | |
76 var sourceURLIndex = source.lastIndexOf("//# sourceURL="); | |
77 if (sourceURLIndex === -1) { | 81 if (sourceURLIndex === -1) { |
78 sourceURLIndex = source.lastIndexOf("//@ sourceURL="); | 82 sourceURLIndex = source.lastIndexOf('//@ sourceURL='); |
79 if (sourceURLIndex === -1) | 83 if (sourceURLIndex === -1) |
80 return source; | 84 return source; |
81 } | 85 } |
82 var sourceURLLineIndex = source.lastIndexOf("\n", sourceURLIndex); | 86 var sourceURLLineIndex = source.lastIndexOf('\n', sourceURLIndex); |
83 if (sourceURLLineIndex === -1) | 87 if (sourceURLLineIndex === -1) |
84 return source; | 88 return source; |
85 var sourceURLLine = source.substr(sourceURLLineIndex + 1).split("\n", 1)[0]; | 89 var sourceURLLine = source.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; |
86 if (sourceURLLine.search(WebInspector.Script.sourceURLRegex) === -1) | 90 if (sourceURLLine.search(WebInspector.Script.sourceURLRegex) === -1) |
87 return source; | 91 return source; |
88 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); |
89 }; | 93 } |
90 | 94 |
91 /** | 95 /** |
92 * @param {!WebInspector.Script} script | 96 * @param {!WebInspector.Script} script |
93 * @param {string} source | 97 * @param {string} source |
94 */ | 98 */ |
95 WebInspector.Script._reportDeprecatedCommentIfNeeded = function(script, source) | 99 static _reportDeprecatedCommentIfNeeded(script, source) { |
96 { | |
97 var consoleModel = script.target().consoleModel; | 100 var consoleModel = script.target().consoleModel; |
98 if (!consoleModel) | 101 if (!consoleModel) |
99 return; | 102 return; |
100 var linesToCheck = 5; | 103 var linesToCheck = 5; |
101 var offset = source.lastIndexOf("\n"); | 104 var offset = source.lastIndexOf('\n'); |
102 while (linesToCheck && offset !== -1) { | 105 while (linesToCheck && offset !== -1) { |
103 offset = source.lastIndexOf("\n", offset - 1); | 106 offset = source.lastIndexOf('\n', offset - 1); |
104 --linesToCheck; | 107 --linesToCheck; |
105 } | 108 } |
106 offset = offset !== -1 ? offset : 0; | 109 offset = offset !== -1 ? offset : 0; |
107 var sourceTail = source.substr(offset); | 110 var sourceTail = source.substr(offset); |
108 if (sourceTail.length > 5000) | 111 if (sourceTail.length > 5000) |
| 112 return; |
| 113 if (sourceTail.search(/^[\040\t]*\/\/@ source(mapping)?url=/mi) === -1) |
| 114 return; |
| 115 var text = WebInspector.UIString( |
| 116 '\'//@ sourceURL\' and \'//@ sourceMappingURL\' are deprecated, please u
se \'//# sourceURL=\' and \'//# sourceMappingURL=\' instead.'); |
| 117 var msg = new WebInspector.ConsoleMessage( |
| 118 script.target(), WebInspector.ConsoleMessage.MessageSource.JS, WebInspec
tor.ConsoleMessage.MessageLevel.Warning, |
| 119 text, undefined, undefined, undefined, undefined, undefined, undefined,
undefined, undefined, undefined, |
| 120 script.scriptId); |
| 121 consoleModel.addMessage(msg); |
| 122 } |
| 123 |
| 124 /** |
| 125 * @return {boolean} |
| 126 */ |
| 127 isContentScript() { |
| 128 return this._isContentScript; |
| 129 } |
| 130 |
| 131 /** |
| 132 * @return {?WebInspector.ExecutionContext} |
| 133 */ |
| 134 executionContext() { |
| 135 return this.target().runtimeModel.executionContext(this._executionContextId)
; |
| 136 } |
| 137 |
| 138 /** |
| 139 * @return {boolean} |
| 140 */ |
| 141 isLiveEdit() { |
| 142 return this._isLiveEdit; |
| 143 } |
| 144 |
| 145 /** |
| 146 * @override |
| 147 * @return {string} |
| 148 */ |
| 149 contentURL() { |
| 150 return this.sourceURL; |
| 151 } |
| 152 |
| 153 /** |
| 154 * @override |
| 155 * @return {!WebInspector.ResourceType} |
| 156 */ |
| 157 contentType() { |
| 158 return WebInspector.resourceTypes.Script; |
| 159 } |
| 160 |
| 161 /** |
| 162 * @override |
| 163 * @return {!Promise<?string>} |
| 164 */ |
| 165 requestContent() { |
| 166 if (this._source) |
| 167 return Promise.resolve(this._source); |
| 168 if (!this.scriptId) |
| 169 return Promise.resolve(/** @type {?string} */ ('')); |
| 170 |
| 171 var callback; |
| 172 var promise = new Promise(fulfill => callback = fulfill); |
| 173 this.target().debuggerAgent().getScriptSource(this.scriptId, didGetScriptSou
rce.bind(this)); |
| 174 return promise; |
| 175 |
| 176 /** |
| 177 * @this {WebInspector.Script} |
| 178 * @param {?Protocol.Error} error |
| 179 * @param {string} source |
| 180 */ |
| 181 function didGetScriptSource(error, source) { |
| 182 if (!error) { |
| 183 WebInspector.Script._reportDeprecatedCommentIfNeeded(this, source); |
| 184 this._source = WebInspector.Script._trimSourceURLComment(source); |
| 185 } else { |
| 186 this._source = ''; |
| 187 } |
| 188 callback(this._source); |
| 189 } |
| 190 } |
| 191 |
| 192 /** |
| 193 * @override |
| 194 * @param {string} query |
| 195 * @param {boolean} caseSensitive |
| 196 * @param {boolean} isRegex |
| 197 * @param {function(!Array.<!DebuggerAgent.SearchMatch>)} callback |
| 198 */ |
| 199 searchInContent(query, caseSensitive, isRegex, callback) { |
| 200 /** |
| 201 * @param {?Protocol.Error} error |
| 202 * @param {!Array.<!DebuggerAgent.SearchMatch>} searchMatches |
| 203 */ |
| 204 function innerCallback(error, searchMatches) { |
| 205 if (error) { |
| 206 console.error(error); |
| 207 callback([]); |
109 return; | 208 return; |
110 if (sourceTail.search(/^[\040\t]*\/\/@ source(mapping)?url=/mi) === -1) | 209 } |
111 return; | 210 var result = []; |
112 var text = WebInspector.UIString("'//@ sourceURL' and '//@ sourceMappingURL'
are deprecated, please use '//# sourceURL=' and '//# sourceMappingURL=' instead
."); | 211 for (var i = 0; i < searchMatches.length; ++i) { |
113 var msg = new WebInspector.ConsoleMessage(script.target(), WebInspector.Cons
oleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageLevel.Warning, t
ext, undefined, undefined, undefined, undefined, undefined, undefined, undefined
, undefined, undefined, script.scriptId); | 212 var searchMatch = |
114 consoleModel.addMessage(msg); | 213 new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNu
mber, searchMatches[i].lineContent); |
| 214 result.push(searchMatch); |
| 215 } |
| 216 callback(result || []); |
| 217 } |
| 218 |
| 219 if (this.scriptId) { |
| 220 // Script failed to parse. |
| 221 this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSe
nsitive, isRegex, innerCallback); |
| 222 } else { |
| 223 callback([]); |
| 224 } |
| 225 } |
| 226 |
| 227 /** |
| 228 * @param {string} source |
| 229 * @return {string} |
| 230 */ |
| 231 _appendSourceURLCommentIfNeeded(source) { |
| 232 if (!this.hasSourceURL) |
| 233 return source; |
| 234 return source + '\n //# sourceURL=' + this.sourceURL; |
| 235 } |
| 236 |
| 237 /** |
| 238 * @param {string} newSource |
| 239 * @param {function(?Protocol.Error, !RuntimeAgent.ExceptionDetails=, !Array.<
!DebuggerAgent.CallFrame>=, !RuntimeAgent.StackTrace=, boolean=)} callback |
| 240 */ |
| 241 editSource(newSource, callback) { |
| 242 /** |
| 243 * @this {WebInspector.Script} |
| 244 * @param {?Protocol.Error} error |
| 245 * @param {!Array.<!DebuggerAgent.CallFrame>=} callFrames |
| 246 * @param {boolean=} stackChanged |
| 247 * @param {!RuntimeAgent.StackTrace=} asyncStackTrace |
| 248 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails |
| 249 */ |
| 250 function didEditScriptSource(error, callFrames, stackChanged, asyncStackTrac
e, exceptionDetails) { |
| 251 if (!error && !exceptionDetails) |
| 252 this._source = newSource; |
| 253 var needsStepIn = !!stackChanged; |
| 254 callback(error, exceptionDetails, callFrames, asyncStackTrace, needsStepIn
); |
| 255 } |
| 256 |
| 257 newSource = WebInspector.Script._trimSourceURLComment(newSource); |
| 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); |
| 260 |
| 261 if (this.scriptId) |
| 262 this.target().debuggerAgent().setScriptSource( |
| 263 this.scriptId, newSource, undefined, didEditScriptSource.bind(this)); |
| 264 else |
| 265 callback('Script failed to parse'); |
| 266 } |
| 267 |
| 268 /** |
| 269 * @param {number} lineNumber |
| 270 * @param {number=} columnNumber |
| 271 * @return {!WebInspector.DebuggerModel.Location} |
| 272 */ |
| 273 rawLocation(lineNumber, columnNumber) { |
| 274 return new WebInspector.DebuggerModel.Location(this.debuggerModel, this.scri
ptId, lineNumber, columnNumber || 0); |
| 275 } |
| 276 |
| 277 /** |
| 278 * @return {boolean} |
| 279 */ |
| 280 isInlineScript() { |
| 281 var startsAtZero = !this.lineOffset && !this.columnOffset; |
| 282 return !!this.sourceURL && !startsAtZero; |
| 283 } |
| 284 |
| 285 /** |
| 286 * @param {string} sourceMapURL |
| 287 */ |
| 288 addSourceMapURL(sourceMapURL) { |
| 289 if (this.sourceMapURL) |
| 290 return; |
| 291 this.sourceMapURL = sourceMapURL; |
| 292 this.dispatchEventToListeners(WebInspector.Script.Events.SourceMapURLAdded,
this.sourceMapURL); |
| 293 } |
| 294 |
| 295 /** |
| 296 * @return {boolean} |
| 297 */ |
| 298 isAnonymousScript() { |
| 299 return !this.sourceURL; |
| 300 } |
| 301 |
| 302 /** |
| 303 * @return {boolean} |
| 304 */ |
| 305 isInlineScriptWithSourceURL() { |
| 306 return !!this.hasSourceURL && this.isInlineScript(); |
| 307 } |
| 308 |
| 309 /** |
| 310 * @param {!Array<!DebuggerAgent.ScriptPosition>} positions |
| 311 * @return {!Promise<boolean>} |
| 312 */ |
| 313 setBlackboxedRanges(positions) { |
| 314 return new Promise(setBlackboxedRanges.bind(this)); |
| 315 |
| 316 /** |
| 317 * @param {function(?)} fulfill |
| 318 * @param {function(*)} reject |
| 319 * @this {WebInspector.Script} |
| 320 */ |
| 321 function setBlackboxedRanges(fulfill, reject) { |
| 322 this.target().debuggerAgent().setBlackboxedRanges(this.scriptId, positions
, callback); |
| 323 /** |
| 324 * @param {?Protocol.Error} error |
| 325 */ |
| 326 function callback(error) { |
| 327 if (error) |
| 328 console.error(error); |
| 329 fulfill(!error); |
| 330 } |
| 331 } |
| 332 } |
115 }; | 333 }; |
116 | 334 |
117 WebInspector.Script.prototype = { | 335 /** @enum {symbol} */ |
118 /** | 336 WebInspector.Script.Events = { |
119 * @return {boolean} | 337 ScriptEdited: Symbol('ScriptEdited'), |
120 */ | 338 SourceMapURLAdded: Symbol('SourceMapURLAdded') |
121 isContentScript: function() | |
122 { | |
123 return this._isContentScript; | |
124 }, | |
125 | |
126 /** | |
127 * @return {?WebInspector.ExecutionContext} | |
128 */ | |
129 executionContext: function() | |
130 { | |
131 return this.target().runtimeModel.executionContext(this._executionContex
tId); | |
132 }, | |
133 | |
134 /** | |
135 * @return {boolean} | |
136 */ | |
137 isLiveEdit: function() | |
138 { | |
139 return this._isLiveEdit; | |
140 }, | |
141 | |
142 /** | |
143 * @override | |
144 * @return {string} | |
145 */ | |
146 contentURL: function() | |
147 { | |
148 return this.sourceURL; | |
149 }, | |
150 | |
151 /** | |
152 * @override | |
153 * @return {!WebInspector.ResourceType} | |
154 */ | |
155 contentType: function() | |
156 { | |
157 return WebInspector.resourceTypes.Script; | |
158 }, | |
159 | |
160 /** | |
161 * @override | |
162 * @return {!Promise<?string>} | |
163 */ | |
164 requestContent: function() | |
165 { | |
166 if (this._source) | |
167 return Promise.resolve(this._source); | |
168 if (!this.scriptId) | |
169 return Promise.resolve(/** @type {?string} */("")); | |
170 | |
171 var callback; | |
172 var promise = new Promise(fulfill => callback = fulfill); | |
173 this.target().debuggerAgent().getScriptSource(this.scriptId, didGetScrip
tSource.bind(this)); | |
174 return promise; | |
175 | |
176 /** | |
177 * @this {WebInspector.Script} | |
178 * @param {?Protocol.Error} error | |
179 * @param {string} source | |
180 */ | |
181 function didGetScriptSource(error, source) | |
182 { | |
183 if (!error) { | |
184 WebInspector.Script._reportDeprecatedCommentIfNeeded(this, sourc
e); | |
185 this._source = WebInspector.Script._trimSourceURLComment(source)
; | |
186 } else { | |
187 this._source = ""; | |
188 } | |
189 callback(this._source); | |
190 } | |
191 }, | |
192 | |
193 /** | |
194 * @override | |
195 * @param {string} query | |
196 * @param {boolean} caseSensitive | |
197 * @param {boolean} isRegex | |
198 * @param {function(!Array.<!DebuggerAgent.SearchMatch>)} callback | |
199 */ | |
200 searchInContent: function(query, caseSensitive, isRegex, callback) | |
201 { | |
202 /** | |
203 * @param {?Protocol.Error} error | |
204 * @param {!Array.<!DebuggerAgent.SearchMatch>} searchMatches | |
205 */ | |
206 function innerCallback(error, searchMatches) | |
207 { | |
208 if (error) { | |
209 console.error(error); | |
210 callback([]); | |
211 return; | |
212 } | |
213 var result = []; | |
214 for (var i = 0; i < searchMatches.length; ++i) { | |
215 var searchMatch = new WebInspector.ContentProvider.SearchMatch(s
earchMatches[i].lineNumber, searchMatches[i].lineContent); | |
216 result.push(searchMatch); | |
217 } | |
218 callback(result || []); | |
219 } | |
220 | |
221 if (this.scriptId) { | |
222 // Script failed to parse. | |
223 this.target().debuggerAgent().searchInContent(this.scriptId, query,
caseSensitive, isRegex, innerCallback); | |
224 } else { | |
225 callback([]); | |
226 } | |
227 }, | |
228 | |
229 /** | |
230 * @param {string} source | |
231 * @return {string} | |
232 */ | |
233 _appendSourceURLCommentIfNeeded: function(source) | |
234 { | |
235 if (!this.hasSourceURL) | |
236 return source; | |
237 return source + "\n //# sourceURL=" + this.sourceURL; | |
238 }, | |
239 | |
240 /** | |
241 * @param {string} newSource | |
242 * @param {function(?Protocol.Error, !RuntimeAgent.ExceptionDetails=, !Array
.<!DebuggerAgent.CallFrame>=, !RuntimeAgent.StackTrace=, boolean=)} callback | |
243 */ | |
244 editSource: function(newSource, callback) | |
245 { | |
246 /** | |
247 * @this {WebInspector.Script} | |
248 * @param {?Protocol.Error} error | |
249 * @param {!Array.<!DebuggerAgent.CallFrame>=} callFrames | |
250 * @param {boolean=} stackChanged | |
251 * @param {!RuntimeAgent.StackTrace=} asyncStackTrace | |
252 * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails | |
253 */ | |
254 function didEditScriptSource(error, callFrames, stackChanged, asyncStack
Trace, exceptionDetails) | |
255 { | |
256 if (!error && !exceptionDetails) | |
257 this._source = newSource; | |
258 var needsStepIn = !!stackChanged; | |
259 callback(error, exceptionDetails, callFrames, asyncStackTrace, needs
StepIn); | |
260 } | |
261 | |
262 newSource = WebInspector.Script._trimSourceURLComment(newSource); | |
263 // We append correct sourceURL to script for consistency only. It's not
actually needed for things to work correctly. | |
264 newSource = this._appendSourceURLCommentIfNeeded(newSource); | |
265 | |
266 if (this.scriptId) | |
267 this.target().debuggerAgent().setScriptSource(this.scriptId, newSour
ce, undefined, didEditScriptSource.bind(this)); | |
268 else | |
269 callback("Script failed to parse"); | |
270 }, | |
271 | |
272 /** | |
273 * @param {number} lineNumber | |
274 * @param {number=} columnNumber | |
275 * @return {!WebInspector.DebuggerModel.Location} | |
276 */ | |
277 rawLocation: function(lineNumber, columnNumber) | |
278 { | |
279 return new WebInspector.DebuggerModel.Location(this.debuggerModel, this.
scriptId, lineNumber, columnNumber || 0); | |
280 }, | |
281 | |
282 /** | |
283 * @return {boolean} | |
284 */ | |
285 isInlineScript: function() | |
286 { | |
287 var startsAtZero = !this.lineOffset && !this.columnOffset; | |
288 return !!this.sourceURL && !startsAtZero; | |
289 }, | |
290 | |
291 /** | |
292 * @param {string} sourceMapURL | |
293 */ | |
294 addSourceMapURL: function(sourceMapURL) | |
295 { | |
296 if (this.sourceMapURL) | |
297 return; | |
298 this.sourceMapURL = sourceMapURL; | |
299 this.dispatchEventToListeners(WebInspector.Script.Events.SourceMapURLAdd
ed, this.sourceMapURL); | |
300 }, | |
301 | |
302 /** | |
303 * @return {boolean} | |
304 */ | |
305 isAnonymousScript: function() | |
306 { | |
307 return !this.sourceURL; | |
308 }, | |
309 | |
310 /** | |
311 * @return {boolean} | |
312 */ | |
313 isInlineScriptWithSourceURL: function() | |
314 { | |
315 return !!this.hasSourceURL && this.isInlineScript(); | |
316 }, | |
317 | |
318 /** | |
319 * @param {!Array<!DebuggerAgent.ScriptPosition>} positions | |
320 * @return {!Promise<boolean>} | |
321 */ | |
322 setBlackboxedRanges: function(positions) | |
323 { | |
324 return new Promise(setBlackboxedRanges.bind(this)); | |
325 | |
326 /** | |
327 * @param {function(?)} fulfill | |
328 * @param {function(*)} reject | |
329 * @this {WebInspector.Script} | |
330 */ | |
331 function setBlackboxedRanges(fulfill, reject) | |
332 { | |
333 this.target().debuggerAgent().setBlackboxedRanges(this.scriptId, pos
itions, callback); | |
334 /** | |
335 * @param {?Protocol.Error} error | |
336 */ | |
337 function callback(error) | |
338 { | |
339 if (error) | |
340 console.error(error); | |
341 fulfill(!error); | |
342 } | |
343 } | |
344 }, | |
345 | |
346 __proto__: WebInspector.SDKObject.prototype | |
347 }; | 339 }; |
| 340 |
| 341 WebInspector.Script.sourceURLRegex = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$
/m; |
| 342 |
| 343 |
OLD | NEW |