OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 387 |
388 // Adjust according to the offset within the resource. | 388 // Adjust according to the offset within the resource. |
389 if (include_resource_offset) { | 389 if (include_resource_offset) { |
390 line += this.line_offset; | 390 line += this.line_offset; |
391 if (line == this.line_offset) { | 391 if (line == this.line_offset) { |
392 column += this.column_offset; | 392 column += this.column_offset; |
393 } | 393 } |
394 } | 394 } |
395 | 395 |
396 return new SourceLocation(this, position, line, column, start, end); | 396 return new SourceLocation(this, position, line, column, start, end); |
397 }; | 397 } |
398 | 398 |
399 | 399 |
400 /** | 400 /** |
401 * Get information on a specific source line and column possibly offset by a | 401 * Get information on a specific source line and column possibly offset by a |
402 * fixed source position. This function is used to find a source position from | 402 * fixed source position. This function is used to find a source position from |
403 * a line and column position. The fixed source position offset is typically | 403 * a line and column position. The fixed source position offset is typically |
404 * used to find a source position in a function based on a line and column in | 404 * used to find a source position in a function based on a line and column in |
405 * the source for the function alone. The offset passed will then be the | 405 * the source for the function alone. The offset passed will then be the |
406 * start position of the source for the function within the full script source. | 406 * start position of the source for the function within the full script source. |
407 * @param {number} opt_line The line within the source. Default value is 0 | 407 * @param {number} opt_line The line within the source. Default value is 0 |
408 * @param {number} opt_column The column in within the line. Default value is 0 | 408 * @param {number} opt_column The column in within the line. Default value is 0 |
409 * @param {number} opt_offset_position The offset from the begining of the | 409 * @param {number} opt_offset_position The offset from the begining of the |
410 * source from where the line and column calculation starts. | 410 * source from where the line and column calculation starts. |
411 * Default value is 0 | 411 * Default value is 0 |
412 * @return {SourceLocation} | 412 * @return {SourceLocation} |
413 * If line is negative or not in the source null is returned. | 413 * If line is negative or not in the source null is returned. |
414 */ | 414 */ |
415 function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) { | 415 function ScriptLocationFromLine(opt_line, opt_column, opt_offset_position) { |
416 // Default is the first line in the script. Lines in the script is relative | 416 // Default is the first line in the script. Lines in the script is relative |
417 // to the offset within the resource. | 417 // to the offset within the resource. |
418 var line = 0; | 418 var line = 0; |
419 if (!IS_UNDEFINED(opt_line)) { | 419 if (!IS_UNDEFINED(opt_line)) { |
420 line = opt_line - this.line_offset; | 420 line = opt_line - this.line_offset; |
421 } | 421 } |
422 | 422 |
423 // Default is first column. If on the first line add the offset within the | 423 // Default is first column. If on the first line add the offset within the |
424 // resource. | 424 // resource. |
425 var column = opt_column || 0; | 425 var column = opt_column || 0; |
426 if (line == 0) { | 426 if (line == 0) { |
427 column -= this.column_offset | 427 column -= this.column_offset; |
428 } | 428 } |
429 | 429 |
430 var offset_position = opt_offset_position || 0; | 430 var offset_position = opt_offset_position || 0; |
431 if (line < 0 || column < 0 || offset_position < 0) return null; | 431 if (line < 0 || column < 0 || offset_position < 0) return null; |
432 if (line == 0) { | 432 if (line == 0) { |
433 return this.locationFromPosition(offset_position + column, false); | 433 return this.locationFromPosition(offset_position + column, false); |
434 } else { | 434 } else { |
435 // Find the line where the offset position is located. | 435 // Find the line where the offset position is located. |
436 var offset_line = this.lineFromPosition(offset_position); | 436 var offset_line = this.lineFromPosition(offset_position); |
437 | 437 |
438 if (offset_line == -1 || offset_line + line >= this.lineCount()) { | 438 if (offset_line == -1 || offset_line + line >= this.lineCount()) { |
439 return null; | 439 return null; |
440 } | 440 } |
441 | 441 |
442 return this.locationFromPosition(this.line_ends[offset_line + line - 1] + 1
+ column); // line > 0 here. | 442 return this.locationFromPosition( |
| 443 this.line_ends[offset_line + line - 1] + 1 + column); // line > 0 here. |
443 } | 444 } |
444 } | 445 } |
445 | 446 |
446 | 447 |
447 /** | 448 /** |
448 * Get a slice of source code from the script. The boundaries for the slice is | 449 * Get a slice of source code from the script. The boundaries for the slice is |
449 * specified in lines. | 450 * specified in lines. |
450 * @param {number} opt_from_line The first line (zero bound) in the slice. | 451 * @param {number} opt_from_line The first line (zero bound) in the slice. |
451 * Default is 0 | 452 * Default is 0 |
452 * @param {number} opt_to_column The last line (zero bound) in the slice (non | 453 * @param {number} opt_to_column The last line (zero bound) in the slice (non |
453 * inclusive). Default is the number of lines in the script | 454 * inclusive). Default is the number of lines in the script |
454 * @return {SourceSlice} The source slice or null of the parameters where | 455 * @return {SourceSlice} The source slice or null of the parameters where |
455 * invalid | 456 * invalid |
456 */ | 457 */ |
457 function ScriptSourceSlice(opt_from_line, opt_to_line) { | 458 function ScriptSourceSlice(opt_from_line, opt_to_line) { |
458 var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset : opt_from_line
; | 459 var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset |
459 var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount()
: opt_to_line | 460 : opt_from_line; |
| 461 var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount() |
| 462 : opt_to_line; |
460 | 463 |
461 // Adjust according to the offset within the resource. | 464 // Adjust according to the offset within the resource. |
462 from_line -= this.line_offset; | 465 from_line -= this.line_offset; |
463 to_line -= this.line_offset; | 466 to_line -= this.line_offset; |
464 if (from_line < 0) from_line = 0; | 467 if (from_line < 0) from_line = 0; |
465 if (to_line > this.lineCount()) to_line = this.lineCount(); | 468 if (to_line > this.lineCount()) to_line = this.lineCount(); |
466 | 469 |
467 // Check parameters. | 470 // Check parameters. |
468 if (from_line >= this.lineCount() || | 471 if (from_line >= this.lineCount() || |
469 to_line < 0 || | 472 to_line < 0 || |
470 from_line > to_line) { | 473 from_line > to_line) { |
471 return null; | 474 return null; |
472 } | 475 } |
473 | 476 |
474 var line_ends = this.line_ends; | 477 var line_ends = this.line_ends; |
475 var from_position = from_line == 0 ? 0 : line_ends[from_line - 1] + 1; | 478 var from_position = from_line == 0 ? 0 : line_ends[from_line - 1] + 1; |
476 var to_position = to_line == 0 ? 0 : line_ends[to_line - 1] + 1; | 479 var to_position = to_line == 0 ? 0 : line_ends[to_line - 1] + 1; |
477 | 480 |
478 // Return a source slice with line numbers re-adjusted to the resource. | 481 // Return a source slice with line numbers re-adjusted to the resource. |
479 return new SourceSlice(this, from_line + this.line_offset, to_line + this.line
_offset, | 482 return new SourceSlice(this, |
480 from_position, to_position); | 483 from_line + this.line_offset, |
| 484 to_line + this.line_offset, |
| 485 from_position, to_position); |
481 } | 486 } |
482 | 487 |
483 | 488 |
484 function ScriptSourceLine(opt_line) { | 489 function ScriptSourceLine(opt_line) { |
485 // Default is the first line in the script. Lines in the script are relative | 490 // Default is the first line in the script. Lines in the script are relative |
486 // to the offset within the resource. | 491 // to the offset within the resource. |
487 var line = 0; | 492 var line = 0; |
488 if (!IS_UNDEFINED(opt_line)) { | 493 if (!IS_UNDEFINED(opt_line)) { |
489 line = opt_line - this.line_offset; | 494 line = opt_line - this.line_offset; |
490 } | 495 } |
(...skipping 12 matching lines...) Expand all Loading... |
503 | 508 |
504 | 509 |
505 /** | 510 /** |
506 * Returns the number of source lines. | 511 * Returns the number of source lines. |
507 * @return {number} | 512 * @return {number} |
508 * Number of source lines. | 513 * Number of source lines. |
509 */ | 514 */ |
510 function ScriptLineCount() { | 515 function ScriptLineCount() { |
511 // Return number of source lines. | 516 // Return number of source lines. |
512 return this.line_ends.length; | 517 return this.line_ends.length; |
513 }; | 518 } |
514 | 519 |
515 | 520 |
516 /** | 521 /** |
517 * Returns the name of script if available, contents of sourceURL comment | 522 * Returns the name of script if available, contents of sourceURL comment |
518 * otherwise. See | 523 * otherwise. See |
519 * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt | 524 * http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt |
520 * for details on using //@ sourceURL comment to identify scritps that don't | 525 * for details on using //@ sourceURL comment to identify scritps that don't |
521 * have name. | 526 * have name. |
522 * | 527 * |
523 * @return {?string} script name if present, value for //@ sourceURL comment | 528 * @return {?string} script name if present, value for //@ sourceURL comment |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 | 573 |
569 /** | 574 /** |
570 * Class for source location. A source location is a position within some | 575 * Class for source location. A source location is a position within some |
571 * source with the following properties: | 576 * source with the following properties: |
572 * script : script object for the source | 577 * script : script object for the source |
573 * line : source line number | 578 * line : source line number |
574 * column : source column within the line | 579 * column : source column within the line |
575 * position : position within the source | 580 * position : position within the source |
576 * start : position of start of source context (inclusive) | 581 * start : position of start of source context (inclusive) |
577 * end : position of end of source context (not inclusive) | 582 * end : position of end of source context (not inclusive) |
578 * Source text for the source context is the character interval [start, end[. In | 583 * Source text for the source context is the character interval |
579 * most cases end will point to a newline character. It might point just past | 584 * [start, end[. In most cases end will point to a newline character. |
580 * the final position of the source if the last source line does not end with a | 585 * It might point just past the final position of the source if the last |
581 * newline character. | 586 * source line does not end with a newline character. |
582 * @param {Script} script The Script object for which this is a location | 587 * @param {Script} script The Script object for which this is a location |
583 * @param {number} position Source position for the location | 588 * @param {number} position Source position for the location |
584 * @param {number} line The line number for the location | 589 * @param {number} line The line number for the location |
585 * @param {number} column The column within the line for the location | 590 * @param {number} column The column within the line for the location |
586 * @param {number} start Source position for start of source context | 591 * @param {number} start Source position for start of source context |
587 * @param {number} end Source position for end of source context | 592 * @param {number} end Source position for end of source context |
588 * @constructor | 593 * @constructor |
589 */ | 594 */ |
590 function SourceLocation(script, position, line, column, start, end) { | 595 function SourceLocation(script, position, line, column, start, end) { |
591 this.script = script; | 596 this.script = script; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 var end_limit = this.position + limit - before; | 643 var end_limit = this.position + limit - before; |
639 if (this.start < start_limit && end_limit < this.end) { | 644 if (this.start < start_limit && end_limit < this.end) { |
640 this.start = start_limit; | 645 this.start = start_limit; |
641 this.end = end_limit; | 646 this.end = end_limit; |
642 } else if (this.start < start_limit) { | 647 } else if (this.start < start_limit) { |
643 this.start = this.end - limit; | 648 this.start = this.end - limit; |
644 } else { | 649 } else { |
645 this.end = this.start + limit; | 650 this.end = this.start + limit; |
646 } | 651 } |
647 } | 652 } |
648 }; | 653 } |
649 | 654 |
650 | 655 |
651 /** | 656 /** |
652 * Get the source text for a SourceLocation | 657 * Get the source text for a SourceLocation |
653 * @return {String} | 658 * @return {String} |
654 * Source text for this location. | 659 * Source text for this location. |
655 */ | 660 */ |
656 function SourceLocationSourceText() { | 661 function SourceLocationSourceText() { |
657 return %_CallFunction(this.script.source, this.start, this.end, StringSubstrin
g); | 662 return %_CallFunction(this.script.source, |
658 }; | 663 this.start, |
| 664 this.end, |
| 665 StringSubstring); |
| 666 } |
659 | 667 |
660 | 668 |
661 SetUpLockedPrototype(SourceLocation, | 669 SetUpLockedPrototype(SourceLocation, |
662 $Array("script", "position", "line", "column", "start", "end"), | 670 $Array("script", "position", "line", "column", "start", "end"), |
663 $Array( | 671 $Array( |
664 "restrict", SourceLocationRestrict, | 672 "restrict", SourceLocationRestrict, |
665 "sourceText", SourceLocationSourceText | 673 "sourceText", SourceLocationSourceText |
666 ) | 674 ) |
667 ); | 675 ); |
668 | 676 |
669 | 677 |
670 /** | 678 /** |
671 * Class for a source slice. A source slice is a part of a script source with | 679 * Class for a source slice. A source slice is a part of a script source with |
672 * the following properties: | 680 * the following properties: |
673 * script : script object for the source | 681 * script : script object for the source |
674 * from_line : line number for the first line in the slice | 682 * from_line : line number for the first line in the slice |
675 * to_line : source line number for the last line in the slice | 683 * to_line : source line number for the last line in the slice |
676 * from_position : position of the first character in the slice | 684 * from_position : position of the first character in the slice |
(...skipping 19 matching lines...) Expand all Loading... |
696 /** | 704 /** |
697 * Get the source text for a SourceSlice | 705 * Get the source text for a SourceSlice |
698 * @return {String} Source text for this slice. The last line will include | 706 * @return {String} Source text for this slice. The last line will include |
699 * the line terminating characters (if any) | 707 * the line terminating characters (if any) |
700 */ | 708 */ |
701 function SourceSliceSourceText() { | 709 function SourceSliceSourceText() { |
702 return %_CallFunction(this.script.source, | 710 return %_CallFunction(this.script.source, |
703 this.from_position, | 711 this.from_position, |
704 this.to_position, | 712 this.to_position, |
705 StringSubstring); | 713 StringSubstring); |
706 }; | 714 } |
707 | 715 |
708 SetUpLockedPrototype(SourceSlice, | 716 SetUpLockedPrototype(SourceSlice, |
709 $Array("script", "from_line", "to_line", "from_position", "to_position"), | 717 $Array("script", "from_line", "to_line", "from_position", "to_position"), |
710 $Array("sourceText", SourceSliceSourceText) | 718 $Array("sourceText", SourceSliceSourceText) |
711 ); | 719 ); |
712 | 720 |
713 | 721 |
714 // Returns the offset of the given position within the containing | 722 // Returns the offset of the given position within the containing |
715 // line. | 723 // line. |
716 function GetPositionInLine(message) { | 724 function GetPositionInLine(message) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 } | 763 } |
756 | 764 |
757 function CallSite(receiver, fun, pos) { | 765 function CallSite(receiver, fun, pos) { |
758 this.receiver = receiver; | 766 this.receiver = receiver; |
759 this.fun = fun; | 767 this.fun = fun; |
760 this.pos = pos; | 768 this.pos = pos; |
761 } | 769 } |
762 | 770 |
763 function CallSiteGetThis() { | 771 function CallSiteGetThis() { |
764 return this.receiver; | 772 return this.receiver; |
765 }; | 773 } |
766 | 774 |
767 function CallSiteGetTypeName() { | 775 function CallSiteGetTypeName() { |
768 var constructor = this.receiver.constructor; | 776 var constructor = this.receiver.constructor; |
769 if (!constructor) { | 777 if (!constructor) { |
770 return %_CallFunction(this.receiver, ObjectToString); | 778 return %_CallFunction(this.receiver, ObjectToString); |
771 } | 779 } |
772 var constructorName = constructor.name; | 780 var constructorName = constructor.name; |
773 if (!constructorName) { | 781 if (!constructorName) { |
774 return %_CallFunction(this.receiver, ObjectToString); | 782 return %_CallFunction(this.receiver, ObjectToString); |
775 } | 783 } |
776 return constructorName; | 784 return constructorName; |
777 }; | 785 } |
778 | 786 |
779 function CallSiteIsToplevel() { | 787 function CallSiteIsToplevel() { |
780 if (this.receiver == null) { | 788 if (this.receiver == null) { |
781 return true; | 789 return true; |
782 } | 790 } |
783 return IS_GLOBAL(this.receiver); | 791 return IS_GLOBAL(this.receiver); |
784 }; | 792 } |
785 | 793 |
786 function CallSiteIsEval() { | 794 function CallSiteIsEval() { |
787 var script = %FunctionGetScript(this.fun); | 795 var script = %FunctionGetScript(this.fun); |
788 return script && script.compilation_type == COMPILATION_TYPE_EVAL; | 796 return script && script.compilation_type == COMPILATION_TYPE_EVAL; |
789 }; | 797 } |
790 | 798 |
791 function CallSiteGetEvalOrigin() { | 799 function CallSiteGetEvalOrigin() { |
792 var script = %FunctionGetScript(this.fun); | 800 var script = %FunctionGetScript(this.fun); |
793 return FormatEvalOrigin(script); | 801 return FormatEvalOrigin(script); |
794 }; | 802 } |
795 | 803 |
796 function CallSiteGetScriptNameOrSourceURL() { | 804 function CallSiteGetScriptNameOrSourceURL() { |
797 var script = %FunctionGetScript(this.fun); | 805 var script = %FunctionGetScript(this.fun); |
798 return script ? script.nameOrSourceURL() : null; | 806 return script ? script.nameOrSourceURL() : null; |
799 }; | 807 } |
800 | 808 |
801 function CallSiteGetFunction() { | 809 function CallSiteGetFunction() { |
802 return this.fun; | 810 return this.fun; |
803 }; | 811 } |
804 | 812 |
805 function CallSiteGetFunctionName() { | 813 function CallSiteGetFunctionName() { |
806 // See if the function knows its own name | 814 // See if the function knows its own name |
807 var name = this.fun.name; | 815 var name = this.fun.name; |
808 if (name) { | 816 if (name) { |
809 return name; | 817 return name; |
810 } else { | 818 } else { |
811 return %FunctionGetInferredName(this.fun); | 819 return %FunctionGetInferredName(this.fun); |
812 } | 820 } |
813 // Maybe this is an evaluation? | 821 // Maybe this is an evaluation? |
814 var script = %FunctionGetScript(this.fun); | 822 var script = %FunctionGetScript(this.fun); |
815 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { | 823 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { |
816 return "eval"; | 824 return "eval"; |
817 } | 825 } |
818 return null; | 826 return null; |
819 }; | 827 } |
820 | 828 |
821 function CallSiteGetMethodName() { | 829 function CallSiteGetMethodName() { |
822 // See if we can find a unique property on the receiver that holds | 830 // See if we can find a unique property on the receiver that holds |
823 // this function. | 831 // this function. |
824 var ownName = this.fun.name; | 832 var ownName = this.fun.name; |
825 if (ownName && this.receiver && | 833 if (ownName && this.receiver && |
826 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun |
| | 834 (%_CallFunction(this.receiver, |
827 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun |
| | 835 ownName, |
| 836 ObjectLookupGetter) === this.fun || |
| 837 %_CallFunction(this.receiver, |
| 838 ownName, |
| 839 ObjectLookupSetter) === this.fun || |
828 this.receiver[ownName] === this.fun)) { | 840 this.receiver[ownName] === this.fun)) { |
829 // To handle DontEnum properties we guess that the method has | 841 // To handle DontEnum properties we guess that the method has |
830 // the same name as the function. | 842 // the same name as the function. |
831 return ownName; | 843 return ownName; |
832 } | 844 } |
833 var name = null; | 845 var name = null; |
834 for (var prop in this.receiver) { | 846 for (var prop in this.receiver) { |
835 if (this.receiver.__lookupGetter__(prop) === this.fun || | 847 if (this.receiver.__lookupGetter__(prop) === this.fun || |
836 this.receiver.__lookupSetter__(prop) === this.fun || | 848 this.receiver.__lookupSetter__(prop) === this.fun || |
837 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f
un)) { | 849 (!this.receiver.__lookupGetter__(prop) && |
| 850 this.receiver[prop] === this.fun)) { |
838 // If we find more than one match bail out to avoid confusion. | 851 // If we find more than one match bail out to avoid confusion. |
839 if (name) { | 852 if (name) { |
840 return null; | 853 return null; |
841 } | 854 } |
842 name = prop; | 855 name = prop; |
843 } | 856 } |
844 } | 857 } |
845 if (name) { | 858 if (name) { |
846 return name; | 859 return name; |
847 } | 860 } |
848 return null; | 861 return null; |
849 }; | 862 } |
850 | 863 |
851 function CallSiteGetFileName() { | 864 function CallSiteGetFileName() { |
852 var script = %FunctionGetScript(this.fun); | 865 var script = %FunctionGetScript(this.fun); |
853 return script ? script.name : null; | 866 return script ? script.name : null; |
854 }; | 867 } |
855 | 868 |
856 function CallSiteGetLineNumber() { | 869 function CallSiteGetLineNumber() { |
857 if (this.pos == -1) { | 870 if (this.pos == -1) { |
858 return null; | 871 return null; |
859 } | 872 } |
860 var script = %FunctionGetScript(this.fun); | 873 var script = %FunctionGetScript(this.fun); |
861 var location = null; | 874 var location = null; |
862 if (script) { | 875 if (script) { |
863 location = script.locationFromPosition(this.pos, true); | 876 location = script.locationFromPosition(this.pos, true); |
864 } | 877 } |
865 return location ? location.line + 1 : null; | 878 return location ? location.line + 1 : null; |
866 }; | 879 } |
867 | 880 |
868 function CallSiteGetColumnNumber() { | 881 function CallSiteGetColumnNumber() { |
869 if (this.pos == -1) { | 882 if (this.pos == -1) { |
870 return null; | 883 return null; |
871 } | 884 } |
872 var script = %FunctionGetScript(this.fun); | 885 var script = %FunctionGetScript(this.fun); |
873 var location = null; | 886 var location = null; |
874 if (script) { | 887 if (script) { |
875 location = script.locationFromPosition(this.pos, true); | 888 location = script.locationFromPosition(this.pos, true); |
876 } | 889 } |
877 return location ? location.column + 1: null; | 890 return location ? location.column + 1: null; |
878 }; | 891 } |
879 | 892 |
880 function CallSiteIsNative() { | 893 function CallSiteIsNative() { |
881 var script = %FunctionGetScript(this.fun); | 894 var script = %FunctionGetScript(this.fun); |
882 return script ? (script.type == TYPE_NATIVE) : false; | 895 return script ? (script.type == TYPE_NATIVE) : false; |
883 }; | 896 } |
884 | 897 |
885 function CallSiteGetPosition() { | 898 function CallSiteGetPosition() { |
886 return this.pos; | 899 return this.pos; |
887 }; | 900 } |
888 | 901 |
889 function CallSiteIsConstructor() { | 902 function CallSiteIsConstructor() { |
890 var constructor = this.receiver ? this.receiver.constructor : null; | 903 var constructor = this.receiver ? this.receiver.constructor : null; |
891 if (!constructor) { | 904 if (!constructor) { |
892 return false; | 905 return false; |
893 } | 906 } |
894 return this.fun === constructor; | 907 return this.fun === constructor; |
895 }; | 908 } |
896 | 909 |
897 SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array( | 910 SetUpLockedPrototype(CallSite, $Array("receiver", "fun", "pos"), $Array( |
898 "getThis", CallSiteGetThis, | 911 "getThis", CallSiteGetThis, |
899 "getTypeName", CallSiteGetTypeName, | 912 "getTypeName", CallSiteGetTypeName, |
900 "isToplevel", CallSiteIsToplevel, | 913 "isToplevel", CallSiteIsToplevel, |
901 "isEval", CallSiteIsEval, | 914 "isEval", CallSiteIsEval, |
902 "getEvalOrigin", CallSiteGetEvalOrigin, | 915 "getEvalOrigin", CallSiteGetEvalOrigin, |
903 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, | 916 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, |
904 "getFunction", CallSiteGetFunction, | 917 "getFunction", CallSiteGetFunction, |
905 "getFunctionName", CallSiteGetFunctionName, | 918 "getFunctionName", CallSiteGetFunctionName, |
(...skipping 22 matching lines...) Expand all Loading... |
928 | 941 |
929 var eval_from_script = script.eval_from_script; | 942 var eval_from_script = script.eval_from_script; |
930 if (eval_from_script) { | 943 if (eval_from_script) { |
931 if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { | 944 if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) { |
932 // eval script originated from another eval. | 945 // eval script originated from another eval. |
933 eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")"; | 946 eval_origin += " (" + FormatEvalOrigin(eval_from_script) + ")"; |
934 } else { | 947 } else { |
935 // eval script originated from "real" source. | 948 // eval script originated from "real" source. |
936 if (eval_from_script.name) { | 949 if (eval_from_script.name) { |
937 eval_origin += " (" + eval_from_script.name; | 950 eval_origin += " (" + eval_from_script.name; |
938 var location = eval_from_script.locationFromPosition(script.eval_from_sc
ript_position, true); | 951 var location = eval_from_script.locationFromPosition( |
| 952 script.eval_from_script_position, true); |
939 if (location) { | 953 if (location) { |
940 eval_origin += ":" + (location.line + 1); | 954 eval_origin += ":" + (location.line + 1); |
941 eval_origin += ":" + (location.column + 1); | 955 eval_origin += ":" + (location.column + 1); |
942 } | 956 } |
943 eval_origin += ")" | 957 eval_origin += ")"; |
944 } else { | 958 } else { |
945 eval_origin += " (unknown source)"; | 959 eval_origin += " (unknown source)"; |
946 } | 960 } |
947 } | 961 } |
948 } | 962 } |
949 | 963 |
950 return eval_origin; | 964 return eval_origin; |
951 }; | 965 } |
952 | 966 |
953 function FormatSourcePosition(frame) { | 967 function FormatSourcePosition(frame) { |
954 var fileName; | 968 var fileName; |
955 var fileLocation = ""; | 969 var fileLocation = ""; |
956 if (frame.isNative()) { | 970 if (frame.isNative()) { |
957 fileLocation = "native"; | 971 fileLocation = "native"; |
958 } else if (frame.isEval()) { | 972 } else if (frame.isEval()) { |
959 fileName = frame.getScriptNameOrSourceURL(); | 973 fileName = frame.getScriptNameOrSourceURL(); |
960 if (!fileName) | 974 if (!fileName) { |
961 fileLocation = frame.getEvalOrigin(); | 975 fileLocation = frame.getEvalOrigin(); |
| 976 } |
962 } else { | 977 } else { |
963 fileName = frame.getFileName(); | 978 fileName = frame.getFileName(); |
964 } | 979 } |
965 | 980 |
966 if (fileName) { | 981 if (fileName) { |
967 fileLocation += fileName; | 982 fileLocation += fileName; |
968 var lineNumber = frame.getLineNumber(); | 983 var lineNumber = frame.getLineNumber(); |
969 if (lineNumber != null) { | 984 if (lineNumber != null) { |
970 fileLocation += ":" + lineNumber; | 985 fileLocation += ":" + lineNumber; |
971 var columnNumber = frame.getColumnNumber(); | 986 var columnNumber = frame.getColumnNumber(); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; | 1075 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; |
1061 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { | 1076 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { |
1062 stackTraceLimit = 10000; | 1077 stackTraceLimit = 10000; |
1063 } | 1078 } |
1064 var raw_stack = %CollectStackTrace(cons_opt | 1079 var raw_stack = %CollectStackTrace(cons_opt |
1065 ? cons_opt | 1080 ? cons_opt |
1066 : captureStackTrace, stackTraceLimit); | 1081 : captureStackTrace, stackTraceLimit); |
1067 DefineOneShotAccessor(obj, 'stack', function (obj) { | 1082 DefineOneShotAccessor(obj, 'stack', function (obj) { |
1068 return FormatRawStackTrace(obj, raw_stack); | 1083 return FormatRawStackTrace(obj, raw_stack); |
1069 }); | 1084 }); |
1070 }; | 1085 } |
1071 | 1086 |
1072 | 1087 |
1073 function SetUpError() { | 1088 function SetUpError() { |
1074 // Define special error type constructors. | 1089 // Define special error type constructors. |
1075 | 1090 |
1076 function DefineError(f) { | 1091 function DefineError(f) { |
1077 // Store the error function in both the global object | 1092 // Store the error function in both the global object |
1078 // and the runtime object. The function is fetched | 1093 // and the runtime object. The function is fetched |
1079 // from the runtime object when throwing errors from | 1094 // from the runtime object when throwing errors from |
1080 // within the runtime system to avoid strange side | 1095 // within the runtime system to avoid strange side |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1150 | 1165 |
1151 // Global list of error objects visited during ErrorToString. This is | 1166 // Global list of error objects visited during ErrorToString. This is |
1152 // used to detect cycles in error toString formatting. | 1167 // used to detect cycles in error toString formatting. |
1153 const visited_errors = new InternalArray(); | 1168 const visited_errors = new InternalArray(); |
1154 const cyclic_error_marker = new $Object(); | 1169 const cyclic_error_marker = new $Object(); |
1155 | 1170 |
1156 function ErrorToStringDetectCycle(error) { | 1171 function ErrorToStringDetectCycle(error) { |
1157 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; | 1172 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; |
1158 try { | 1173 try { |
1159 var type = error.type; | 1174 var type = error.type; |
1160 var name = error.name | 1175 var name = error.name; |
1161 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); | 1176 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); |
1162 var message = error.message; | 1177 var message = error.message; |
1163 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); | 1178 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); |
1164 if (type && !hasMessage) { | 1179 if (type && !hasMessage) { |
1165 message = FormatMessage(%NewMessageObject(type, error.arguments)); | 1180 message = FormatMessage(%NewMessageObject(type, error.arguments)); |
1166 } | 1181 } |
1167 message = IS_UNDEFINED(message) ? "" : TO_STRING_INLINE(message); | 1182 message = IS_UNDEFINED(message) ? "" : TO_STRING_INLINE(message); |
1168 if (name === "") return message; | 1183 if (name === "") return message; |
1169 if (message === "") return name; | 1184 if (message === "") return name; |
1170 return name + ": " + message; | 1185 return name + ": " + message; |
(...skipping 19 matching lines...) Expand all Loading... |
1190 throw e; | 1205 throw e; |
1191 } | 1206 } |
1192 } | 1207 } |
1193 | 1208 |
1194 | 1209 |
1195 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1210 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
1196 | 1211 |
1197 // Boilerplate for exceptions for stack overflows. Used from | 1212 // Boilerplate for exceptions for stack overflows. Used from |
1198 // Isolate::StackOverflow(). | 1213 // Isolate::StackOverflow(). |
1199 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1214 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |