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 // Define special error type constructors. | 911 // Set up special error type constructors. |
912 function DefineError(global, f) { | 912 function SetUpError(error_function) { |
913 // Store the error function in both the global object | 913 %FunctionSetInstanceClassName(error_function, 'Error'); |
914 // and the runtime object. The function is fetched | 914 var name = error_function.name; |
915 // from the runtime object when throwing errors from | 915 %AddNamedProperty(error_function.prototype, 'name', name, DONT_ENUM); |
Igor Sheludko
2015/12/04 17:06:10
Why not set the prototype up in the bootstrapper?
| |
916 // within the runtime system to avoid strange side | 916 %AddNamedProperty(error_function.prototype, 'message', '', DONT_ENUM); |
917 // effects when overwriting the error functions from | 917 %AddNamedProperty(error_function.prototype, 'constructor', error_function, DON T_ENUM); |
Igor Sheludko
2015/12/04 17:06:10
Line longer than 80 chars.
| |
918 // user code. | 918 |
919 var name = f.name; | 919 // TODO(verwaest): NativeError.prototype should not have .toString, but this |
920 %AddNamedProperty(global, name, f, DONT_ENUM); | 920 // currently fails. |
921 // Configure the error function. | 921 utils.InstallFunctions(error_function.prototype, DONT_ENUM, |
922 if (name == 'Error') { | 922 ['toString', ErrorToString]); |
923 // The prototype of the Error object must itself be an error. | 923 |
924 // However, it can't be an instance of the Error object because | 924 %SetCode(error_function, function(m) { |
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); | |
934 } | |
935 %FunctionSetInstanceClassName(f, 'Error'); | |
936 %AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); | |
937 %AddNamedProperty(f.prototype, 'name', name, DONT_ENUM); | |
938 %SetCode(f, function(m) { | |
939 if (!IS_UNDEFINED(new.target)) { | 925 if (!IS_UNDEFINED(new.target)) { |
940 try { captureStackTrace(this, f); } catch (e) { } | 926 try { captureStackTrace(this, error_function); } catch (e) { } |
941 // Define all the expected properties directly on the error | 927 // Define all the expected properties directly on the error |
942 // object. This avoids going through getters and setters defined | 928 // object. This avoids going through getters and setters defined |
943 // on prototype objects. | 929 // on prototype objects. |
944 if (!IS_UNDEFINED(m)) { | 930 if (!IS_UNDEFINED(m)) { |
945 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); | 931 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); |
946 } | 932 } |
947 } else { | 933 } else { |
948 return new f(m); | 934 return new error_function(m); |
949 } | 935 } |
950 }); | 936 }); |
951 %SetNativeFlag(f); | 937 |
952 return f; | 938 %SetNativeFlag(error_function); |
939 return error_function; | |
953 }; | 940 }; |
954 | 941 |
955 GlobalError = DefineError(global, function Error() { }); | 942 GlobalError = SetUpError(global.Error); |
956 GlobalEvalError = DefineError(global, function EvalError() { }); | 943 GlobalEvalError = SetUpError(global.EvalError); |
957 GlobalRangeError = DefineError(global, function RangeError() { }); | 944 GlobalRangeError = SetUpError(global.RangeError); |
958 GlobalReferenceError = DefineError(global, function ReferenceError() { }); | 945 GlobalReferenceError = SetUpError(global.ReferenceError); |
959 GlobalSyntaxError = DefineError(global, function SyntaxError() { }); | 946 GlobalSyntaxError = SetUpError(global.SyntaxError); |
960 GlobalTypeError = DefineError(global, function TypeError() { }); | 947 GlobalTypeError = SetUpError(global.TypeError); |
961 GlobalURIError = DefineError(global, function URIError() { }); | 948 GlobalURIError = SetUpError(global.URIError); |
962 | |
963 %AddNamedProperty(GlobalError.prototype, 'message', '', DONT_ENUM); | |
964 | |
965 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, | |
966 ['toString', ErrorToString]); | |
967 | 949 |
968 function ErrorToString() { | 950 function ErrorToString() { |
969 if (!IS_SPEC_OBJECT(this)) { | 951 if (!IS_SPEC_OBJECT(this)) { |
970 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); | 952 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); |
971 } | 953 } |
972 | 954 |
973 return %ErrorToStringRT(this); | 955 return %ErrorToStringRT(this); |
974 } | 956 } |
975 | 957 |
976 function MakeError(type, arg0, arg1, arg2) { | 958 function MakeError(type, arg0, arg1, arg2) { |
(...skipping 27 matching lines...) Expand all Loading... | |
1004 // Define accessors first, as this may fail and throw. | 986 // Define accessors first, as this may fail and throw. |
1005 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, | 987 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, |
1006 set: StackTraceSetter, | 988 set: StackTraceSetter, |
1007 configurable: true }); | 989 configurable: true }); |
1008 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); | 990 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); |
1009 }; | 991 }; |
1010 | 992 |
1011 GlobalError.captureStackTrace = captureStackTrace; | 993 GlobalError.captureStackTrace = captureStackTrace; |
1012 | 994 |
1013 %InstallToContext([ | 995 %InstallToContext([ |
1014 "error_function", GlobalError, | |
1015 "eval_error_function", GlobalEvalError, | |
1016 "get_stack_trace_line_fun", GetStackTraceLine, | 996 "get_stack_trace_line_fun", GetStackTraceLine, |
1017 "make_error_function", MakeGenericError, | 997 "make_error_function", MakeGenericError, |
1018 "make_range_error", MakeRangeError, | 998 "make_range_error", MakeRangeError, |
1019 "make_type_error", MakeTypeError, | 999 "make_type_error", MakeTypeError, |
1020 "message_get_column_number", GetColumnNumber, | 1000 "message_get_column_number", GetColumnNumber, |
1021 "message_get_line_number", GetLineNumber, | 1001 "message_get_line_number", GetLineNumber, |
1022 "message_get_source_line", GetSourceLine, | 1002 "message_get_source_line", GetSourceLine, |
1023 "no_side_effect_to_string_fun", NoSideEffectToString, | 1003 "no_side_effect_to_string_fun", NoSideEffectToString, |
1024 "range_error_function", GlobalRangeError, | |
1025 "reference_error_function", GlobalReferenceError, | |
1026 "stack_overflow_boilerplate", StackOverflowBoilerplate, | 1004 "stack_overflow_boilerplate", StackOverflowBoilerplate, |
1027 "syntax_error_function", GlobalSyntaxError, | |
1028 "to_detail_string_fun", ToDetailString, | 1005 "to_detail_string_fun", ToDetailString, |
1029 "type_error_function", GlobalTypeError, | |
1030 "uri_error_function", GlobalURIError, | |
1031 ]); | 1006 ]); |
1032 | 1007 |
1033 utils.Export(function(to) { | 1008 utils.Export(function(to) { |
1034 to.ErrorToString = ErrorToString; | 1009 to.ErrorToString = ErrorToString; |
1035 to.MakeError = MakeError; | 1010 to.MakeError = MakeError; |
1036 to.MakeRangeError = MakeRangeError; | 1011 to.MakeRangeError = MakeRangeError; |
1037 to.MakeSyntaxError = MakeSyntaxError; | 1012 to.MakeSyntaxError = MakeSyntaxError; |
1038 to.MakeTypeError = MakeTypeError; | 1013 to.MakeTypeError = MakeTypeError; |
1039 to.MakeURIError = MakeURIError; | 1014 to.MakeURIError = MakeURIError; |
1040 }); | 1015 }); |
1041 | 1016 |
1042 }); | 1017 }); |
OLD | NEW |