Revision: 12507
Author: [email protected]
Date: Fri Sep 14 04:43:46 2012
Log: Replace r12503. Explicitly check toString() for exception in d8's
print().
[email protected]
BUG=v8:2317
Review URL: https://chromiumcodereview.appspot.com/10911305
http://code.google.com/p/v8/source/detail?r=12507
Modified:
/branches/bleeding_edge/src/api.cc
/branches/bleeding_edge/src/d8.cc
/branches/bleeding_edge/test/cctest/test-api.cc
=======================================
--- /branches/bleeding_edge/src/api.cc Fri Sep 14 01:13:57 2012
+++ /branches/bleeding_edge/src/api.cc Fri Sep 14 04:43:46 2012
@@ -5500,6 +5500,7 @@
if (obj.IsEmpty()) return;
ENTER_V8(isolate);
i::HandleScope scope(isolate);
+ TryCatch try_catch;
Handle<String> str = obj->ToString();
if (str.IsEmpty()) return;
i::Handle<i::String> i_str = Utils::OpenHandle(*str);
@@ -5521,6 +5522,7 @@
if (obj.IsEmpty()) return;
ENTER_V8(isolate);
i::HandleScope scope(isolate);
+ TryCatch try_catch;
Handle<String> str = obj->ToString();
if (str.IsEmpty()) return;
length_ = str->Length();
@@ -5541,6 +5543,7 @@
if (obj.IsEmpty()) return;
ENTER_V8(isolate);
i::HandleScope scope(isolate);
+ TryCatch try_catch;
Handle<String> str = obj->ToString();
if (str.IsEmpty()) return;
length_ = str->Length();
=======================================
--- /branches/bleeding_edge/src/d8.cc Tue Aug 21 00:06:21 2012
+++ /branches/bleeding_edge/src/d8.cc Fri Sep 14 04:43:46 2012
@@ -200,7 +200,13 @@
if (i != 0) {
printf(" ");
}
- v8::String::Utf8Value str(args[i]);
+
+ // Explicitly catch potential exceptions in toString().
+ v8::TryCatch try_catch;
+ Handle<String> str_obj = args[i]->ToString();
+ if (try_catch.HasCaught()) return try_catch.ReThrow();
+
+ v8::String::Utf8Value str(str_obj);
int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(),
stdout));
if (n != str.length()) {
printf("Error in fwrite\n");
=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc Fri Sep 14 01:13:57 2012
+++ /branches/bleeding_edge/test/cctest/test-api.cc Fri Sep 14 04:43:46 2012
@@ -17513,37 +17513,4 @@
THREADED_TEST(SemaphoreInterruption) {
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
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev