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