Commit 471c0d29 authored by ager@chromium.org's avatar ager@chromium.org

Avoid callbacks to user code during error formatting in a couple of

other situations.

Do not use overwritten Object.prototype.hasOwnProperty and
Array.prototype.pop. Do not use split and join in the error formatting
implementation. They are too big to control and their generality is
not needed.

Review URL: http://codereview.chromium.org/6287041

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@6552 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5264d17d
...@@ -171,8 +171,9 @@ function Join(array, length, separator, convert) { ...@@ -171,8 +171,9 @@ function Join(array, length, separator, convert) {
} }
return %StringBuilderConcat(elements, length2, ''); return %StringBuilderConcat(elements, length2, '');
} finally { } finally {
// Make sure to pop the visited array no matter what happens. // Make sure to remove the last element of the visited array no
if (is_array) visited_arrays.pop(); // matter what happens.
if (is_array) visited_arrays.length = visited_arrays.length - 1;
} }
} }
......
This diff is collapsed.
...@@ -1084,9 +1084,9 @@ ErrorMirror.prototype.toText = function() { ...@@ -1084,9 +1084,9 @@ ErrorMirror.prototype.toText = function() {
// Use the same text representation as in messages.js. // Use the same text representation as in messages.js.
var text; var text;
try { try {
str = builtins.ToDetailString(this.value_); str = %_CallFunction(this.value_, builtins.errorToString);
} catch (e) { } catch (e) {
str = '#<an Error>'; str = '#<Error>';
} }
return str; return str;
} }
......
...@@ -2369,13 +2369,25 @@ static void check_reference_error_message( ...@@ -2369,13 +2369,25 @@ static void check_reference_error_message(
} }
// Test that overwritten toString methods are not invoked on uncaught static v8::Handle<Value> Fail(const v8::Arguments& args) {
// exception formatting. However, they are invoked when performing ApiTestFuzzer::Fuzz();
// normal error string conversions. CHECK(false);
return v8::Undefined();
}
// Test that overwritten methods are not invoked on uncaught exception
// formatting. However, they are invoked when performing normal error
// string conversions.
TEST(APIThrowMessageOverwrittenToString) { TEST(APIThrowMessageOverwrittenToString) {
v8::HandleScope scope; v8::HandleScope scope;
v8::V8::AddMessageListener(check_reference_error_message); v8::V8::AddMessageListener(check_reference_error_message);
LocalContext context; Local<ObjectTemplate> templ = ObjectTemplate::New();
templ->Set(v8_str("fail"), v8::FunctionTemplate::New(Fail));
LocalContext context(NULL, templ);
CompileRun("Array.prototype.pop = fail;");
CompileRun("Object.prototype.hasOwnProperty = fail;");
CompileRun("Object.prototype.toString = function f() { return 'Yikes'; }");
CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }"); CompileRun("Number.prototype.toString = function f() { return 'Yikes'; }");
CompileRun("String.prototype.toString = function f() { return 'Yikes'; }"); CompileRun("String.prototype.toString = function f() { return 'Yikes'; }");
CompileRun("ReferenceError.prototype.toString =" CompileRun("ReferenceError.prototype.toString ="
......
...@@ -76,7 +76,7 @@ function testErrorMirror(e) { ...@@ -76,7 +76,7 @@ function testErrorMirror(e) {
} }
assertTrue(found_message, 'Property message not found'); assertTrue(found_message, 'Property message not found');
} }
// Check the formatted text (regress 1231579). // Check the formatted text (regress 1231579).
assertEquals(fromJSON.text, e.toString(), 'toString'); assertEquals(fromJSON.text, e.toString(), 'toString');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment