OLD | NEW |
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 Loading... |
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 Loading... |
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 7534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13003 "o = {};\n" | 12956 "o = {};\n" |
13004 "o.__defineGetter__('f', function() { throw undefined; });\n" | 12957 "o.__defineGetter__('f', function() { throw undefined; });\n" |
13005 "o\n").As<Object>(); | 12958 "o\n").As<Object>(); |
13006 CHECK(!with_js_getter.IsEmpty()); | 12959 CHECK(!with_js_getter.IsEmpty()); |
13007 | 12960 |
13008 TryCatch try_catch; | 12961 TryCatch try_catch; |
13009 | 12962 |
13010 Local<Value> result = instance->GetRealNamedProperty(v8_str("f")); | 12963 Local<Value> result = instance->GetRealNamedProperty(v8_str("f")); |
13011 CHECK(try_catch.HasCaught()); | 12964 CHECK(try_catch.HasCaught()); |
13012 try_catch.Reset(); | 12965 try_catch.Reset(); |
13013 // TODO(mstarzinger): The exception is propagated directly to the TryCatch | 12966 CHECK(result.IsEmpty()); |
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()); | |
13018 | 12967 |
13019 result = another->GetRealNamedProperty(v8_str("f")); | 12968 result = another->GetRealNamedProperty(v8_str("f")); |
13020 CHECK(try_catch.HasCaught()); | 12969 CHECK(try_catch.HasCaught()); |
13021 try_catch.Reset(); | 12970 try_catch.Reset(); |
13022 // TODO(mstarzinger): Likewise. | 12971 CHECK(result.IsEmpty()); |
13023 CHECK(result->IsUndefined()); | |
13024 | 12972 |
13025 result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f")); | 12973 result = another->GetRealNamedPropertyInPrototypeChain(v8_str("f")); |
13026 CHECK(try_catch.HasCaught()); | 12974 CHECK(try_catch.HasCaught()); |
13027 try_catch.Reset(); | 12975 try_catch.Reset(); |
13028 // TODO(mstarzinger): Likewise. | 12976 CHECK(result.IsEmpty()); |
13029 CHECK(result->IsUndefined()); | |
13030 | 12977 |
13031 result = another->Get(v8_str("f")); | 12978 result = another->Get(v8_str("f")); |
13032 CHECK(try_catch.HasCaught()); | 12979 CHECK(try_catch.HasCaught()); |
13033 try_catch.Reset(); | 12980 try_catch.Reset(); |
13034 // TODO(mstarzinger): Likewise. | 12981 CHECK(result.IsEmpty()); |
13035 CHECK(result->IsUndefined()); | |
13036 | 12982 |
13037 result = with_js_getter->GetRealNamedProperty(v8_str("f")); | 12983 result = with_js_getter->GetRealNamedProperty(v8_str("f")); |
13038 CHECK(try_catch.HasCaught()); | 12984 CHECK(try_catch.HasCaught()); |
13039 try_catch.Reset(); | 12985 try_catch.Reset(); |
13040 CHECK(result.IsEmpty()); | 12986 CHECK(result.IsEmpty()); |
13041 | 12987 |
13042 result = with_js_getter->Get(v8_str("f")); | 12988 result = with_js_getter->Get(v8_str("f")); |
13043 CHECK(try_catch.HasCaught()); | 12989 CHECK(try_catch.HasCaught()); |
13044 try_catch.Reset(); | 12990 try_catch.Reset(); |
13045 CHECK(result.IsEmpty()); | 12991 CHECK(result.IsEmpty()); |
(...skipping 9634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
22680 Local<Script> script = v8::ScriptCompiler::Compile( | 22626 Local<Script> script = v8::ScriptCompiler::Compile( |
22681 isolate, &script_source); | 22627 isolate, &script_source); |
22682 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); | 22628 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); |
22683 CHECK(!script_name.IsEmpty()); | 22629 CHECK(!script_name.IsEmpty()); |
22684 CHECK(script_name->IsString()); | 22630 CHECK(script_name->IsString()); |
22685 String::Utf8Value utf8_name(script_name); | 22631 String::Utf8Value utf8_name(script_name); |
22686 CHECK_EQ(url, *utf8_name); | 22632 CHECK_EQ(url, *utf8_name); |
22687 int line_number = script->GetUnboundScript()->GetLineNumber(0); | 22633 int line_number = script->GetUnboundScript()->GetLineNumber(0); |
22688 CHECK_EQ(13, line_number); | 22634 CHECK_EQ(13, line_number); |
22689 } | 22635 } |
OLD | NEW |