Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: src/js/messages.js

Issue 1496333002: Support intriscDefaultProto for Error functions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: mark test262 test as fixed Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/isolate.cc ('k') | test/mjsunit/error-constructors.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 var prototype = new GlobalObject();
916 // within the runtime system to avoid strange side 916 if (name !== 'Error') {
917 // effects when overwriting the error functions from 917 %InternalSetPrototype(error_function, GlobalError);
918 // user code. 918 %InternalSetPrototype(prototype, GlobalError.prototype);
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);
934 } 919 }
935 %FunctionSetInstanceClassName(f, 'Error'); 920 %FunctionSetPrototype(error_function, prototype);
936 %AddNamedProperty(f.prototype, 'constructor', f, DONT_ENUM); 921
937 %AddNamedProperty(f.prototype, 'name', name, DONT_ENUM); 922 %AddNamedProperty(error_function.prototype, 'name', name, DONT_ENUM);
938 %SetCode(f, function(m) { 923 %AddNamedProperty(error_function.prototype, 'message', '', DONT_ENUM);
939 if (!IS_UNDEFINED(new.target)) { 924 %AddNamedProperty(
940 try { captureStackTrace(this, f); } catch (e) { } 925 error_function.prototype, 'constructor', error_function, DONT_ENUM);
941 // Define all the expected properties directly on the error 926
942 // object. This avoids going through getters and setters defined 927 %SetCode(error_function, function(m) {
943 // on prototype objects. 928 if (IS_UNDEFINED(new.target)) return new error_function(m);
944 if (!IS_UNDEFINED(m)) { 929
945 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM); 930 try { captureStackTrace(this, error_function); } catch (e) { }
946 } 931 // Define all the expected properties directly on the error
947 } else { 932 // object. This avoids going through getters and setters defined
948 return new f(m); 933 // on prototype objects.
934 if (!IS_UNDEFINED(m)) {
935 %AddNamedProperty(this, 'message', TO_STRING(m), DONT_ENUM);
949 } 936 }
950 }); 937 });
951 %SetNativeFlag(f); 938
952 return f; 939 %SetNativeFlag(error_function);
940 return error_function;
953 }; 941 };
954 942
955 GlobalError = DefineError(global, function Error() { }); 943 GlobalError = SetUpError(global.Error);
956 GlobalEvalError = DefineError(global, function EvalError() { }); 944 GlobalEvalError = SetUpError(global.EvalError);
957 GlobalRangeError = DefineError(global, function RangeError() { }); 945 GlobalRangeError = SetUpError(global.RangeError);
958 GlobalReferenceError = DefineError(global, function ReferenceError() { }); 946 GlobalReferenceError = SetUpError(global.ReferenceError);
959 GlobalSyntaxError = DefineError(global, function SyntaxError() { }); 947 GlobalSyntaxError = SetUpError(global.SyntaxError);
960 GlobalTypeError = DefineError(global, function TypeError() { }); 948 GlobalTypeError = SetUpError(global.TypeError);
961 GlobalURIError = DefineError(global, function URIError() { }); 949 GlobalURIError = SetUpError(global.URIError);
962
963 %AddNamedProperty(GlobalError.prototype, 'message', '', DONT_ENUM);
964 950
965 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM, 951 utils.InstallFunctions(GlobalError.prototype, DONT_ENUM,
966 ['toString', ErrorToString]); 952 ['toString', ErrorToString]);
967 953
968 function ErrorToString() { 954 function ErrorToString() {
969 if (!IS_SPEC_OBJECT(this)) { 955 if (!IS_SPEC_OBJECT(this)) {
970 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString"); 956 throw MakeTypeError(kCalledOnNonObject, "Error.prototype.toString");
971 } 957 }
972 958
973 return %ErrorToStringRT(this); 959 return %ErrorToStringRT(this);
(...skipping 30 matching lines...) Expand all
1004 // Define accessors first, as this may fail and throw. 990 // Define accessors first, as this may fail and throw.
1005 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, 991 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter,
1006 set: StackTraceSetter, 992 set: StackTraceSetter,
1007 configurable: true }); 993 configurable: true });
1008 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); 994 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace);
1009 }; 995 };
1010 996
1011 GlobalError.captureStackTrace = captureStackTrace; 997 GlobalError.captureStackTrace = captureStackTrace;
1012 998
1013 %InstallToContext([ 999 %InstallToContext([
1014 "error_function", GlobalError,
1015 "eval_error_function", GlobalEvalError,
1016 "get_stack_trace_line_fun", GetStackTraceLine, 1000 "get_stack_trace_line_fun", GetStackTraceLine,
1017 "make_error_function", MakeGenericError, 1001 "make_error_function", MakeGenericError,
1018 "make_range_error", MakeRangeError, 1002 "make_range_error", MakeRangeError,
1019 "make_type_error", MakeTypeError, 1003 "make_type_error", MakeTypeError,
1020 "message_get_column_number", GetColumnNumber, 1004 "message_get_column_number", GetColumnNumber,
1021 "message_get_line_number", GetLineNumber, 1005 "message_get_line_number", GetLineNumber,
1022 "message_get_source_line", GetSourceLine, 1006 "message_get_source_line", GetSourceLine,
1023 "no_side_effect_to_string_fun", NoSideEffectToString, 1007 "no_side_effect_to_string_fun", NoSideEffectToString,
1024 "range_error_function", GlobalRangeError,
1025 "reference_error_function", GlobalReferenceError,
1026 "stack_overflow_boilerplate", StackOverflowBoilerplate, 1008 "stack_overflow_boilerplate", StackOverflowBoilerplate,
1027 "syntax_error_function", GlobalSyntaxError,
1028 "to_detail_string_fun", ToDetailString, 1009 "to_detail_string_fun", ToDetailString,
1029 "type_error_function", GlobalTypeError,
1030 "uri_error_function", GlobalURIError,
1031 ]); 1010 ]);
1032 1011
1033 utils.Export(function(to) { 1012 utils.Export(function(to) {
1034 to.ErrorToString = ErrorToString; 1013 to.ErrorToString = ErrorToString;
1035 to.MakeError = MakeError; 1014 to.MakeError = MakeError;
1036 to.MakeRangeError = MakeRangeError; 1015 to.MakeRangeError = MakeRangeError;
1037 to.MakeSyntaxError = MakeSyntaxError; 1016 to.MakeSyntaxError = MakeSyntaxError;
1038 to.MakeTypeError = MakeTypeError; 1017 to.MakeTypeError = MakeTypeError;
1039 to.MakeURIError = MakeURIError; 1018 to.MakeURIError = MakeURIError;
1040 }); 1019 });
1041 1020
1042 }); 1021 });
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | test/mjsunit/error-constructors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698