}
+// 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);
}
}
CompileRun("ReferenceError.prototype.toString ="
" function() { return 'Whoops' }");
CompileRun("asdf;");
+ CompileRun("ReferenceError.prototype.constructor.name = void 0;");
+ CompileRun("asdf;");
+ CompileRun("ReferenceError.prototype.constructor = void 0;");
+ CompileRun("asdf;");
v8::Handle<Value> string = CompileRun("try { asdf; } catch(e) { e + ''; }");
CHECK(string->Equals(v8_str("Whoops")));
v8::V8::RemoveMessageListeners(check_message);