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

Side by Side 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 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 7534 matching lines...) Expand 10 before | Expand all | Expand 10 after
12956 "o = {};\n" 13003 "o = {};\n"
12957 "o.__defineGetter__('f', function() { throw undefined; });\n" 13004 "o.__defineGetter__('f', function() { throw undefined; });\n"
12958 "o\n").As<Object>(); 13005 "o\n").As<Object>();
12959 CHECK(!with_js_getter.IsEmpty()); 13006 CHECK(!with_js_getter.IsEmpty());
12960 13007
12961 TryCatch try_catch; 13008 TryCatch try_catch;
12962 13009
12963 Local<Value> result = instance->GetRealNamedProperty(v8_str("f")); 13010 Local<Value> result = instance->GetRealNamedProperty(v8_str("f"));
12964 CHECK(try_catch.HasCaught()); 13011 CHECK(try_catch.HasCaught());
12965 try_catch.Reset(); 13012 try_catch.Reset();
12966 CHECK(result.IsEmpty()); 13013 // TODO(mstarzinger): The exception is propagated directly to the TryCatch
13014 // scope and is never scheduled, because there is no real JavaScript frame
13015 // between here and the ThrowingGetter. Fixing this will make the result a
13016 // proper empty handle again.
13017 CHECK(result->IsUndefined());
12967 13018
12968 result = another->GetRealNamedProperty(v8_str("f")); 13019 result = another->GetRealNamedProperty(v8_str("f"));
12969 CHECK(try_catch.HasCaught()); 13020 CHECK(try_catch.HasCaught());
12970 try_catch.Reset(); 13021 try_catch.Reset();
12971 CHECK(result.IsEmpty()); 13022 // TODO(mstarzinger): Likewise.
13023 CHECK(result->IsUndefined());
12972 13024
12973 result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f")); 13025 result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f"));
12974 CHECK(try_catch.HasCaught()); 13026 CHECK(try_catch.HasCaught());
12975 try_catch.Reset(); 13027 try_catch.Reset();
12976 CHECK(result.IsEmpty()); 13028 // TODO(mstarzinger): Likewise.
13029 CHECK(result->IsUndefined());
12977 13030
12978 result = another->Get(v8_str("f")); 13031 result = another->Get(v8_str("f"));
12979 CHECK(try_catch.HasCaught()); 13032 CHECK(try_catch.HasCaught());
12980 try_catch.Reset(); 13033 try_catch.Reset();
12981 CHECK(result.IsEmpty()); 13034 // TODO(mstarzinger): Likewise.
13035 CHECK(result->IsUndefined());
12982 13036
12983 result = with_js_getter->GetRealNamedProperty(v8_str("f")); 13037 result = with_js_getter->GetRealNamedProperty(v8_str("f"));
12984 CHECK(try_catch.HasCaught()); 13038 CHECK(try_catch.HasCaught());
12985 try_catch.Reset(); 13039 try_catch.Reset();
12986 CHECK(result.IsEmpty()); 13040 CHECK(result.IsEmpty());
12987 13041
12988 result = with_js_getter->Get(v8_str("f")); 13042 result = with_js_getter->Get(v8_str("f"));
12989 CHECK(try_catch.HasCaught()); 13043 CHECK(try_catch.HasCaught());
12990 try_catch.Reset(); 13044 try_catch.Reset();
12991 CHECK(result.IsEmpty()); 13045 CHECK(result.IsEmpty());
(...skipping 9522 matching lines...) Expand 10 before | Expand all | Expand 10 after
22514 v8::internal::FLAG_stack_size = 150; 22568 v8::internal::FLAG_stack_size = 150;
22515 LocalContext current; 22569 LocalContext current;
22516 v8::Isolate* isolate = current->GetIsolate(); 22570 v8::Isolate* isolate = current->GetIsolate();
22517 v8::HandleScope scope(isolate); 22571 v8::HandleScope scope(isolate);
22518 V8::SetCaptureStackTraceForUncaughtExceptions( 22572 V8::SetCaptureStackTraceForUncaughtExceptions(
22519 true, 10, v8::StackTrace::kDetailed); 22573 true, 10, v8::StackTrace::kDetailed);
22520 v8::TryCatch try_catch; 22574 v8::TryCatch try_catch;
22521 CompileRun("(function f(x) { f(x+1); })(0)"); 22575 CompileRun("(function f(x) { f(x+1); })(0)");
22522 CHECK(try_catch.HasCaught()); 22576 CHECK(try_catch.HasCaught());
22523 } 22577 }
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