OLD | NEW |
---|---|
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
939 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); | 939 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); |
940 %FunctionSetPrototype(f, new ErrorPrototype()); | 940 %FunctionSetPrototype(f, new ErrorPrototype()); |
941 } else { | 941 } else { |
942 %FunctionSetPrototype(f, new $Error()); | 942 %FunctionSetPrototype(f, new $Error()); |
943 } | 943 } |
944 %FunctionSetInstanceClassName(f, 'Error'); | 944 %FunctionSetInstanceClassName(f, 'Error'); |
945 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); | 945 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); |
946 f.prototype.name = name; | 946 f.prototype.name = name; |
947 %SetCode(f, function(m) { | 947 %SetCode(f, function(m) { |
948 if (%_IsConstructCall()) { | 948 if (%_IsConstructCall()) { |
949 // Define all the expected properties directly on the error | |
950 // object. This avoids going through getters and setters defined | |
951 // on prototype objects. | |
952 %IgnoreAttributesAndSetProperty(this, 'stack', void 0); | |
953 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0); | |
954 %IgnoreAttributesAndSetProperty(this, 'type', void 0); | |
949 if (m === kAddMessageAccessorsMarker) { | 955 if (m === kAddMessageAccessorsMarker) { |
Søren Thygesen Gjesse
2011/01/12 15:46:41
Maybe add a comment that DefineOneShotAccessor ens
| |
950 DefineOneShotAccessor(this, 'message', function (obj) { | 956 DefineOneShotAccessor(this, 'message', function (obj) { |
951 return FormatMessage({type: obj.type, args: obj.arguments}); | 957 return FormatMessage({type: obj.type, args: obj.arguments}); |
952 }); | 958 }); |
953 } else if (!IS_UNDEFINED(m)) { | 959 } else if (!IS_UNDEFINED(m)) { |
954 this.message = ToString(m); | 960 %IgnoreAttributesAndSetProperty(this, 'message', ToString(m)); |
955 } | 961 } |
956 captureStackTrace(this, f); | 962 captureStackTrace(this, f); |
957 } else { | 963 } else { |
958 return new f(m); | 964 return new f(m); |
959 } | 965 } |
960 }); | 966 }); |
961 } | 967 } |
962 | 968 |
963 function captureStackTrace(obj, cons_opt) { | 969 function captureStackTrace(obj, cons_opt) { |
964 var stackTraceLimit = $Error.stackTraceLimit; | 970 var stackTraceLimit = $Error.stackTraceLimit; |
(...skipping 20 matching lines...) Expand all Loading... | |
985 $Error.captureStackTrace = captureStackTrace; | 991 $Error.captureStackTrace = captureStackTrace; |
986 | 992 |
987 // Setup extra properties of the Error.prototype object. | 993 // Setup extra properties of the Error.prototype object. |
988 $Error.prototype.message = ''; | 994 $Error.prototype.message = ''; |
989 | 995 |
990 %SetProperty($Error.prototype, 'toString', function toString() { | 996 %SetProperty($Error.prototype, 'toString', function toString() { |
991 var type = this.type; | 997 var type = this.type; |
992 if (type && !this.hasOwnProperty("message")) { | 998 if (type && !this.hasOwnProperty("message")) { |
993 return this.name + ": " + FormatMessage({ type: type, args: this.arguments } ); | 999 return this.name + ": " + FormatMessage({ type: type, args: this.arguments } ); |
994 } | 1000 } |
995 var message = this.message; | 1001 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; |
996 return this.name + (message ? (": " + message) : ""); | 1002 return this.name + message; |
997 }, DONT_ENUM); | 1003 }, DONT_ENUM); |
998 | 1004 |
999 | 1005 |
1000 // Boilerplate for exceptions for stack overflows. Used from | 1006 // Boilerplate for exceptions for stack overflows. Used from |
1001 // Top::StackOverflow(). | 1007 // Top::StackOverflow(). |
1002 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1008 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
OLD | NEW |