| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 } | 776 } |
| 777 | 777 |
| 778 | 778 |
| 779 function GetStackTraceLine(recv, fun, pos, isGlobal) { | 779 function GetStackTraceLine(recv, fun, pos, isGlobal) { |
| 780 return new CallSite(recv, fun, pos, false).toString(); | 780 return new CallSite(recv, fun, pos, false).toString(); |
| 781 } | 781 } |
| 782 | 782 |
| 783 // ---------------------------------------------------------------------------- | 783 // ---------------------------------------------------------------------------- |
| 784 // Error implementation | 784 // Error implementation |
| 785 | 785 |
| 786 var CallSiteReceiverKey = %CreateSymbol("receiver"); | 786 //TODO(rossberg) |
| 787 var CallSiteFunctionKey = %CreateSymbol("function"); | 787 var CallSiteReceiverKey = NEW_PRIVATE("receiver"); |
| 788 var CallSitePositionKey = %CreateSymbol("position"); | 788 var CallSiteFunctionKey = NEW_PRIVATE("function"); |
| 789 var CallSiteStrictModeKey = %CreateSymbol("strict mode"); | 789 var CallSitePositionKey = NEW_PRIVATE("position"); |
| 790 var CallSiteStrictModeKey = NEW_PRIVATE("strict mode"); |
| 790 | 791 |
| 791 function CallSite(receiver, fun, pos, strict_mode) { | 792 function CallSite(receiver, fun, pos, strict_mode) { |
| 792 this[CallSiteReceiverKey] = receiver; | 793 SET_PRIVATE(this, CallSiteReceiverKey, receiver); |
| 793 this[CallSiteFunctionKey] = fun; | 794 SET_PRIVATE(this, CallSiteFunctionKey, fun); |
| 794 this[CallSitePositionKey] = pos; | 795 SET_PRIVATE(this, CallSitePositionKey, pos); |
| 795 this[CallSiteStrictModeKey] = strict_mode; | 796 SET_PRIVATE(this, CallSiteStrictModeKey, strict_mode); |
| 796 } | 797 } |
| 797 | 798 |
| 798 function CallSiteGetThis() { | 799 function CallSiteGetThis() { |
| 799 return this[CallSiteStrictModeKey] ? UNDEFINED : this[CallSiteReceiverKey]; | 800 return GET_PRIVATE(this, CallSiteStrictModeKey) |
| 801 ? UNDEFINED : GET_PRIVATE(this, CallSiteReceiverKey); |
| 800 } | 802 } |
| 801 | 803 |
| 802 function CallSiteGetTypeName() { | 804 function CallSiteGetTypeName() { |
| 803 return GetTypeName(this[CallSiteReceiverKey], false); | 805 return GetTypeName(GET_PRIVATE(this, CallSiteReceiverKey), false); |
| 804 } | 806 } |
| 805 | 807 |
| 806 function CallSiteIsToplevel() { | 808 function CallSiteIsToplevel() { |
| 807 if (this[CallSiteReceiverKey] == null) { | 809 if (GET_PRIVATE(this, CallSiteReceiverKey) == null) { |
| 808 return true; | 810 return true; |
| 809 } | 811 } |
| 810 return IS_GLOBAL(this[CallSiteReceiverKey]); | 812 return IS_GLOBAL(GET_PRIVATE(this, CallSiteReceiverKey)); |
| 811 } | 813 } |
| 812 | 814 |
| 813 function CallSiteIsEval() { | 815 function CallSiteIsEval() { |
| 814 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 816 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 815 return script && script.compilation_type == COMPILATION_TYPE_EVAL; | 817 return script && script.compilation_type == COMPILATION_TYPE_EVAL; |
| 816 } | 818 } |
| 817 | 819 |
| 818 function CallSiteGetEvalOrigin() { | 820 function CallSiteGetEvalOrigin() { |
| 819 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 821 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 820 return FormatEvalOrigin(script); | 822 return FormatEvalOrigin(script); |
| 821 } | 823 } |
| 822 | 824 |
| 823 function CallSiteGetScriptNameOrSourceURL() { | 825 function CallSiteGetScriptNameOrSourceURL() { |
| 824 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 826 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 825 return script ? script.nameOrSourceURL() : null; | 827 return script ? script.nameOrSourceURL() : null; |
| 826 } | 828 } |
| 827 | 829 |
| 828 function CallSiteGetFunction() { | 830 function CallSiteGetFunction() { |
| 829 return this[CallSiteStrictModeKey] ? UNDEFINED : this[CallSiteFunctionKey]; | 831 return GET_PRIVATE(this, CallSiteStrictModeKey) |
| 832 ? UNDEFINED : GET_PRIVATE(this, CallSiteFunctionKey); |
| 830 } | 833 } |
| 831 | 834 |
| 832 function CallSiteGetFunctionName() { | 835 function CallSiteGetFunctionName() { |
| 833 // See if the function knows its own name | 836 // See if the function knows its own name |
| 834 var name = this[CallSiteFunctionKey].name; | 837 var name = GET_PRIVATE(this, CallSiteFunctionKey).name; |
| 835 if (name) { | 838 if (name) { |
| 836 return name; | 839 return name; |
| 837 } | 840 } |
| 838 name = %FunctionGetInferredName(this[CallSiteFunctionKey]); | 841 name = %FunctionGetInferredName(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 839 if (name) { | 842 if (name) { |
| 840 return name; | 843 return name; |
| 841 } | 844 } |
| 842 // Maybe this is an evaluation? | 845 // Maybe this is an evaluation? |
| 843 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 846 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 844 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { | 847 if (script && script.compilation_type == COMPILATION_TYPE_EVAL) { |
| 845 return "eval"; | 848 return "eval"; |
| 846 } | 849 } |
| 847 return null; | 850 return null; |
| 848 } | 851 } |
| 849 | 852 |
| 850 function CallSiteGetMethodName() { | 853 function CallSiteGetMethodName() { |
| 851 // See if we can find a unique property on the receiver that holds | 854 // See if we can find a unique property on the receiver that holds |
| 852 // this function. | 855 // this function. |
| 853 var receiver = this[CallSiteReceiverKey]; | 856 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); |
| 854 var fun = this[CallSiteFunctionKey]; | 857 var fun = GET_PRIVATE(this, CallSiteFunctionKey); |
| 855 var ownName = fun.name; | 858 var ownName = fun.name; |
| 856 if (ownName && receiver && | 859 if (ownName && receiver && |
| 857 (%_CallFunction(receiver, ownName, ObjectLookupGetter) === fun || | 860 (%_CallFunction(receiver, ownName, ObjectLookupGetter) === fun || |
| 858 %_CallFunction(receiver, ownName, ObjectLookupSetter) === fun || | 861 %_CallFunction(receiver, ownName, ObjectLookupSetter) === fun || |
| 859 (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) { | 862 (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) { |
| 860 // To handle DontEnum properties we guess that the method has | 863 // To handle DontEnum properties we guess that the method has |
| 861 // the same name as the function. | 864 // the same name as the function. |
| 862 return ownName; | 865 return ownName; |
| 863 } | 866 } |
| 864 var name = null; | 867 var name = null; |
| 865 for (var prop in receiver) { | 868 for (var prop in receiver) { |
| 866 if (%_CallFunction(receiver, prop, ObjectLookupGetter) === fun || | 869 if (%_CallFunction(receiver, prop, ObjectLookupGetter) === fun || |
| 867 %_CallFunction(receiver, prop, ObjectLookupSetter) === fun || | 870 %_CallFunction(receiver, prop, ObjectLookupSetter) === fun || |
| 868 (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) { | 871 (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) { |
| 869 // If we find more than one match bail out to avoid confusion. | 872 // If we find more than one match bail out to avoid confusion. |
| 870 if (name) { | 873 if (name) { |
| 871 return null; | 874 return null; |
| 872 } | 875 } |
| 873 name = prop; | 876 name = prop; |
| 874 } | 877 } |
| 875 } | 878 } |
| 876 if (name) { | 879 if (name) { |
| 877 return name; | 880 return name; |
| 878 } | 881 } |
| 879 return null; | 882 return null; |
| 880 } | 883 } |
| 881 | 884 |
| 882 function CallSiteGetFileName() { | 885 function CallSiteGetFileName() { |
| 883 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 886 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 884 return script ? script.name : null; | 887 return script ? script.name : null; |
| 885 } | 888 } |
| 886 | 889 |
| 887 function CallSiteGetLineNumber() { | 890 function CallSiteGetLineNumber() { |
| 888 if (this[CallSitePositionKey] == -1) { | 891 if (GET_PRIVATE(this, CallSitePositionKey) == -1) { |
| 889 return null; | 892 return null; |
| 890 } | 893 } |
| 891 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 894 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 892 var location = null; | 895 var location = null; |
| 893 if (script) { | 896 if (script) { |
| 894 location = script.locationFromPosition(this[CallSitePositionKey], true); | 897 location = script.locationFromPosition( |
| 898 GET_PRIVATE(this, CallSitePositionKey), true); |
| 895 } | 899 } |
| 896 return location ? location.line + 1 : null; | 900 return location ? location.line + 1 : null; |
| 897 } | 901 } |
| 898 | 902 |
| 899 function CallSiteGetColumnNumber() { | 903 function CallSiteGetColumnNumber() { |
| 900 if (this[CallSitePositionKey] == -1) { | 904 if (GET_PRIVATE(this, CallSitePositionKey) == -1) { |
| 901 return null; | 905 return null; |
| 902 } | 906 } |
| 903 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 907 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 904 var location = null; | 908 var location = null; |
| 905 if (script) { | 909 if (script) { |
| 906 location = script.locationFromPosition(this[CallSitePositionKey], true); | 910 location = script.locationFromPosition( |
| 911 GET_PRIVATE(this, CallSitePositionKey), true); |
| 907 } | 912 } |
| 908 return location ? location.column + 1: null; | 913 return location ? location.column + 1: null; |
| 909 } | 914 } |
| 910 | 915 |
| 911 function CallSiteIsNative() { | 916 function CallSiteIsNative() { |
| 912 var script = %FunctionGetScript(this[CallSiteFunctionKey]); | 917 var script = %FunctionGetScript(GET_PRIVATE(this, CallSiteFunctionKey)); |
| 913 return script ? (script.type == TYPE_NATIVE) : false; | 918 return script ? (script.type == TYPE_NATIVE) : false; |
| 914 } | 919 } |
| 915 | 920 |
| 916 function CallSiteGetPosition() { | 921 function CallSiteGetPosition() { |
| 917 return this[CallSitePositionKey]; | 922 return GET_PRIVATE(this, CallSitePositionKey); |
| 918 } | 923 } |
| 919 | 924 |
| 920 function CallSiteIsConstructor() { | 925 function CallSiteIsConstructor() { |
| 921 var receiver = this[CallSiteReceiverKey]; | 926 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); |
| 922 var constructor = (receiver != null && IS_OBJECT(receiver)) | 927 var constructor = (receiver != null && IS_OBJECT(receiver)) |
| 923 ? %GetDataProperty(receiver, "constructor") : null; | 928 ? %GetDataProperty(receiver, "constructor") : null; |
| 924 if (!constructor) return false; | 929 if (!constructor) return false; |
| 925 return this[CallSiteFunctionKey] === constructor; | 930 return GET_PRIVATE(this, CallSiteFunctionKey) === constructor; |
| 926 } | 931 } |
| 927 | 932 |
| 928 function CallSiteToString() { | 933 function CallSiteToString() { |
| 929 var fileName; | 934 var fileName; |
| 930 var fileLocation = ""; | 935 var fileLocation = ""; |
| 931 if (this.isNative()) { | 936 if (this.isNative()) { |
| 932 fileLocation = "native"; | 937 fileLocation = "native"; |
| 933 } else { | 938 } else { |
| 934 if (this.isEval()) { | 939 if (this.isEval()) { |
| 935 fileName = this.getScriptNameOrSourceURL(); | 940 fileName = this.getScriptNameOrSourceURL(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 958 } | 963 } |
| 959 } | 964 } |
| 960 } | 965 } |
| 961 | 966 |
| 962 var line = ""; | 967 var line = ""; |
| 963 var functionName = this.getFunctionName(); | 968 var functionName = this.getFunctionName(); |
| 964 var addSuffix = true; | 969 var addSuffix = true; |
| 965 var isConstructor = this.isConstructor(); | 970 var isConstructor = this.isConstructor(); |
| 966 var isMethodCall = !(this.isToplevel() || isConstructor); | 971 var isMethodCall = !(this.isToplevel() || isConstructor); |
| 967 if (isMethodCall) { | 972 if (isMethodCall) { |
| 968 var typeName = GetTypeName(this[CallSiteReceiverKey], true); | 973 var typeName = GetTypeName(GET_PRIVATE(this, CallSiteReceiverKey), true); |
| 969 var methodName = this.getMethodName(); | 974 var methodName = this.getMethodName(); |
| 970 if (functionName) { | 975 if (functionName) { |
| 971 if (typeName && | 976 if (typeName && |
| 972 %_CallFunction(functionName, typeName, StringIndexOf) != 0) { | 977 %_CallFunction(functionName, typeName, StringIndexOf) != 0) { |
| 973 line += typeName + "."; | 978 line += typeName + "."; |
| 974 } | 979 } |
| 975 line += functionName; | 980 line += functionName; |
| 976 if (methodName && | 981 if (methodName && |
| 977 (%_CallFunction(functionName, "." + methodName, StringIndexOf) != | 982 (%_CallFunction(functionName, "." + methodName, StringIndexOf) != |
| 978 functionName.length - methodName.length - 1)) { | 983 functionName.length - methodName.length - 1)) { |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 %GetAndClearOverflowedStackTrace(this); | 1346 %GetAndClearOverflowedStackTrace(this); |
| 1342 }; | 1347 }; |
| 1343 | 1348 |
| 1344 %DefineOrRedefineAccessorProperty( | 1349 %DefineOrRedefineAccessorProperty( |
| 1345 boilerplate, 'stack', getter, setter, DONT_ENUM); | 1350 boilerplate, 'stack', getter, setter, DONT_ENUM); |
| 1346 | 1351 |
| 1347 return boilerplate; | 1352 return boilerplate; |
| 1348 } | 1353 } |
| 1349 | 1354 |
| 1350 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); | 1355 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); |
| OLD | NEW |