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

Unified Diff: src/messages.js

Issue 6322008: Version 3.0.10... (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/liveobjectlist-inl.h ('k') | src/mips/ic-mips.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/messages.js
===================================================================
--- src/messages.js (revision 6437)
+++ src/messages.js (working copy)
@@ -90,21 +90,28 @@
}
+// When formatting internally created error messages, do not
+// invoke overwritten error toString methods but explicitly use
+// the error to string method. This is to avoid leaking error
+// objects between script tags in a browser setting.
+function ToStringCheckErrorObject(obj) {
+ if (obj instanceof $Error) {
+ return %_CallFunction(obj, errorToString);
+ } else {
+ return ToString(obj);
+ }
+}
+
+
function ToDetailString(obj) {
if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toString) {
var constructor = obj.constructor;
- if (!constructor) return ToString(obj);
+ if (!constructor) return ToStringCheckErrorObject(obj);
var constructorName = constructor.name;
- if (!constructorName) return ToString(obj);
+ if (!constructorName) return ToStringCheckErrorObject(obj);
return "#<" + GetInstanceName(constructorName) + ">";
- } else if (obj instanceof $Error) {
- // When formatting internally created error messages, do not
- // invoke overwritten error toString methods but explicitly use
- // the error to string method. This is to avoid leaking error
- // objects between script tags in a browser setting.
- return %_CallFunction(obj, errorToString);
} else {
- return ToString(obj);
+ return ToStringCheckErrorObject(obj);
}
}
@@ -202,7 +209,13 @@
array_indexof_not_defined: "Array.getIndexOf: Argument undefined",
object_not_extensible: "Can't add property %0, object is not extensible",
illegal_access: "Illegal access",
- invalid_preparser_data: "Invalid preparser data for function %0"
+ invalid_preparser_data: "Invalid preparser data for function %0",
+ strict_mode_with: "Strict mode code may not include a with statement",
+ strict_catch_variable: "Catch variable may not be eval or arguments in strict mode",
+ strict_param_name: "Parameter name eval or arguments is not allowed in strict mode",
+ strict_param_dupe: "Strict mode function may not have duplicate parameter names",
+ strict_var_name: "Variable name may not be eval or arguments in strict mode",
+ strict_function_name: "Function name may not be eval or arguments in strict mode",
};
}
var format = kMessages[message.type];
@@ -1006,19 +1019,44 @@
// Setup extra properties of the Error.prototype object.
$Error.prototype.message = '';
+// Global list of error objects visited during errorToString. This is
+// used to detect cycles in error toString formatting.
+var visited_errors = new $Array();
+var cyclic_error_marker = new $Object();
+
+function errorToStringDetectCycle() {
+ if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker;
+ try {
+ var type = this.type;
+ if (type && !this.hasOwnProperty("message")) {
+ var formatted = FormatMessage({ type: type, args: this.arguments });
+ return this.name + ": " + formatted;
+ }
+ var message = this.hasOwnProperty("message") ? (": " + this.message) : "";
+ return this.name + message;
+ } finally {
+ visited_errors.pop();
+ }
+}
+
function errorToString() {
- var type = this.type;
- if (type && !this.hasOwnProperty("message")) {
- return this.name + ": " + FormatMessage({ type: type, args: this.arguments });
+ // This helper function is needed because access to properties on
+ // the builtins object do not work inside of a catch clause.
+ function isCyclicErrorMarker(o) { return o === cyclic_error_marker; }
+
+ try {
+ return %_CallFunction(this, errorToStringDetectCycle);
+ } catch(e) {
+ // If this error message was encountered already return the empty
+ // string for it instead of recursively formatting it.
+ if (isCyclicErrorMarker(e)) return '';
+ else throw e;
}
- var message = this.hasOwnProperty("message") ? (": " + this.message) : "";
- return this.name + message;
}
%FunctionSetName(errorToString, 'toString');
%SetProperty($Error.prototype, 'toString', errorToString, DONT_ENUM);
-
// Boilerplate for exceptions for stack overflows. Used from
// Top::StackOverflow().
const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
« no previous file with comments | « src/liveobjectlist-inl.h ('k') | src/mips/ic-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698