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

Unified Diff: test/cctest/test-api.cc

Issue 287133005: Make v8::TryCatch able to consume natively thrown exceptions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Make ready for review. Created 6 years, 7 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/isolate.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 93c8e41f053795e02fb9a4cd698c525ec3db1ac2..a22a7e77673e4e26d6ac8e3367ed9c688fb88269 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -5343,15 +5343,28 @@ THREADED_TEST(TryCatchAndFinally) {
}
-static void TryCatchNestedHelper(int depth) {
+static void TryCatchNested1Helper(int depth) {
if (depth > 0) {
v8::TryCatch try_catch;
try_catch.SetVerbose(true);
- TryCatchNestedHelper(depth - 1);
+ TryCatchNested1Helper(depth - 1);
CHECK(try_catch.HasCaught());
try_catch.ReThrow();
} else {
- CcTest::isolate()->ThrowException(v8_str("back"));
+ CcTest::isolate()->ThrowException(v8_str("E1"));
+ }
+}
+
+
+static void TryCatchNested2Helper(int depth) {
+ if (depth > 0) {
+ v8::TryCatch try_catch;
+ try_catch.SetVerbose(true);
+ TryCatchNested2Helper(depth - 1);
+ CHECK(try_catch.HasCaught());
+ try_catch.ReThrow();
+ } else {
+ CompileRun("throw 'E2';");
}
}
@@ -5360,10 +5373,22 @@ TEST(TryCatchNested) {
v8::V8::Initialize();
LocalContext context;
v8::HandleScope scope(context->GetIsolate());
- v8::TryCatch try_catch;
- TryCatchNestedHelper(5);
- CHECK(try_catch.HasCaught());
- CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back"));
+
+ {
+ // Test nested try-catch with a native throw in the end.
+ v8::TryCatch try_catch;
+ TryCatchNested1Helper(5);
+ CHECK(try_catch.HasCaught());
+ CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E1"));
+ }
+
+ {
+ // Test nested try-catch with a JavaScript throw in the end.
+ v8::TryCatch try_catch;
+ TryCatchNested2Helper(5);
+ CHECK(try_catch.HasCaught());
+ CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2"));
+ }
}
@@ -5409,6 +5434,28 @@ TEST(TryCatchMixedNesting) {
}
+void TryCatchNativeHelper(const v8::FunctionCallbackInfo<v8::Value>& args) {
+ ApiTestFuzzer::Fuzz();
+ v8::TryCatch try_catch;
+ args.GetIsolate()->ThrowException(v8_str("boom"));
+ CHECK(try_catch.HasCaught());
+}
+
+
+TEST(TryCatchNative) {
+ v8::Isolate* isolate = CcTest::isolate();
+ v8::HandleScope scope(isolate);
+ v8::V8::Initialize();
+ v8::TryCatch try_catch;
+ Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
+ templ->Set(v8_str("TryCatchNativeHelper"),
+ v8::FunctionTemplate::New(isolate, TryCatchNativeHelper));
+ LocalContext context(0, templ);
+ CompileRun("TryCatchNativeHelper();");
+ CHECK(!try_catch.HasCaught());
+}
+
+
THREADED_TEST(Equality) {
LocalContext context;
v8::Isolate* isolate = context->GetIsolate();
@@ -12963,22 +13010,29 @@ THREADED_TEST(VariousGetPropertiesAndThrowingCallbacks) {
Local<Value> result = instance->GetRealNamedProperty(v8_str("f"));
CHECK(try_catch.HasCaught());
try_catch.Reset();
- CHECK(result.IsEmpty());
+ // TODO(mstarzinger): The exception is propagated directly to the TryCatch
+ // scope and is never scheduled, because there is no real JavaScript frame
+ // between here and the ThrowingGetter. Fixing this will make the result a
+ // proper empty handle again.
+ CHECK(result->IsUndefined());
result = another->GetRealNamedProperty(v8_str("f"));
CHECK(try_catch.HasCaught());
try_catch.Reset();
- CHECK(result.IsEmpty());
+ // TODO(mstarzinger): Likewise.
+ CHECK(result->IsUndefined());
result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f"));
CHECK(try_catch.HasCaught());
try_catch.Reset();
- CHECK(result.IsEmpty());
+ // TODO(mstarzinger): Likewise.
+ CHECK(result->IsUndefined());
result = another->Get(v8_str("f"));
CHECK(try_catch.HasCaught());
try_catch.Reset();
- CHECK(result.IsEmpty());
+ // TODO(mstarzinger): Likewise.
+ CHECK(result->IsUndefined());
result = with_js_getter->GetRealNamedProperty(v8_str("f"));
CHECK(try_catch.HasCaught());
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698