| 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 (function(global, utils) { | 7 (function(global, utils) { |
| 8 | 8 |
| 9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
| 10 | 10 |
| (...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 SET_PRIVATE(this, formattedStackTraceSymbol, v); | 901 SET_PRIVATE(this, formattedStackTraceSymbol, v); |
| 902 } | 902 } |
| 903 }; | 903 }; |
| 904 | 904 |
| 905 | 905 |
| 906 // Use a dummy function since we do not actually want to capture a stack trace | 906 // Use a dummy function since we do not actually want to capture a stack trace |
| 907 // when constructing the initial Error prototytpes. | 907 // when constructing the initial Error prototytpes. |
| 908 var captureStackTrace = function() {}; | 908 var captureStackTrace = function() {}; |
| 909 | 909 |
| 910 | 910 |
| 911 // Set up special error type constructors. | 911 // Define special error type constructors. |
| 912 function SetUpError(error_function) { | 912 function DefineError(global, f) { |
| 913 %FunctionSetInstanceClassName(error_function, 'Error'); | 913 // Store the error function in both the global object |
| 914 var name = error_function.name; | 914 // and the runtime object. The function is fetched |
| 915 var prototype = new GlobalObject(); | 915 // from the runtime object when throwing errors from |
| 916 if (name !== 'Error') { | 916 // within the runtime system to avoid strange side |
| 917 %InternalSetPrototype(error_function, GlobalError); | 917 // effects when overwriting the error functions from |
| 918 %InternalSetPrototype(prototype, GlobalError.prototype); | 918 // user code. |
| 919 var name = f.name; |
| 920 %AddNamedProperty(global, name, f, DONT_ENUM); |
| 921 // Configure the error function. |
| 922 if (name == 'Error') { |
| 923 // The prototype of the Error object must itself be an error. |
| 924 // However, it can't be an instance of the Error object because |
| 925 // it hasn't been properly configured yet. Instead we create a |
| 926 // special not-a-true-error-but-close-enough object. |
| 927 var ErrorPrototype = function() {}; |
| 928 %FunctionSetPrototype(ErrorPrototype, GlobalObject.prototype); |
| 929 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); |
| 930 %FunctionSetPrototype(f, new ErrorPrototype()); |
| 931 } else { |
| 932 %FunctionSetPrototype(f, new GlobalError()); |
| 933 %InternalSetPrototype(f, GlobalError); |
| 919 } | 934 } |
| 920 %FunctionSetPrototype(error_function, prototype); | 935 %FunctionSetInstanceClassName(f, 'Error'); |
| 921 | 936 %AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); |
| 922 %AddNamedProperty(error_function.prototype, 'name', name, DONT_ENUM); | 937 %AddNamedProperty(f.prototype, 'name', name, DONT_ENUM); |
| 923 %AddNamedProperty(error_function.prototype, 'message', '', DONT_ENUM); | 938 %SetCode(f, function(m) { |
| 924 %AddNamedProperty( | 939 if (!IS_UNDEFINED(new.target)) { |
| 925 error_function.prototype, 'constructor', error_function, DONT_ENUM); | 940 try { captureStackTrace(this, f); } catch (e) { } |
| 926 | 941 // Define all the expected properties directly on the error |
| 927 %SetCode(error_function, function(m) { | 942 // object. This avoids going through getters and setters defined |
| 928 if (IS_UNDEFINED(new.target)) return new error_function(m); | 943 // on prototype objects. |
| 929 | 944 if (!IS_UNDEFINED(m)) { |
| 930 try { captureStackTrace(this, error_function); } catch (e) { } | 945 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); |
| 931 // Define all the expected properties directly on the error | 946 } |
| 932 // object. This avoids going through getters and setters defined | 947 } else { |
| 933 // on prototype objects. | 948 return new f(m); |
| 934 if (!IS_UNDEFINED(m)) { | |
| 935 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); | |
| 936 } | 949 } |
| 937 }); | 950 }); |
| 938 | 951 %SetNativeFlag(f); |
| 939 %SetNativeFlag(error_function); | 952 return f; |
| 940 return error_function; | |
| 941 }; | 953 }; |
| 942 | 954 |
| 943 GlobalError = SetUpError(global.Error); | 955 GlobalError = DefineError(global, function Error() { }); |
| 944 GlobalEvalError = SetUpError(global.EvalError); | 956 GlobalEvalError = DefineError(global, function EvalError() { }); |
| 945 GlobalRangeError = SetUpError(global.RangeError); | 957 GlobalRangeError = DefineError(global, function RangeError() { }); |
| 946 GlobalReferenceError = SetUpError(global.ReferenceError); | 958 GlobalReferenceError = DefineError(global, function ReferenceError() { }); |
| 947 GlobalSyntaxError = SetUpError(global.SyntaxError); | 959 GlobalSyntaxError = DefineError(global, function SyntaxError() { }); |
| 948 GlobalTypeError = SetUpError(global.TypeError); | 960 GlobalTypeError = DefineError(global, function TypeError() { }); |
| 949 GlobalURIError = SetUpError(global.URIError); | 961 GlobalURIError = DefineError(global, function URIError() { }); |
| 962 |
| 963 %AddNamedProperty(GlobalError.prototype, 'message', '', DONT_ENUM); |
| 950 | 964 |
| 951 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, | 965 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, |
| 952 ['toString', ErrorToString]); | 966 ['toString', ErrorToString]); |
| 953 | 967 |
| 954 function ErrorToString() { | 968 function ErrorToString() { |
| 955 if (!IS_SPEC_OBJECT(this)) { | 969 if (!IS_SPEC_OBJECT(this)) { |
| 956 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); | 970 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); |
| 957 } | 971 } |
| 958 | 972 |
| 959 return %ErrorToStringRT(this); | 973 return %ErrorToStringRT(this); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 990 // Define accessors first, as this may fail and throw. | 1004 // Define accessors first, as this may fail and throw. |
| 991 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, | 1005 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, |
| 992 set: StackTraceSetter, | 1006 set: StackTraceSetter, |
| 993 configurable: true }); | 1007 configurable: true }); |
| 994 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); | 1008 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); |
| 995 }; | 1009 }; |
| 996 | 1010 |
| 997 GlobalError.captureStackTrace = captureStackTrace; | 1011 GlobalError.captureStackTrace = captureStackTrace; |
| 998 | 1012 |
| 999 %InstallToContext([ | 1013 %InstallToContext([ |
| 1014 "error_function", GlobalError, |
| 1015 "eval_error_function", GlobalEvalError, |
| 1000 "get_stack_trace_line_fun", GetStackTraceLine, | 1016 "get_stack_trace_line_fun", GetStackTraceLine, |
| 1001 "make_error_function", MakeGenericError, | 1017 "make_error_function", MakeGenericError, |
| 1002 "make_range_error", MakeRangeError, | 1018 "make_range_error", MakeRangeError, |
| 1003 "make_type_error", MakeTypeError, | 1019 "make_type_error", MakeTypeError, |
| 1004 "message_get_column_number", GetColumnNumber, | 1020 "message_get_column_number", GetColumnNumber, |
| 1005 "message_get_line_number", GetLineNumber, | 1021 "message_get_line_number", GetLineNumber, |
| 1006 "message_get_source_line", GetSourceLine, | 1022 "message_get_source_line", GetSourceLine, |
| 1007 "no_side_effect_to_string_fun", NoSideEffectToString, | 1023 "no_side_effect_to_string_fun", NoSideEffectToString, |
| 1024 "range_error_function", GlobalRangeError, |
| 1025 "reference_error_function", GlobalReferenceError, |
| 1008 "stack_overflow_boilerplate", StackOverflowBoilerplate, | 1026 "stack_overflow_boilerplate", StackOverflowBoilerplate, |
| 1027 "syntax_error_function", GlobalSyntaxError, |
| 1009 "to_detail_string_fun", ToDetailString, | 1028 "to_detail_string_fun", ToDetailString, |
| 1029 "type_error_function", GlobalTypeError, |
| 1030 "uri_error_function", GlobalURIError, |
| 1010 ]); | 1031 ]); |
| 1011 | 1032 |
| 1012 utils.Export(function(to) { | 1033 utils.Export(function(to) { |
| 1013 to.ErrorToString = ErrorToString; | 1034 to.ErrorToString = ErrorToString; |
| 1014 to.MakeError = MakeError; | 1035 to.MakeError = MakeError; |
| 1015 to.MakeRangeError = MakeRangeError; | 1036 to.MakeRangeError = MakeRangeError; |
| 1016 to.MakeSyntaxError = MakeSyntaxError; | 1037 to.MakeSyntaxError = MakeSyntaxError; |
| 1017 to.MakeTypeError = MakeTypeError; | 1038 to.MakeTypeError = MakeTypeError; |
| 1018 to.MakeURIError = MakeURIError; | 1039 to.MakeURIError = MakeURIError; |
| 1019 }); | 1040 }); |
| 1020 | 1041 |
| 1021 }); | 1042 }); |
| OLD | NEW |