| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * Find a line number given a specific source position. | 233 * Find a line number given a specific source position. |
| 234 * @param {number} position The source position. | 234 * @param {number} position The source position. |
| 235 * @return {number} 0 if input too small, -1 if input too large, | 235 * @return {number} 0 if input too small, -1 if input too large, |
| 236 else the line number. | 236 else the line number. |
| 237 */ | 237 */ |
| 238 Script.prototype.lineFromPosition = function(position) { | 238 Script.prototype.lineFromPosition = function(position) { |
| 239 var lower = 0; | 239 var lower = 0; |
| 240 var upper = this.lineCount() - 1; | 240 var upper = this.lineCount() - 1; |
| 241 var line_ends = this.line_ends; |
| 241 | 242 |
| 242 // We'll never find invalid positions so bail right away. | 243 // We'll never find invalid positions so bail right away. |
| 243 if (position > this.line_ends[upper]) { | 244 if (position > line_ends[upper]) { |
| 244 return -1; | 245 return -1; |
| 245 } | 246 } |
| 246 | 247 |
| 247 // This means we don't have to safe-guard indexing line_ends[i - 1]. | 248 // This means we don't have to safe-guard indexing line_ends[i - 1]. |
| 248 if (position <= this.line_ends[0]) { | 249 if (position <= line_ends[0]) { |
| 249 return 0; | 250 return 0; |
| 250 } | 251 } |
| 251 | 252 |
| 252 // Binary search to find line # from position range. | 253 // Binary search to find line # from position range. |
| 253 while (upper >= 1) { | 254 while (upper >= 1) { |
| 254 var i = (lower + upper) >> 1; | 255 var i = (lower + upper) >> 1; |
| 255 | 256 |
| 256 if (position > this.line_ends[i]) { | 257 if (position > line_ends[i]) { |
| 257 lower = i + 1; | 258 lower = i + 1; |
| 258 } else if (position <= this.line_ends[i - 1]) { | 259 } else if (position <= line_ends[i - 1]) { |
| 259 upper = i - 1; | 260 upper = i - 1; |
| 260 } else { | 261 } else { |
| 261 return i; | 262 return i; |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 return -1; | 265 return -1; |
| 265 } | 266 } |
| 266 | 267 |
| 267 /** | 268 /** |
| 268 * Get information on a specific source position. | 269 * Get information on a specific source position. |
| 269 * @param {number} position The source position | 270 * @param {number} position The source position |
| 270 * @param {boolean} include_resource_offset Set to true to have the resource | 271 * @param {boolean} include_resource_offset Set to true to have the resource |
| 271 * offset added to the location | 272 * offset added to the location |
| 272 * @return {SourceLocation} | 273 * @return {SourceLocation} |
| 273 * If line is negative or not in the source null is returned. | 274 * If line is negative or not in the source null is returned. |
| 274 */ | 275 */ |
| 275 Script.prototype.locationFromPosition = function (position, | 276 Script.prototype.locationFromPosition = function (position, |
| 276 include_resource_offset) { | 277 include_resource_offset) { |
| 277 var line = this.lineFromPosition(position); | 278 var line = this.lineFromPosition(position); |
| 278 if (line == -1) return null; | 279 if (line == -1) return null; |
| 279 | 280 |
| 280 // Determine start, end and column. | 281 // Determine start, end and column. |
| 281 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; | 282 var line_ends = this.line_ends; |
| 282 var end = this.line_ends[line]; | 283 var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
| 284 var end = line_ends[line]; |
| 283 if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; | 285 if (end > 0 && StringCharAt.call(this.source, end - 1) == '\r') end--; |
| 284 var column = position - start; | 286 var column = position - start; |
| 285 | 287 |
| 286 // Adjust according to the offset within the resource. | 288 // Adjust according to the offset within the resource. |
| 287 if (include_resource_offset) { | 289 if (include_resource_offset) { |
| 288 line += this.line_offset; | 290 line += this.line_offset; |
| 289 if (line == this.line_offset) { | 291 if (line == this.line_offset) { |
| 290 column += this.column_offset; | 292 column += this.column_offset; |
| 291 } | 293 } |
| 292 } | 294 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 if (from_line < 0) from_line = 0; | 363 if (from_line < 0) from_line = 0; |
| 362 if (to_line > this.lineCount()) to_line = this.lineCount(); | 364 if (to_line > this.lineCount()) to_line = this.lineCount(); |
| 363 | 365 |
| 364 // Check parameters. | 366 // Check parameters. |
| 365 if (from_line >= this.lineCount() || | 367 if (from_line >= this.lineCount() || |
| 366 to_line < 0 || | 368 to_line < 0 || |
| 367 from_line > to_line) { | 369 from_line > to_line) { |
| 368 return null; | 370 return null; |
| 369 } | 371 } |
| 370 | 372 |
| 371 var from_position = from_line == 0 ? 0 : this.line_ends[from_line - 1] + 1; | 373 var line_ends = this.line_ends; |
| 372 var to_position = to_line == 0 ? 0 : this.line_ends[to_line - 1] + 1; | 374 var from_position = from_line == 0 ? 0 : line_ends[from_line - 1] + 1; |
| 375 var to_position = to_line == 0 ? 0 : line_ends[to_line - 1] + 1; |
| 373 | 376 |
| 374 // Return a source slice with line numbers re-adjusted to the resource. | 377 // Return a source slice with line numbers re-adjusted to the resource. |
| 375 return new SourceSlice(this, from_line + this.line_offset, to_line + this.line
_offset, | 378 return new SourceSlice(this, from_line + this.line_offset, to_line + this.line
_offset, |
| 376 from_position, to_position); | 379 from_position, to_position); |
| 377 } | 380 } |
| 378 | 381 |
| 379 | 382 |
| 380 Script.prototype.sourceLine = function (opt_line) { | 383 Script.prototype.sourceLine = function (opt_line) { |
| 381 // Default is the first line in the script. Lines in the script are relative | 384 // Default is the first line in the script. Lines in the script are relative |
| 382 // to the offset within the resource. | 385 // to the offset within the resource. |
| 383 var line = 0; | 386 var line = 0; |
| 384 if (!IS_UNDEFINED(opt_line)) { | 387 if (!IS_UNDEFINED(opt_line)) { |
| 385 line = opt_line - this.line_offset; | 388 line = opt_line - this.line_offset; |
| 386 } | 389 } |
| 387 | 390 |
| 388 // Check parameter. | 391 // Check parameter. |
| 389 if (line < 0 || this.lineCount() <= line) { | 392 if (line < 0 || this.lineCount() <= line) { |
| 390 return null; | 393 return null; |
| 391 } | 394 } |
| 392 | 395 |
| 393 // Return the source line. | 396 // Return the source line. |
| 394 var start = line == 0 ? 0 : this.line_ends[line - 1] + 1; | 397 var line_ends = this.line_ends; |
| 395 var end = this.line_ends[line]; | 398 var start = line == 0 ? 0 : line_ends[line - 1] + 1; |
| 399 var end = line_ends[line]; |
| 396 return StringSubstring.call(this.source, start, end); | 400 return StringSubstring.call(this.source, start, end); |
| 397 } | 401 } |
| 398 | 402 |
| 399 | 403 |
| 400 /** | 404 /** |
| 401 * Returns the number of source lines. | 405 * Returns the number of source lines. |
| 402 * @return {number} | 406 * @return {number} |
| 403 * Number of source lines. | 407 * Number of source lines. |
| 404 */ | 408 */ |
| 405 Script.prototype.lineCount = function() { | 409 Script.prototype.lineCount = function() { |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); | 892 return this.name + ": " + FormatMessage({ type: type, args: this.arguments }
); |
| 889 } | 893 } |
| 890 var message = this.message; | 894 var message = this.message; |
| 891 return this.name + (message ? (": " + message) : ""); | 895 return this.name + (message ? (": " + message) : ""); |
| 892 }, DONT_ENUM); | 896 }, DONT_ENUM); |
| 893 | 897 |
| 894 | 898 |
| 895 // Boilerplate for exceptions for stack overflows. Used from | 899 // Boilerplate for exceptions for stack overflows. Used from |
| 896 // Top::StackOverflow(). | 900 // Top::StackOverflow(). |
| 897 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 901 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |