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

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

Issue 291393002: Make v8::TryCatch able to consume natively thrown exceptions (again). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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 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 5325 matching lines...) Expand 10 before | Expand all | Expand 10 after
5336 CompileRun( 5336 CompileRun(
5337 "try {\n" 5337 "try {\n"
5338 " throw new Error('a');\n" 5338 " throw new Error('a');\n"
5339 "} finally {\n" 5339 "} finally {\n"
5340 " native_with_try_catch();\n" 5340 " native_with_try_catch();\n"
5341 "}\n"); 5341 "}\n");
5342 CHECK(try_catch.HasCaught()); 5342 CHECK(try_catch.HasCaught());
5343 } 5343 }
5344 5344
5345 5345
5346 static void TryCatchNestedHelper(int depth) { 5346 static void TryCatchNested1Helper(int depth) {
5347 if (depth > 0) { 5347 if (depth > 0) {
5348 v8::TryCatch try_catch; 5348 v8::TryCatch try_catch;
5349 try_catch.SetVerbose(true); 5349 try_catch.SetVerbose(true);
5350 TryCatchNestedHelper(depth - 1); 5350 TryCatchNested1Helper(depth - 1);
5351 CHECK(try_catch.HasCaught()); 5351 CHECK(try_catch.HasCaught());
5352 try_catch.ReThrow(); 5352 try_catch.ReThrow();
5353 } else { 5353 } else {
5354 CcTest::isolate()->ThrowException(v8_str("back")); 5354 CcTest::isolate()->ThrowException(v8_str("E1"));
5355 } 5355 }
5356 } 5356 }
5357 5357
5358
5359 static void TryCatchNested2Helper(int depth) {
5360 if (depth > 0) {
5361 v8::TryCatch try_catch;
5362 try_catch.SetVerbose(true);
5363 TryCatchNested2Helper(depth - 1);
5364 CHECK(try_catch.HasCaught());
5365 try_catch.ReThrow();
5366 } else {
5367 CompileRun("throw 'E2';");
5368 }
5369 }
5370
5358 5371
5359 TEST(TryCatchNested) { 5372 TEST(TryCatchNested) {
5360 v8::V8::Initialize(); 5373 v8::V8::Initialize();
5361 LocalContext context; 5374 LocalContext context;
5362 v8::HandleScope scope(context->GetIsolate()); 5375 v8::HandleScope scope(context->GetIsolate());
5363 v8::TryCatch try_catch; 5376
5364 TryCatchNestedHelper(5); 5377 {
5365 CHECK(try_catch.HasCaught()); 5378 // Test nested try-catch with a native throw in the end.
5366 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back")); 5379 v8::TryCatch try_catch;
5380 TryCatchNested1Helper(5);
5381 CHECK(try_catch.HasCaught());
5382 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E1"));
5383 }
5384
5385 {
5386 // Test nested try-catch with a JavaScript throw in the end.
5387 v8::TryCatch try_catch;
5388 TryCatchNested2Helper(5);
5389 CHECK(try_catch.HasCaught());
5390 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "E2"));
5391 }
5367 } 5392 }
5368 5393
5369 5394
5370 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) { 5395 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) {
5371 CHECK(try_catch->HasCaught()); 5396 CHECK(try_catch->HasCaught());
5372 Handle<Message> message = try_catch->Message(); 5397 Handle<Message> message = try_catch->Message();
5373 Handle<Value> resource = message->GetScriptResourceName(); 5398 Handle<Value> resource = message->GetScriptResourceName();
5374 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner")); 5399 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner"));
5375 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()), 5400 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()),
5376 "Uncaught Error: a")); 5401 "Uncaught Error: a"));
(...skipping 25 matching lines...) Expand all
5402 v8::TryCatch try_catch; 5427 v8::TryCatch try_catch;
5403 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5428 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5404 templ->Set(v8_str("TryCatchMixedNestingHelper"), 5429 templ->Set(v8_str("TryCatchMixedNestingHelper"),
5405 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); 5430 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper));
5406 LocalContext context(0, templ); 5431 LocalContext context(0, templ);
5407 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); 5432 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1);
5408 TryCatchMixedNestingCheck(&try_catch); 5433 TryCatchMixedNestingCheck(&try_catch);
5409 } 5434 }
5410 5435
5411 5436
5437 void TryCatchNativeHelper(const v8::FunctionCallbackInfo<v8::Value>& args) {
5438 ApiTestFuzzer::Fuzz();
5439 v8::TryCatch try_catch;
5440 args.GetIsolate()->ThrowException(v8_str("boom"));
5441 CHECK(try_catch.HasCaught());
5442 }
5443
5444
5445 TEST(TryCatchNative) {
5446 v8::Isolate* isolate = CcTest::isolate();
5447 v8::HandleScope scope(isolate);
5448 v8::V8::Initialize();
5449 v8::TryCatch try_catch;
5450 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5451 templ->Set(v8_str("TryCatchNativeHelper"),
5452 v8::FunctionTemplate::New(isolate, TryCatchNativeHelper));
5453 LocalContext context(0, templ);
5454 CompileRun("TryCatchNativeHelper();");
5455 CHECK(!try_catch.HasCaught());
5456 }
5457
5458
5412 THREADED_TEST(Equality) { 5459 THREADED_TEST(Equality) {
5413 LocalContext context; 5460 LocalContext context;
5414 v8::Isolate* isolate = context->GetIsolate(); 5461 v8::Isolate* isolate = context->GetIsolate();
5415 v8::HandleScope scope(context->GetIsolate()); 5462 v8::HandleScope scope(context->GetIsolate());
5416 // Check that equality works at all before relying on CHECK_EQ 5463 // Check that equality works at all before relying on CHECK_EQ
5417 CHECK(v8_str("a")->Equals(v8_str("a"))); 5464 CHECK(v8_str("a")->Equals(v8_str("a")));
5418 CHECK(!v8_str("a")->Equals(v8_str("b"))); 5465 CHECK(!v8_str("a")->Equals(v8_str("b")));
5419 5466
5420 CHECK_EQ(v8_str("a"), v8_str("a")); 5467 CHECK_EQ(v8_str("a"), v8_str("a"));
5421 CHECK_NE(v8_str("a"), v8_str("b")); 5468 CHECK_NE(v8_str("a"), v8_str("b"));
(...skipping 17203 matching lines...) Expand 10 before | Expand all | Expand 10 after
22625 Local<Script> script = v8::ScriptCompiler::Compile( 22672 Local<Script> script = v8::ScriptCompiler::Compile(
22626 isolate, &script_source); 22673 isolate, &script_source);
22627 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); 22674 Local<Value> script_name = script->GetUnboundScript()->GetScriptName();
22628 CHECK(!script_name.IsEmpty()); 22675 CHECK(!script_name.IsEmpty());
22629 CHECK(script_name->IsString()); 22676 CHECK(script_name->IsString());
22630 String::Utf8Value utf8_name(script_name); 22677 String::Utf8Value utf8_name(script_name);
22631 CHECK_EQ(url, *utf8_name); 22678 CHECK_EQ(url, *utf8_name);
22632 int line_number = script->GetUnboundScript()->GetLineNumber(0); 22679 int line_number = script->GetUnboundScript()->GetLineNumber(0);
22633 CHECK_EQ(13, line_number); 22680 CHECK_EQ(13, line_number);
22634 } 22681 }
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