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

Side by Side Diff: src/messages.js

Issue 6272004: Make the 'name' property on error prototypes read-only and dont-delete... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 9 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | test/mjsunit/error-constructors.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 } 90 }
91 91
92 92
93 function ToDetailString(obj) { 93 function ToDetailString(obj) {
94 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) { 94 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) {
95 var constructor = obj.constructor; 95 var constructor = obj.constructor;
96 if (!constructor) return ToString(obj); 96 if (!constructor) return ToString(obj);
97 var constructorName = constructor.name; 97 var constructorName = constructor.name;
98 if (!constructorName) return ToString(obj); 98 if (!constructorName) return ToString(obj);
99 return "#<" + GetInstanceName(constructorName) + ">"; 99 return "#<" + GetInstanceName(constructorName) + ">";
100 } else if (obj instanceof $Error) {
101 // When formatting internally created error messages, do not
102 // invoke overwritten error toString methods but explicitly use
103 // the error to string method. This is to avoid leaking error
104 // objects between script tags in a browser setting.
105 return %_CallFunction(obj, errorToString);
100 } else { 106 } else {
101 return ToString(obj); 107 return ToString(obj);
102 } 108 }
103 } 109 }
104 110
105 111
106 function MakeGenericError(constructor, type, args) { 112 function MakeGenericError(constructor, type, args) {
107 if (IS_UNDEFINED(args)) { 113 if (IS_UNDEFINED(args)) {
108 args = []; 114 args = [];
109 } 115 }
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 // special not-a-true-error-but-close-enough object. 942 // special not-a-true-error-but-close-enough object.
937 function ErrorPrototype() {} 943 function ErrorPrototype() {}
938 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); 944 %FunctionSetPrototype(ErrorPrototype, $Object.prototype);
939 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); 945 %FunctionSetInstanceClassName(ErrorPrototype, 'Error');
940 %FunctionSetPrototype(f, new ErrorPrototype()); 946 %FunctionSetPrototype(f, new ErrorPrototype());
941 } else { 947 } else {
942 %FunctionSetPrototype(f, new $Error()); 948 %FunctionSetPrototype(f, new $Error());
943 } 949 }
944 %FunctionSetInstanceClassName(f, 'Error'); 950 %FunctionSetInstanceClassName(f, 'Error');
945 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); 951 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM);
946 f.prototype.name = name; 952 // The name property on the prototype of error objects is not
953 // specified as being read-one and dont-delete. However, allowing
954 // overwriting allows leaks of error objects between script blocks
955 // in the same context in a browser setting. Therefore we fix the
956 // name.
957 %SetProperty(f.prototype, "name", name, READ_ONLY | DONT_DELETE);
947 %SetCode(f, function(m) { 958 %SetCode(f, function(m) {
948 if (%_IsConstructCall()) { 959 if (%_IsConstructCall()) {
949 // Define all the expected properties directly on the error 960 // Define all the expected properties directly on the error
950 // object. This avoids going through getters and setters defined 961 // object. This avoids going through getters and setters defined
951 // on prototype objects. 962 // on prototype objects.
952 %IgnoreAttributesAndSetProperty(this, 'stack', void 0); 963 %IgnoreAttributesAndSetProperty(this, 'stack', void 0);
953 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0); 964 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0);
954 %IgnoreAttributesAndSetProperty(this, 'type', void 0); 965 %IgnoreAttributesAndSetProperty(this, 'type', void 0);
955 if (m === kAddMessageAccessorsMarker) { 966 if (m === kAddMessageAccessorsMarker) {
956 // DefineOneShotAccessor always inserts a message property and 967 // DefineOneShotAccessor always inserts a message property and
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 DefineError(function SyntaxError() { }); 999 DefineError(function SyntaxError() { });
989 DefineError(function ReferenceError() { }); 1000 DefineError(function ReferenceError() { });
990 DefineError(function EvalError() { }); 1001 DefineError(function EvalError() { });
991 DefineError(function URIError() { }); 1002 DefineError(function URIError() { });
992 1003
993 $Error.captureStackTrace = captureStackTrace; 1004 $Error.captureStackTrace = captureStackTrace;
994 1005
995 // Setup extra properties of the Error.prototype object. 1006 // Setup extra properties of the Error.prototype object.
996 $Error.prototype.message = ''; 1007 $Error.prototype.message = '';
997 1008
998 %SetProperty($Error.prototype, 'toString', function toString() { 1009 function errorToString() {
999 var type = this.type; 1010 var type = this.type;
1000 if (type && !this.hasOwnProperty("message")) { 1011 if (type && !this.hasOwnProperty("message")) {
1001 return this.name + ": " + FormatMessage({ type: type, args: this.arguments } ); 1012 return this.name + ": " + FormatMessage({ type: type, args: this.arguments } );
1002 } 1013 }
1003 var message = this.hasOwnProperty("message") ? (": " + this.message) : ""; 1014 var message = this.hasOwnProperty("message") ? (": " + this.message) : "";
1004 return this.name + message; 1015 return this.name + message;
1005 }, DONT_ENUM); 1016 }
1017 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM);
1006 1018
1007 1019
1008 // Boilerplate for exceptions for stack overflows. Used from 1020 // Boilerplate for exceptions for stack overflows. Used from
1009 // Top::StackOverflow(). 1021 // Top::StackOverflow().
1010 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1022 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | test/mjsunit/error-constructors.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698