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

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

Issue 296133013: Revert "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 TryCatchNested1Helper(int depth) { 5346 static void TryCatchNestedHelper(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 TryCatchNested1Helper(depth - 1); 5350 TryCatchNestedHelper(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("E1")); 5354 CcTest::isolate()->ThrowException(v8_str("back"));
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
5371 5358
5372 TEST(TryCatchNested) { 5359 TEST(TryCatchNested) {
5373 v8::V8::Initialize(); 5360 v8::V8::Initialize();
5374 LocalContext context; 5361 LocalContext context;
5375 v8::HandleScope scope(context->GetIsolate()); 5362 v8::HandleScope scope(context->GetIsolate());
5376 5363 v8::TryCatch try_catch;
5377 { 5364 TryCatchNestedHelper(5);
5378 // Test nested try-catch with a native throw in the end. 5365 CHECK(try_catch.HasCaught());
5379 v8::TryCatch try_catch; 5366 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(try_catch.Exception()), "back"));
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 }
5392 } 5367 }
5393 5368
5394 5369
5395 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) { 5370 void TryCatchMixedNestingCheck(v8::TryCatch* try_catch) {
5396 CHECK(try_catch->HasCaught()); 5371 CHECK(try_catch->HasCaught());
5397 Handle<Message> message = try_catch->Message(); 5372 Handle<Message> message = try_catch->Message();
5398 Handle<Value> resource = message->GetScriptResourceName(); 5373 Handle<Value> resource = message->GetScriptResourceName();
5399 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner")); 5374 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(resource), "inner"));
5400 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()), 5375 CHECK_EQ(0, strcmp(*v8::String::Utf8Value(message->Get()),
5401 "Uncaught Error: a")); 5376 "Uncaught Error: a"));
(...skipping 25 matching lines...) Expand all
5427 v8::TryCatch try_catch; 5402 v8::TryCatch try_catch;
5428 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate); 5403 Local<ObjectTemplate> templ = ObjectTemplate::New(isolate);
5429 templ->Set(v8_str("TryCatchMixedNestingHelper"), 5404 templ->Set(v8_str("TryCatchMixedNestingHelper"),
5430 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper)); 5405 v8::FunctionTemplate::New(isolate, TryCatchMixedNestingHelper));
5431 LocalContext context(0, templ); 5406 LocalContext context(0, templ);
5432 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1); 5407 CompileRunWithOrigin("TryCatchMixedNestingHelper();\n", "outer", 1, 1);
5433 TryCatchMixedNestingCheck(&try_catch); 5408 TryCatchMixedNestingCheck(&try_catch);
5434 } 5409 }
5435 5410
5436 5411
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
5459 THREADED_TEST(Equality) { 5412 THREADED_TEST(Equality) {
5460 LocalContext context; 5413 LocalContext context;
5461 v8::Isolate* isolate = context->GetIsolate(); 5414 v8::Isolate* isolate = context->GetIsolate();
5462 v8::HandleScope scope(context->GetIsolate()); 5415 v8::HandleScope scope(context->GetIsolate());
5463 // Check that equality works at all before relying on CHECK_EQ 5416 // Check that equality works at all before relying on CHECK_EQ
5464 CHECK(v8_str("a")->Equals(v8_str("a"))); 5417 CHECK(v8_str("a")->Equals(v8_str("a")));
5465 CHECK(!v8_str("a")->Equals(v8_str("b"))); 5418 CHECK(!v8_str("a")->Equals(v8_str("b")));
5466 5419
5467 CHECK_EQ(v8_str("a"), v8_str("a")); 5420 CHECK_EQ(v8_str("a"), v8_str("a"));
5468 CHECK_NE(v8_str("a"), v8_str("b")); 5421 CHECK_NE(v8_str("a"), v8_str("b"));
(...skipping 17203 matching lines...) Expand 10 before | Expand all | Expand 10 after
22672 Local<Script> script = v8::ScriptCompiler::Compile( 22625 Local<Script> script = v8::ScriptCompiler::Compile(
22673 isolate, &script_source); 22626 isolate, &script_source);
22674 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); 22627 Local<Value> script_name = script->GetUnboundScript()->GetScriptName();
22675 CHECK(!script_name.IsEmpty()); 22628 CHECK(!script_name.IsEmpty());
22676 CHECK(script_name->IsString()); 22629 CHECK(script_name->IsString());
22677 String::Utf8Value utf8_name(script_name); 22630 String::Utf8Value utf8_name(script_name);
22678 CHECK_EQ(url, *utf8_name); 22631 CHECK_EQ(url, *utf8_name);
22679 int line_number = script->GetUnboundScript()->GetLineNumber(0); 22632 int line_number = script->GetUnboundScript()->GetLineNumber(0);
22680 CHECK_EQ(13, line_number); 22633 CHECK_EQ(13, line_number);
22681 } 22634 }
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