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 var kMessages = { | 7 var kMessages = { |
8 // Error | 8 // Error |
9 cyclic_proto: ["Cyclic __proto__ value"], | 9 cyclic_proto: ["Cyclic __proto__ value"], |
10 code_gen_from_strings: ["%0"], | 10 code_gen_from_strings: ["%0"], |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return MakeGenericError($ReferenceError, type, [arg]); | 385 return MakeGenericError($ReferenceError, type, [arg]); |
386 } | 386 } |
387 | 387 |
388 /** | 388 /** |
389 * Find a line number given a specific source position. | 389 * Find a line number given a specific source position. |
390 * @param {number} position The source position. | 390 * @param {number} position The source position. |
391 * @return {number} 0 if input too small, -1 if input too large, | 391 * @return {number} 0 if input too small, -1 if input too large, |
392 else the line number. | 392 else the line number. |
393 */ | 393 */ |
394 function ScriptLineFromPosition(position) { | 394 function ScriptLineFromPosition(position) { |
395 var lower = 0; | |
396 var upper = this.lineCount() - 1; | |
397 var line_ends = this.line_ends; | 395 var line_ends = this.line_ends; |
| 396 var upper = line_ends.length - 1; |
| 397 if (upper < 0) return -1; |
398 | 398 |
399 // We'll never find invalid positions so bail right away. | 399 // We'll never find invalid positions so bail right away. |
400 if (position > line_ends[upper]) { | 400 if (position > line_ends[upper]) return -1; |
401 return -1; | 401 if (position <= line_ends[0]) return 0; |
402 } | |
403 | 402 |
404 // This means we don't have to safe-guard indexing line_ends[i - 1]. | 403 var lower = 1; |
405 if (position <= line_ends[0]) { | 404 // Binary search. |
406 return 0; | 405 while (true) { |
407 } | 406 var mid = (upper + lower) >> 1; |
408 | 407 if (position <= line_ends[mid - 1]) { |
409 // Binary search to find line # from position range. | 408 upper = mid - 1; |
410 while (upper >= 1) { | 409 } else if (position > line_ends[mid]){ |
411 var i = (lower + upper) >> 1; | 410 lower = mid + 1; |
412 | |
413 if (position > line_ends[i]) { | |
414 lower = i + 1; | |
415 } else if (position <= line_ends[i - 1]) { | |
416 upper = i - 1; | |
417 } else { | 411 } else { |
418 return i; | 412 return mid; |
419 } | 413 } |
420 } | 414 } |
421 | |
422 return -1; | |
423 } | 415 } |
424 | 416 |
425 /** | 417 /** |
426 * Get information on a specific source position. | 418 * Get information on a specific source position. |
427 * @param {number} position The source position | 419 * @param {number} position The source position |
428 * @param {boolean} include_resource_offset Set to true to have the resource | 420 * @param {boolean} include_resource_offset Set to true to have the resource |
429 * offset added to the location | 421 * offset added to the location |
430 * @return {SourceLocation} | 422 * @return {SourceLocation} |
431 * If line is negative or not in the source null is returned. | 423 * If line is negative or not in the source null is returned. |
432 */ | 424 */ |
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1320 function SetUpStackOverflowBoilerplate() { | 1312 function SetUpStackOverflowBoilerplate() { |
1321 var boilerplate = MakeRangeError('stack_overflow', []); | 1313 var boilerplate = MakeRangeError('stack_overflow', []); |
1322 | 1314 |
1323 %DefineAccessorPropertyUnchecked( | 1315 %DefineAccessorPropertyUnchecked( |
1324 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1316 boilerplate, 'stack', StackTraceGetter, StackTraceSetter, DONT_ENUM); |
1325 | 1317 |
1326 return boilerplate; | 1318 return boilerplate; |
1327 } | 1319 } |
1328 | 1320 |
1329 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1321 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
OLD | NEW |