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

Side by Side Diff: test/cctest/test-api.cc

Issue 399473006: Reland "Make v8::TryCatch able to consume natively thrown exceptions." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 5294 matching lines...) Expand 10 before | Expand all | Expand 10 after
5305 CompileRun( 5305 CompileRun(
5306 "try {\n" 5306 "try {\n"
5307 " throw new Error('a');\n" 5307 " throw new Error('a');\n"
5308 "} finally {\n" 5308 "} finally {\n"
5309 " native_with_try_catch();\n" 5309 " native_with_try_catch();\n"
5310 "}\n"); 5310 "}\n");
5311 CHECK(try_catch.HasCaught()); 5311 CHECK(try_catch.HasCaught());
5312 } 5312 }
5313 5313
5314 5314
5315 static void TryCatchNestedHelper(int depth) { 5315 static void TryCatchNested1Helper(int depth) {
5316 if (depth > 0) { 5316 if (depth > 0) {
5317 v8::TryCatch try_catch; 5317 v8::TryCatch try_catch;
5318 try_catch.SetVerbose(true); 5318 try_catch.SetVerbose(true);
5319 TryCatchNestedHelper(depth - 1); 5319 TryCatchNested1Helper(depth - 1);
5320 CHECK(try_catch.HasCaught()); 5320 CHECK(try_catch.HasCaught());
5321 try_catch.ReThrow(); 5321 try_catch.ReThrow();
5322 } else { 5322 } else {
5323 CcTest::isolate()->ThrowException(v8_str("back")); 5323 CcTest::isolate()->ThrowException(v8_str("E1"));
5324 } 5324 }
5325 } 5325 }
5326 5326
5327
5328 static void TryCatchNested2Helper(int depth) {
5329 if (depth > 0) {
5330 v8::TryCatch try_catch;
5331 try_catch.SetVerbose(true);
5332 TryCatchNested2Helper(depth - 1);
5333 CHECK(try_catch.HasCaught());
5334 try_catch.ReThrow();
5335 } else {
5336 CompileRun("throw 'E2';");
5337 }
5338 }
5339
5327 5340
5328 TEST(TryCatchNested) { 5341 TEST(TryCatchNested) {
5329 v8::V8::Initialize(); 5342 v8::V8::Initialize();
5330 LocalContext context; 5343 LocalContext context;
5331 v8::HandleScope scope(context->GetIsolate()); 5344 v8::HandleScope scope(context->GetIsolate());
5332 v8::TryCatch try_catch; 5345
5333 TryCatchNestedHelper(5); 5346 {
5334 CHECK(try_catch.HasCaught()); 5347 // Test nested try-catch with a native throw in the end.
5335 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back")); 5348 v8::TryCatch try_catch;
5349 TryCatchNested1Helper(5);
5350 CHECK(try_catch.HasCaught());
5351 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E1"));
5352 }
5353
5354 {
5355 // Test nested try-catch with a JavaScript throw in the end.
5356 v8::TryCatch try_catch;
5357 TryCatchNested2Helper(5);
5358 CHECK(try_catch.HasCaught());
5359 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2"));
5360 }
5336 } 5361 }
5337 5362
5338 5363
5339 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) { 5364 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) {
5340 CHECK(try_catch->HasCaught()); 5365 CHECK(try_catch->HasCaught());
5341 Handle<Message> message = try_catch->Message(); 5366 Handle<Message> message = try_catch->Message();
5342 Handle<Value> resource = message->GetScriptOrigin().ResourceName(); 5367 Handle<Value> resource = message->GetScriptOrigin().ResourceName();
5343 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner")); 5368 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner"));
5344 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()), 5369 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()),
5345 "Uncaught Error: a")); 5370 "Uncaught Error: a"));
(...skipping 25 matching lines...) Expand all
5371 v8::TryCatch try_catch; 5396 v8::TryCatch try_catch;
5372 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5397 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5373 templ->Set(v8_str("TryCatchMixedNestingHelper"), 5398 templ->Set(v8_str("TryCatchMixedNestingHelper"),
5374 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); 5399 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper));
5375 LocalContext context(0, templ); 5400 LocalContext context(0, templ);
5376 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); 5401 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1);
5377 TryCatchMixedNestingCheck(&try_catch); 5402 TryCatchMixedNestingCheck(&try_catch);
5378 } 5403 }
5379 5404
5380 5405
5406 void TryCatchNativeHelper(const v8::FunctionCallbackInfo<v8::Value>& args) {
5407 ApiTestFuzzer::Fuzz();
5408 v8::TryCatch try_catch;
5409 args.GetIsolate()->ThrowException(v8_str("boom"));
5410 CHECK(try_catch.HasCaught());
5411 }
5412
5413
5414 TEST(TryCatchNative) {
5415 v8::Isolate* isolate = CcTest::isolate();
5416 v8::HandleScope scope(isolate);
5417 v8::V8::Initialize();
5418 v8::TryCatch try_catch;
5419 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5420 templ->Set(v8_str("TryCatchNativeHelper"),
5421 v8::FunctionTemplate::New(isolate, TryCatchNativeHelper));
5422 LocalContext context(0, templ);
5423 CompileRun("TryCatchNativeHelper();");
5424 CHECK(!try_catch.HasCaught());
5425 }
5426
5427
5381 THREADED_TEST(Equality) { 5428 THREADED_TEST(Equality) {
5382 LocalContext context; 5429 LocalContext context;
5383 v8::Isolate* isolate = context->GetIsolate(); 5430 v8::Isolate* isolate = context->GetIsolate();
5384 v8::HandleScope scope(context->GetIsolate()); 5431 v8::HandleScope scope(context->GetIsolate());
5385 // Check that equality works at all before relying on CHECK_EQ 5432 // Check that equality works at all before relying on CHECK_EQ
5386 CHECK(v8_str("a")->Equals(v8_str("a"))); 5433 CHECK(v8_str("a")->Equals(v8_str("a")));
5387 CHECK(!v8_str("a")->Equals(v8_str("b"))); 5434 CHECK(!v8_str("a")->Equals(v8_str("b")));
5388 5435
5389 CHECK_EQ(v8_str("a"), v8_str("a")); 5436 CHECK_EQ(v8_str("a"), v8_str("a"));
5390 CHECK_NE(v8_str("a"), v8_str("b")); 5437 CHECK_NE(v8_str("a"), v8_str("b"));
(...skipping 17390 matching lines...) Expand 10 before | Expand all | Expand 10 after
22781 desc = x->GetOwnPropertyDescriptor(v8_str("p1")); 22828 desc = x->GetOwnPropertyDescriptor(v8_str("p1"));
22782 Local<Function> set = 22829 Local<Function> set =
22783 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set"))); 22830 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("set")));
22784 Local<Function> get = 22831 Local<Function> get =
22785 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get"))); 22832 Local<Function>::Cast(Local<Object>::Cast(desc)->Get(v8_str("get")));
22786 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL)); 22833 CHECK_EQ(v8_num(13), get->Call(x, 0, NULL));
22787 Handle<Value> args[] = { v8_num(14) }; 22834 Handle<Value> args[] = { v8_num(14) };
22788 set->Call(x, 1, args); 22835 set->Call(x, 1, args);
22789 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL)); 22836 CHECK_EQ(v8_num(14), get->Call(x, 0, NULL));
22790 } 22837 }
OLDNEW
« 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