Not mask exception thrown by toString in String::UtfValue etc.

R=jkummerow@chromium.org
BUG=v8:2317

Review URL: https://chromiumcodereview.appspot.com/10917236

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12503 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2012-09-14 08:13:57 +00:00
parent e8e675f259
commit 4fe330c055
2 changed files with 33 additions and 3 deletions

View File

@ -5500,7 +5500,6 @@ String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
if (obj.IsEmpty()) return; if (obj.IsEmpty()) return;
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
TryCatch try_catch;
Handle<String> str = obj->ToString(); Handle<String> str = obj->ToString();
if (str.IsEmpty()) return; if (str.IsEmpty()) return;
i::Handle<i::String> i_str = Utils::OpenHandle(*str); i::Handle<i::String> i_str = Utils::OpenHandle(*str);
@ -5522,7 +5521,6 @@ String::AsciiValue::AsciiValue(v8::Handle<v8::Value> obj)
if (obj.IsEmpty()) return; if (obj.IsEmpty()) return;
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
TryCatch try_catch;
Handle<String> str = obj->ToString(); Handle<String> str = obj->ToString();
if (str.IsEmpty()) return; if (str.IsEmpty()) return;
length_ = str->Length(); length_ = str->Length();
@ -5543,7 +5541,6 @@ String::Value::Value(v8::Handle<v8::Value> obj)
if (obj.IsEmpty()) return; if (obj.IsEmpty()) return;
ENTER_V8(isolate); ENTER_V8(isolate);
i::HandleScope scope(isolate); i::HandleScope scope(isolate);
TryCatch try_catch;
Handle<String> str = obj->ToString(); Handle<String> str = obj->ToString();
if (str.IsEmpty()) return; if (str.IsEmpty()) return;
length_ = str->Length(); length_ = str->Length();

View File

@ -17513,4 +17513,37 @@ class ThreadInterruptTest {
THREADED_TEST(SemaphoreInterruption) { THREADED_TEST(SemaphoreInterruption) {
ThreadInterruptTest().RunTest(); ThreadInterruptTest().RunTest();
} }
TEST(Utf8ValueException) {
v8::HandleScope scope;
LocalContext context;
Handle<Value> object = CompileRun(
"var obj = { toString : function() { throw 'deadbeef'; } }; obj");
{ v8::TryCatch try_catch;
v8::String::Utf8Value utf8_value(object);
CHECK(try_catch.HasCaught());
CHECK_EQ("deadbeef", *v8::String::Utf8Value(try_catch.Exception()));
}
{ v8::TryCatch try_catch;
v8::String::AsciiValue ascii_value(object);
CHECK(try_catch.HasCaught());
CHECK_EQ("deadbeef", *v8::String::Utf8Value(try_catch.Exception()));
}
{ v8::TryCatch try_catch;
v8::String::Value value(object);
CHECK(try_catch.HasCaught());
CHECK_EQ("deadbeef", *v8::String::Utf8Value(try_catch.Exception()));
}
// It should work fine without any TryCatch.
v8::String::Utf8Value utf8_value(object);
v8::String::AsciiValue ascii_value(object);
v8::String::Value value(object);
}
#endif // WIN32 #endif // WIN32