OLD | NEW |
1 // Copyright 2006-2008 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 |
11 // with the distribution. | 11 // with the distribution. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 var kReplacementMarkers = [ "%0", "%1", "%2", "%3" ]; | 51 var kReplacementMarkers = [ "%0", "%1", "%2", "%3" ]; |
52 | 52 |
53 function FormatString(format, message) { | 53 function FormatString(format, message) { |
54 var args = %MessageGetArguments(message); | 54 var args = %MessageGetArguments(message); |
55 var result = ""; | 55 var result = ""; |
56 var arg_num = 0; | 56 var arg_num = 0; |
57 for (var i = 0; i < format.length; i++) { | 57 for (var i = 0; i < format.length; i++) { |
58 var str = format[i]; | 58 var str = format[i]; |
59 for (arg_num = 0; arg_num < kReplacementMarkers.length; arg_num++) { | 59 for (arg_num = 0; arg_num < kReplacementMarkers.length; arg_num++) { |
60 if (format[i] !== kReplacementMarkers[arg_num]) continue; | 60 if (str !== kReplacementMarkers[arg_num]) continue; |
61 try { | 61 try { |
62 str = ToDetailString(args[arg_num]); | 62 str = ToDetailString(args[arg_num]); |
63 } catch (e) { | 63 } catch (e) { |
64 str = "#<error>"; | 64 str = "#<error>"; |
65 } | 65 } |
66 } | 66 } |
67 result += str; | 67 result += str; |
68 } | 68 } |
69 return result; | 69 return result; |
70 } | 70 } |
(...skipping 22 matching lines...) Expand all Loading... |
93 function ToStringCheckErrorObject(obj) { | 93 function ToStringCheckErrorObject(obj) { |
94 if (IsNativeErrorObject(obj)) { | 94 if (IsNativeErrorObject(obj)) { |
95 return %_CallFunction(obj, errorToString); | 95 return %_CallFunction(obj, errorToString); |
96 } else { | 96 } else { |
97 return ToString(obj); | 97 return ToString(obj); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 function ToDetailString(obj) { | 102 function ToDetailString(obj) { |
103 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri
ng) { | 103 if (obj != null && IS_OBJECT(obj) && |
| 104 obj.toString === $Object.prototype.toString) { |
104 var constructor = obj.constructor; | 105 var constructor = obj.constructor; |
105 if (!constructor) return ToStringCheckErrorObject(obj); | 106 if (!constructor) return ToStringCheckErrorObject(obj); |
106 var constructorName = constructor.name; | 107 var constructorName = constructor.name; |
107 if (!constructorName || !IS_STRING(constructorName)) { | 108 if (!constructorName || !IS_STRING(constructorName)) { |
108 return ToStringCheckErrorObject(obj); | 109 return ToStringCheckErrorObject(obj); |
109 } | 110 } |
110 return "#<" + constructorName + ">"; | 111 return "#<" + constructorName + ">"; |
111 } else { | 112 } else { |
112 return ToStringCheckErrorObject(obj); | 113 return ToStringCheckErrorObject(obj); |
113 } | 114 } |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
553 */ | 554 */ |
554 function SourceLocation(script, position, line, column, start, end) { | 555 function SourceLocation(script, position, line, column, start, end) { |
555 this.script = script; | 556 this.script = script; |
556 this.position = position; | 557 this.position = position; |
557 this.line = line; | 558 this.line = line; |
558 this.column = column; | 559 this.column = column; |
559 this.start = start; | 560 this.start = start; |
560 this.end = end; | 561 this.end = end; |
561 } | 562 } |
562 | 563 |
| 564 SourceLocation.prototype.__proto__ = null; |
563 | 565 |
564 const kLineLengthLimit = 78; | 566 const kLineLengthLimit = 78; |
565 | 567 |
566 /** | 568 /** |
567 * Restrict source location start and end positions to make the source slice | 569 * Restrict source location start and end positions to make the source slice |
568 * no more that a certain number of characters wide. | 570 * no more that a certain number of characters wide. |
569 * @param {number} opt_limit The with limit of the source text with a default | 571 * @param {number} opt_limit The with limit of the source text with a default |
570 * of 78 | 572 * of 78 |
571 * @param {number} opt_before The number of characters to prefer before the | 573 * @param {number} opt_before The number of characters to prefer before the |
572 * position with a default value of 10 less that the limit | 574 * position with a default value of 10 less that the limit |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 * @constructor | 644 * @constructor |
643 */ | 645 */ |
644 function SourceSlice(script, from_line, to_line, from_position, to_position) { | 646 function SourceSlice(script, from_line, to_line, from_position, to_position) { |
645 this.script = script; | 647 this.script = script; |
646 this.from_line = from_line; | 648 this.from_line = from_line; |
647 this.to_line = to_line; | 649 this.to_line = to_line; |
648 this.from_position = from_position; | 650 this.from_position = from_position; |
649 this.to_position = to_position; | 651 this.to_position = to_position; |
650 } | 652 } |
651 | 653 |
| 654 SourceSlice.prototype.__proto__ = null; |
652 | 655 |
653 /** | 656 /** |
654 * Get the source text for a SourceSlice | 657 * Get the source text for a SourceSlice |
655 * @return {String} Source text for this slice. The last line will include | 658 * @return {String} Source text for this slice. The last line will include |
656 * the line terminating characters (if any) | 659 * the line terminating characters (if any) |
657 */ | 660 */ |
658 SourceSlice.prototype.sourceText = function () { | 661 SourceSlice.prototype.sourceText = function () { |
659 return %_CallFunction(this.script.source, | 662 return %_CallFunction(this.script.source, |
660 this.from_position, | 663 this.from_position, |
661 this.to_position, | 664 this.to_position, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 desc = ToPropertyDescriptor(desc); | 712 desc = ToPropertyDescriptor(desc); |
710 DefineOwnProperty(obj, name, desc, true); | 713 DefineOwnProperty(obj, name, desc, true); |
711 } | 714 } |
712 | 715 |
713 function CallSite(receiver, fun, pos) { | 716 function CallSite(receiver, fun, pos) { |
714 this.receiver = receiver; | 717 this.receiver = receiver; |
715 this.fun = fun; | 718 this.fun = fun; |
716 this.pos = pos; | 719 this.pos = pos; |
717 } | 720 } |
718 | 721 |
| 722 CallSite.prototype.__proto__ = null; |
| 723 |
719 CallSite.prototype.getThis = function () { | 724 CallSite.prototype.getThis = function () { |
720 return this.receiver; | 725 return this.receiver; |
721 }; | 726 }; |
722 | 727 |
723 CallSite.prototype.getTypeName = function () { | 728 CallSite.prototype.getTypeName = function () { |
724 var constructor = this.receiver.constructor; | 729 var constructor = this.receiver.constructor; |
725 if (!constructor) | 730 if (!constructor) { |
726 return %_CallFunction(this.receiver, ObjectToString); | 731 return %_CallFunction(this.receiver, ObjectToString); |
| 732 } |
727 var constructorName = constructor.name; | 733 var constructorName = constructor.name; |
728 if (!constructorName) | 734 if (!constructorName) { |
729 return %_CallFunction(this.receiver, ObjectToString); | 735 return %_CallFunction(this.receiver, ObjectToString); |
| 736 } |
730 return constructorName; | 737 return constructorName; |
731 }; | 738 }; |
732 | 739 |
733 CallSite.prototype.isToplevel = function () { | 740 CallSite.prototype.isToplevel = function () { |
734 if (this.receiver == null) | 741 if (this.receiver == null) { |
735 return true; | 742 return true; |
| 743 } |
736 return IS_GLOBAL(this.receiver); | 744 return IS_GLOBAL(this.receiver); |
737 }; | 745 }; |
738 | 746 |
739 CallSite.prototype.isEval = function () { | 747 CallSite.prototype.isEval = function () { |
740 var script = %FunctionGetScript(this.fun); | 748 var script = %FunctionGetScript(this.fun); |
741 return script && script.compilation_type == COMPILATION_TYPE_EVAL; | 749 return script && script.compilation_type == COMPILATION_TYPE_EVAL; |
742 }; | 750 }; |
743 | 751 |
744 CallSite.prototype.getEvalOrigin = function () { | 752 CallSite.prototype.getEvalOrigin = function () { |
745 var script = %FunctionGetScript(this.fun); | 753 var script = %FunctionGetScript(this.fun); |
(...skipping 12 matching lines...) Expand all Loading... |
758 CallSite.prototype.getFunctionName = function () { | 766 CallSite.prototype.getFunctionName = function () { |
759 // See if the function knows its own name | 767 // See if the function knows its own name |
760 var name = this.fun.name; | 768 var name = this.fun.name; |
761 if (name) { | 769 if (name) { |
762 return name; | 770 return name; |
763 } else { | 771 } else { |
764 return %FunctionGetInferredName(this.fun); | 772 return %FunctionGetInferredName(this.fun); |
765 } | 773 } |
766 // Maybe this is an evaluation? | 774 // Maybe this is an evaluation? |
767 var script = %FunctionGetScript(this.fun); | 775 var script = %FunctionGetScript(this.fun); |
768 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) | 776 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { |
769 return "eval"; | 777 return "eval"; |
| 778 } |
770 return null; | 779 return null; |
771 }; | 780 }; |
772 | 781 |
773 CallSite.prototype.getMethodName = function () { | 782 CallSite.prototype.getMethodName = function () { |
774 // See if we can find a unique property on the receiver that holds | 783 // See if we can find a unique property on the receiver that holds |
775 // this function. | 784 // this function. |
776 var ownName = this.fun.name; | 785 var ownName = this.fun.name; |
777 if (ownName && this.receiver && | 786 if (ownName && this.receiver && |
778 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun |
| | 787 (%_CallFunction(this.receiver, ownName, ObjectLookupGetter) === this.fun |
| |
779 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun |
| | 788 %_CallFunction(this.receiver, ownName, ObjectLookupSetter) === this.fun |
| |
780 this.receiver[ownName] === this.fun)) { | 789 this.receiver[ownName] === this.fun)) { |
781 // To handle DontEnum properties we guess that the method has | 790 // To handle DontEnum properties we guess that the method has |
782 // the same name as the function. | 791 // the same name as the function. |
783 return ownName; | 792 return ownName; |
784 } | 793 } |
785 var name = null; | 794 var name = null; |
786 for (var prop in this.receiver) { | 795 for (var prop in this.receiver) { |
787 if (this.receiver.__lookupGetter__(prop) === this.fun || | 796 if (this.receiver.__lookupGetter__(prop) === this.fun || |
788 this.receiver.__lookupSetter__(prop) === this.fun || | 797 this.receiver.__lookupSetter__(prop) === this.fun || |
789 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f
un)) { | 798 (!this.receiver.__lookupGetter__(prop) && this.receiver[prop] === this.f
un)) { |
790 // If we find more than one match bail out to avoid confusion. | 799 // If we find more than one match bail out to avoid confusion. |
791 if (name) | 800 if (name) { |
792 return null; | 801 return null; |
| 802 } |
793 name = prop; | 803 name = prop; |
794 } | 804 } |
795 } | 805 } |
796 if (name) | 806 if (name) { |
797 return name; | 807 return name; |
| 808 } |
798 return null; | 809 return null; |
799 }; | 810 }; |
800 | 811 |
801 CallSite.prototype.getFileName = function () { | 812 CallSite.prototype.getFileName = function () { |
802 var script = %FunctionGetScript(this.fun); | 813 var script = %FunctionGetScript(this.fun); |
803 return script ? script.name : null; | 814 return script ? script.name : null; |
804 }; | 815 }; |
805 | 816 |
806 CallSite.prototype.getLineNumber = function () { | 817 CallSite.prototype.getLineNumber = function () { |
807 if (this.pos == -1) | 818 if (this.pos == -1) { |
808 return null; | 819 return null; |
| 820 } |
809 var script = %FunctionGetScript(this.fun); | 821 var script = %FunctionGetScript(this.fun); |
810 var location = null; | 822 var location = null; |
811 if (script) { | 823 if (script) { |
812 location = script.locationFromPosition(this.pos, true); | 824 location = script.locationFromPosition(this.pos, true); |
813 } | 825 } |
814 return location ? location.line + 1 : null; | 826 return location ? location.line + 1 : null; |
815 }; | 827 }; |
816 | 828 |
817 CallSite.prototype.getColumnNumber = function () { | 829 CallSite.prototype.getColumnNumber = function () { |
818 if (this.pos == -1) | 830 if (this.pos == -1) { |
819 return null; | 831 return null; |
| 832 } |
820 var script = %FunctionGetScript(this.fun); | 833 var script = %FunctionGetScript(this.fun); |
821 var location = null; | 834 var location = null; |
822 if (script) { | 835 if (script) { |
823 location = script.locationFromPosition(this.pos, true); | 836 location = script.locationFromPosition(this.pos, true); |
824 } | 837 } |
825 return location ? location.column + 1: null; | 838 return location ? location.column + 1: null; |
826 }; | 839 }; |
827 | 840 |
828 CallSite.prototype.isNative = function () { | 841 CallSite.prototype.isNative = function () { |
829 var script = %FunctionGetScript(this.fun); | 842 var script = %FunctionGetScript(this.fun); |
830 return script ? (script.type == TYPE_NATIVE) : false; | 843 return script ? (script.type == TYPE_NATIVE) : false; |
831 }; | 844 }; |
832 | 845 |
833 CallSite.prototype.getPosition = function () { | 846 CallSite.prototype.getPosition = function () { |
834 return this.pos; | 847 return this.pos; |
835 }; | 848 }; |
836 | 849 |
837 CallSite.prototype.isConstructor = function () { | 850 CallSite.prototype.isConstructor = function () { |
838 var constructor = this.receiver ? this.receiver.constructor : null; | 851 var constructor = this.receiver ? this.receiver.constructor : null; |
839 if (!constructor) | 852 if (!constructor) { |
840 return false; | 853 return false; |
| 854 } |
841 return this.fun === constructor; | 855 return this.fun === constructor; |
842 }; | 856 }; |
843 | 857 |
844 function FormatEvalOrigin(script) { | 858 function FormatEvalOrigin(script) { |
845 var sourceURL = script.nameOrSourceURL(); | 859 var sourceURL = script.nameOrSourceURL(); |
846 if (sourceURL) | 860 if (sourceURL) { |
847 return sourceURL; | 861 return sourceURL; |
| 862 } |
848 | 863 |
849 var eval_origin = "eval at "; | 864 var eval_origin = "eval at "; |
850 if (script.eval_from_function_name) { | 865 if (script.eval_from_function_name) { |
851 eval_origin += script.eval_from_function_name; | 866 eval_origin += script.eval_from_function_name; |
852 } else { | 867 } else { |
853 eval_origin += "<anonymous>"; | 868 eval_origin += "<anonymous>"; |
854 } | 869 } |
855 | 870 |
856 var eval_from_script = script.eval_from_script; | 871 var eval_from_script = script.eval_from_script; |
857 if (eval_from_script) { | 872 if (eval_from_script) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 captureStackTrace(this, f); | 1050 captureStackTrace(this, f); |
1036 } else { | 1051 } else { |
1037 return new f(m); | 1052 return new f(m); |
1038 } | 1053 } |
1039 }); | 1054 }); |
1040 } | 1055 } |
1041 | 1056 |
1042 function captureStackTrace(obj, cons_opt) { | 1057 function captureStackTrace(obj, cons_opt) { |
1043 var stackTraceLimit = $Error.stackTraceLimit; | 1058 var stackTraceLimit = $Error.stackTraceLimit; |
1044 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; | 1059 if (!stackTraceLimit || !IS_NUMBER(stackTraceLimit)) return; |
1045 if (stackTraceLimit < 0 || stackTraceLimit > 10000) | 1060 if (stackTraceLimit < 0 || stackTraceLimit > 10000) { |
1046 stackTraceLimit = 10000; | 1061 stackTraceLimit = 10000; |
| 1062 } |
1047 var raw_stack = %CollectStackTrace(cons_opt | 1063 var raw_stack = %CollectStackTrace(cons_opt |
1048 ? cons_opt | 1064 ? cons_opt |
1049 : captureStackTrace, stackTraceLimit); | 1065 : captureStackTrace, stackTraceLimit); |
1050 DefineOneShotAccessor(obj, 'stack', function (obj) { | 1066 DefineOneShotAccessor(obj, 'stack', function (obj) { |
1051 return FormatRawStackTrace(obj, raw_stack); | 1067 return FormatRawStackTrace(obj, raw_stack); |
1052 }); | 1068 }); |
1053 }; | 1069 }; |
1054 | 1070 |
1055 $Math.__proto__ = global.Object.prototype; | 1071 $Math.__proto__ = global.Object.prototype; |
1056 | 1072 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 } | 1126 } |
1111 // This helper function is needed because access to properties on | 1127 // This helper function is needed because access to properties on |
1112 // the builtins object do not work inside of a catch clause. | 1128 // the builtins object do not work inside of a catch clause. |
1113 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } | 1129 function isCyclicErrorMarker(o) { return o === cyclic_error_marker; } |
1114 | 1130 |
1115 try { | 1131 try { |
1116 return %_CallFunction(this, errorToStringDetectCycle); | 1132 return %_CallFunction(this, errorToStringDetectCycle); |
1117 } catch(e) { | 1133 } catch(e) { |
1118 // If this error message was encountered already return the empty | 1134 // If this error message was encountered already return the empty |
1119 // string for it instead of recursively formatting it. | 1135 // string for it instead of recursively formatting it. |
1120 if (isCyclicErrorMarker(e)) return ''; | 1136 if (isCyclicErrorMarker(e)) { |
1121 else throw e; | 1137 return ''; |
| 1138 } |
| 1139 throw e; |
1122 } | 1140 } |
1123 } | 1141 } |
1124 | 1142 |
1125 | 1143 |
1126 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); | 1144 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); |
1127 | 1145 |
1128 // Boilerplate for exceptions for stack overflows. Used from | 1146 // Boilerplate for exceptions for stack overflows. Used from |
1129 // Isolate::StackOverflow(). | 1147 // Isolate::StackOverflow(). |
1130 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1148 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |