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

Side by Side Diff: src/messages.js

Issue 6388003: Another fix for leaking error objects. User code can overwrite (Closed) Base URL: https://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') | no next file with comments »
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 for (var i = 0; i < args.length; i++) { 83 for (var i = 0; i < args.length; i++) {
84 var str; 84 var str;
85 try { str = ToDetailString(args[i]); } 85 try { str = ToDetailString(args[i]); }
86 catch (e) { str = "#<error>"; } 86 catch (e) { str = "#<error>"; }
87 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str); 87 result = ArrayJoin.call(StringSplit.call(result, "%" + i), str);
88 } 88 }
89 return result; 89 return result;
90 } 90 }
91 91
92 92
93 // To check if something is a native error we need to check the
94 // concrete native error types. It is not enough to check "obj
95 // instanceof $Error" because user code can replace
96 // NativeError.prototype.__proto__. User code cannot replace
97 // NativeError.prototype though and therefore this is a safe test.
98 function IsNativeErrorObject(obj) {
99 return (obj instanceof $Error) ||
100 (obj instanceof $EvalError) ||
101 (obj instanceof $RangeError) ||
102 (obj instanceof $ReferenceError) ||
103 (obj instanceof $SyntaxError) ||
104 (obj instanceof $TypeError) ||
105 (obj instanceof $URIError);
106 }
107
108
93 // When formatting internally created error messages, do not 109 // When formatting internally created error messages, do not
94 // invoke overwritten error toString methods but explicitly use 110 // invoke overwritten error toString methods but explicitly use
95 // the error to string method. This is to avoid leaking error 111 // the error to string method. This is to avoid leaking error
96 // objects between script tags in a browser setting. 112 // objects between script tags in a browser setting.
97 function ToStringCheckErrorObject(obj) { 113 function ToStringCheckErrorObject(obj) {
98 if (obj instanceof $Error) { 114 if (IsNativeErrorObject(obj)) {
99 return %_CallFunction(obj, errorToString); 115 return %_CallFunction(obj, errorToString);
100 } else { 116 } else {
101 return ToString(obj); 117 return ToString(obj);
102 } 118 }
103 } 119 }
104 120
105 121
106 function ToDetailString(obj) { 122 function ToDetailString(obj) {
107 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) { 123 if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toStri ng) {
108 var constructor = obj.constructor; 124 var constructor = obj.constructor;
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 else throw e; 1070 else throw e;
1055 } 1071 }
1056 } 1072 }
1057 1073
1058 %FunctionSetName(errorToString, 'toString'); 1074 %FunctionSetName(errorToString, 'toString');
1059 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM); 1075 %SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM);
1060 1076
1061 // Boilerplate for exceptions for stack overflows. Used from 1077 // Boilerplate for exceptions for stack overflows. Used from
1062 // Top::StackOverflow(). 1078 // Top::StackOverflow().
1063 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1079 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « no previous file | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698