OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
6 | 6 |
7 (function(global, utils) { | 7 (function(global, utils) { |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 var Int16x8ToString; | 34 var Int16x8ToString; |
35 var Int32x4ToString; | 35 var Int32x4ToString; |
36 var Int8x16ToString; | 36 var Int8x16ToString; |
37 var InternalArray = utils.InternalArray; | 37 var InternalArray = utils.InternalArray; |
38 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); | 38 var internalErrorSymbol = utils.ImportNow("internal_error_symbol"); |
39 var ObjectHasOwnProperty; | 39 var ObjectHasOwnProperty; |
40 var ObjectToString = utils.ImportNow("object_to_string"); | 40 var ObjectToString = utils.ImportNow("object_to_string"); |
41 var Script = utils.ImportNow("Script"); | 41 var Script = utils.ImportNow("Script"); |
42 var stackTraceSymbol = utils.ImportNow("stack_trace_symbol"); | 42 var stackTraceSymbol = utils.ImportNow("stack_trace_symbol"); |
43 var StringIndexOf; | 43 var StringIndexOf; |
44 var StringSubstring; | |
45 var SymbolToString; | 44 var SymbolToString; |
46 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); | 45 var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
47 var Uint16x8ToString; | 46 var Uint16x8ToString; |
48 var Uint32x4ToString; | 47 var Uint32x4ToString; |
49 var Uint8x16ToString; | 48 var Uint8x16ToString; |
50 | 49 |
51 utils.Import(function(from) { | 50 utils.Import(function(from) { |
52 ArrayJoin = from.ArrayJoin; | 51 ArrayJoin = from.ArrayJoin; |
53 Bool16x8ToString = from.Bool16x8ToString; | 52 Bool16x8ToString = from.Bool16x8ToString; |
54 Bool32x4ToString = from.Bool32x4ToString; | 53 Bool32x4ToString = from.Bool32x4ToString; |
55 Bool8x16ToString = from.Bool8x16ToString; | 54 Bool8x16ToString = from.Bool8x16ToString; |
56 Float32x4ToString = from.Float32x4ToString; | 55 Float32x4ToString = from.Float32x4ToString; |
57 Int16x8ToString = from.Int16x8ToString; | 56 Int16x8ToString = from.Int16x8ToString; |
58 Int32x4ToString = from.Int32x4ToString; | 57 Int32x4ToString = from.Int32x4ToString; |
59 Int8x16ToString = from.Int8x16ToString; | 58 Int8x16ToString = from.Int8x16ToString; |
60 ObjectHasOwnProperty = from.ObjectHasOwnProperty; | 59 ObjectHasOwnProperty = from.ObjectHasOwnProperty; |
61 StringIndexOf = from.StringIndexOf; | 60 StringIndexOf = from.StringIndexOf; |
62 StringSubstring = from.StringSubstring; | |
63 SymbolToString = from.SymbolToString; | 61 SymbolToString = from.SymbolToString; |
64 Uint16x8ToString = from.Uint16x8ToString; | 62 Uint16x8ToString = from.Uint16x8ToString; |
65 Uint32x4ToString = from.Uint32x4ToString; | 63 Uint32x4ToString = from.Uint32x4ToString; |
66 Uint8x16ToString = from.Uint8x16ToString; | 64 Uint8x16ToString = from.Uint8x16ToString; |
67 }); | 65 }); |
68 | 66 |
69 // ------------------------------------------------------------------- | 67 // ------------------------------------------------------------------- |
70 | 68 |
71 var GlobalError; | 69 var GlobalError; |
72 var GlobalTypeError; | 70 var GlobalTypeError; |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 function GetSourceLine(message) { | 210 function GetSourceLine(message) { |
213 var script = %MessageGetScript(message); | 211 var script = %MessageGetScript(message); |
214 var start_position = %MessageGetStartPosition(message); | 212 var start_position = %MessageGetStartPosition(message); |
215 var location = script.locationFromPosition(start_position, true); | 213 var location = script.locationFromPosition(start_position, true); |
216 if (location == null) return ""; | 214 if (location == null) return ""; |
217 return location.sourceText; | 215 return location.sourceText; |
218 } | 216 } |
219 | 217 |
220 | 218 |
221 /** | 219 /** |
222 * Find a line number given a specific source position. | |
223 * @param {number} position The source position. | |
224 * @return {number} 0 if input too small, -1 if input too large, | |
225 else the line number. | |
226 */ | |
227 function ScriptLineFromPosition(position) { | |
228 var info = %ScriptPositionInfo(this, position, false); | |
229 return (info == null) ? -1 : info.line; | |
230 } | |
231 | |
232 | |
233 /** | |
234 * Get information on a specific source position. | 220 * Get information on a specific source position. |
235 * Returns an object with the following following properties: | 221 * Returns an object with the following following properties: |
236 * script : script object for the source | 222 * script : script object for the source |
237 * line : source line number | 223 * line : source line number |
238 * column : source column within the line | 224 * column : source column within the line |
239 * position : position within the source | 225 * position : position within the source |
240 * sourceText : a string containing the current line | 226 * sourceText : a string containing the current line |
241 * @param {number} position The source position | 227 * @param {number} position The source position |
242 * @param {boolean} include_resource_offset Set to true to have the resource | 228 * @param {boolean} include_resource_offset Set to true to have the resource |
243 * offset added to the location | 229 * offset added to the location |
244 * @return If line is negative or not in the source null is returned. | 230 * @return If line is negative or not in the source null is returned. |
245 */ | 231 */ |
246 function ScriptLocationFromPosition(position, | 232 function ScriptLocationFromPosition(position, |
247 include_resource_offset) { | 233 include_resource_offset) { |
248 return %ScriptPositionInfo(this, position, !!include_resource_offset); | 234 return %ScriptPositionInfo(this, position, !!include_resource_offset); |
249 } | 235 } |
250 | 236 |
251 | 237 |
252 /** | 238 /** |
253 * Get information on a specific source line and column possibly offset by a | |
254 * fixed source position. This function is used to find a source position from | |
255 * a line and column position. The fixed source position offset is typically | |
256 * used to find a source position in a function based on a line and column in | |
257 * the source for the function alone. The offset passed will then be the | |
258 * start position of the source for the function within the full script source. | |
259 * @param {number} opt_line The line within the source. Default value is 0 | |
260 * @param {number} opt_column The column in within the line. Default value is 0 | |
261 * @param {number} opt_offset_position The offset from the begining of the | |
262 * source from where the line and column calculation starts. | |
263 * Default value is 0 | |
264 * @return If line is negative or not in the source null is returned. | |
265 */ | |
266 function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) { | |
267 // Default is the first line in the script. Lines in the script is relative | |
268 // to the offset within the resource. | |
269 var line = 0; | |
270 if (!IS_UNDEFINED(opt_line)) { | |
271 line = opt_line - this.line_offset; | |
272 } | |
273 | |
274 // Default is first column. If on the first line add the offset within the | |
275 // resource. | |
276 var column = opt_column || 0; | |
277 if (line == 0) { | |
278 column -= this.column_offset; | |
279 } | |
280 | |
281 var offset_position = opt_offset_position || 0; | |
282 if (line < 0 || column < 0 || offset_position < 0) return null; | |
283 if (line == 0) { | |
284 return this.locationFromPosition(offset_position + column, false); | |
285 } else { | |
286 // Find the line where the offset position is located. | |
287 var offset_line = this.lineFromPosition(offset_position); | |
288 | |
289 if (offset_line == -1 || offset_line + line >= this.lineCount()) { | |
290 return null; | |
291 } | |
292 | |
293 return this.locationFromPosition( | |
294 %ScriptLineStartPosition(this, offset_line + line) + column); | |
295 } | |
296 } | |
297 | |
298 | |
299 /** | |
300 * Get a slice of source code from the script. The boundaries for the slice is | |
301 * specified in lines. | |
302 * @param {number} opt_from_line The first line (zero bound) in the slice. | |
303 * Default is 0 | |
304 * @param {number} opt_to_column The last line (zero bound) in the slice (non | |
305 * inclusive). Default is the number of lines in the script | |
306 * @return {SourceSlice} The source slice or null of the parameters where | |
307 * invalid | |
308 */ | |
309 function ScriptSourceSlice(opt_from_line, opt_to_line) { | |
310 var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset | |
311 : opt_from_line; | |
312 var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount() | |
313 : opt_to_line; | |
314 | |
315 // Adjust according to the offset within the resource. | |
316 from_line -= this.line_offset; | |
317 to_line -= this.line_offset; | |
318 if (from_line < 0) from_line = 0; | |
319 if (to_line > this.lineCount()) to_line = this.lineCount(); | |
320 | |
321 // Check parameters. | |
322 if (from_line >= this.lineCount() || | |
323 to_line < 0 || | |
324 from_line > to_line) { | |
325 return null; | |
326 } | |
327 | |
328 var from_position = %ScriptLineStartPosition(this, from_line); | |
329 var to_position = %ScriptLineStartPosition(this, to_line); | |
330 | |
331 // Return a source slice with line numbers re-adjusted to the resource. | |
332 return new SourceSlice(this, | |
333 from_line + this.line_offset, | |
334 to_line + this.line_offset, | |
335 from_position, to_position); | |
336 } | |
337 | |
338 | |
339 function ScriptSourceLine(opt_line) { | |
340 // Default is the first line in the script. Lines in the script are relative | |
341 // to the offset within the resource. | |
342 var line = 0; | |
343 if (!IS_UNDEFINED(opt_line)) { | |
344 line = opt_line - this.line_offset; | |
345 } | |
346 | |
347 // Check parameter. | |
348 if (line < 0 || this.lineCount() <= line) { | |
349 return null; | |
350 } | |
351 | |
352 // Return the source line. | |
353 var start = %ScriptLineStartPosition(this, line); | |
354 var end = %ScriptLineEndPosition(this, line); | |
355 return %_Call(StringSubstring, this.source, start, end); | |
356 } | |
357 | |
358 | |
359 /** | |
360 * Returns the number of source lines. | |
361 * @return {number} | |
362 * Number of source lines. | |
363 */ | |
364 function ScriptLineCount() { | |
365 // Return number of source lines. | |
366 return %ScriptLineCount(this); | |
367 } | |
368 | |
369 | |
370 /** | |
371 * If sourceURL comment is available returns sourceURL comment contents. | 239 * If sourceURL comment is available returns sourceURL comment contents. |
372 * Otherwise, script name is returned. See | 240 * Otherwise, script name is returned. See |
373 * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt | 241 * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt |
374 * and Source Map Revision 3 proposal for details on using //# sourceURL and | 242 * and Source Map Revision 3 proposal for details on using //# sourceURL and |
375 * deprecated //@ sourceURL comment to identify scripts that don't have name. | 243 * deprecated //@ sourceURL comment to identify scripts that don't have name. |
376 * | 244 * |
377 * @return {?string} script name if present, value for //# sourceURL comment or | 245 * @return {?string} script name if present, value for //# sourceURL comment or |
378 * deprecated //@ sourceURL comment otherwise. | 246 * deprecated //@ sourceURL comment otherwise. |
379 */ | 247 */ |
380 function ScriptNameOrSourceURL() { | 248 function ScriptNameOrSourceURL() { |
381 if (this.source_url) return this.source_url; | 249 if (this.source_url) return this.source_url; |
382 return this.name; | 250 return this.name; |
383 } | 251 } |
384 | 252 |
385 | 253 |
386 utils.SetUpLockedPrototype(Script, [ | 254 utils.SetUpLockedPrototype(Script, [ |
387 "source", | 255 "source", |
388 "name", | 256 "name", |
389 "source_url", | 257 "source_url", |
390 "source_mapping_url", | 258 "source_mapping_url", |
391 "line_offset", | 259 "line_offset", |
392 "column_offset" | 260 "column_offset" |
393 ], [ | 261 ], [ |
394 "lineFromPosition", ScriptLineFromPosition, | |
395 "locationFromPosition", ScriptLocationFromPosition, | 262 "locationFromPosition", ScriptLocationFromPosition, |
396 "locationFromLine", ScriptLocationFromLine, | |
397 "sourceSlice", ScriptSourceSlice, | |
398 "sourceLine", ScriptSourceLine, | |
399 "lineCount", ScriptLineCount, | |
400 "nameOrSourceURL", ScriptNameOrSourceURL, | 263 "nameOrSourceURL", ScriptNameOrSourceURL, |
401 ] | 264 ] |
402 ); | 265 ); |
403 | 266 |
404 | 267 |
405 /** | |
406 * Class for a source slice. A source slice is a part of a script source with | |
407 * the following properties: | |
408 * script : script object for the source | |
409 * from_line : line number for the first line in the slice | |
410 * to_line : source line number for the last line in the slice | |
411 * from_position : position of the first character in the slice | |
412 * to_position : position of the last character in the slice | |
413 * The to_line and to_position are not included in the slice, that is the lines | |
414 * in the slice are [from_line, to_line[. Likewise the characters in the slice | |
415 * are [from_position, to_position[. | |
416 * @param {Script} script The Script object for the source slice | |
417 * @param {number} from_line | |
418 * @param {number} to_line | |
419 * @param {number} from_position | |
420 * @param {number} to_position | |
421 * @constructor | |
422 */ | |
423 function SourceSlice(script, from_line, to_line, from_position, to_position) { | |
424 this.script = script; | |
425 this.from_line = from_line; | |
426 this.to_line = to_line; | |
427 this.from_position = from_position; | |
428 this.to_position = to_position; | |
429 } | |
430 | |
431 /** | |
432 * Get the source text for a SourceSlice | |
433 * @return {String} Source text for this slice. The last line will include | |
434 * the line terminating characters (if any) | |
435 */ | |
436 function SourceSliceSourceText() { | |
437 return %_Call(StringSubstring, | |
438 this.script.source, | |
439 this.from_position, | |
440 this.to_position); | |
441 } | |
442 | |
443 utils.SetUpLockedPrototype(SourceSlice, | |
444 ["script", "from_line", "to_line", "from_position", "to_position"], | |
445 ["sourceText", SourceSliceSourceText] | |
446 ); | |
447 | |
448 | |
449 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 268 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
450 return new CallSite(recv, fun, pos, false).toString(); | 269 return new CallSite(recv, fun, pos, false).toString(); |
451 } | 270 } |
452 | 271 |
453 // ---------------------------------------------------------------------------- | 272 // ---------------------------------------------------------------------------- |
454 // Error implementation | 273 // Error implementation |
455 | 274 |
456 function CallSite(receiver, fun, pos, strict_mode) { | 275 function CallSite(receiver, fun, pos, strict_mode) { |
457 // For wasm frames, receiver is the wasm object and fun is the function index | 276 // For wasm frames, receiver is the wasm object and fun is the function index |
458 // instead of an actual function. | 277 // instead of an actual function. |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 utils.Export(function(to) { | 756 utils.Export(function(to) { |
938 to.ErrorToString = ErrorToString; | 757 to.ErrorToString = ErrorToString; |
939 to.MakeError = MakeError; | 758 to.MakeError = MakeError; |
940 to.MakeRangeError = MakeRangeError; | 759 to.MakeRangeError = MakeRangeError; |
941 to.MakeSyntaxError = MakeSyntaxError; | 760 to.MakeSyntaxError = MakeSyntaxError; |
942 to.MakeTypeError = MakeTypeError; | 761 to.MakeTypeError = MakeTypeError; |
943 to.MakeURIError = MakeURIError; | 762 to.MakeURIError = MakeURIError; |
944 }); | 763 }); |
945 | 764 |
946 }); | 765 }); |
OLD | NEW |