OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 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 3584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3595 CHECK(trouble->IsFunction()); | 3595 CHECK(trouble->IsFunction()); |
3596 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); | 3596 Local<Value> trouble_callee = global->Get(v8_str("trouble_callee")); |
3597 CHECK(trouble_callee->IsFunction()); | 3597 CHECK(trouble_callee->IsFunction()); |
3598 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); | 3598 Local<Value> trouble_caller = global->Get(v8_str("trouble_caller")); |
3599 CHECK(trouble_caller->IsFunction()); | 3599 CHECK(trouble_caller->IsFunction()); |
3600 Function::Cast(*trouble_caller)->Call(global, 0, NULL); | 3600 Function::Cast(*trouble_caller)->Call(global, 0, NULL); |
3601 CHECK_EQ(1, report_count); | 3601 CHECK_EQ(1, report_count); |
3602 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); | 3602 v8::V8::RemoveMessageListeners(ApiUncaughtExceptionTestListener); |
3603 } | 3603 } |
3604 | 3604 |
| 3605 static const char* script_resource_name = "ExceptionInNativeScript.js"; |
| 3606 static void ExceptionInNativeScriptTestListener(v8::Handle<v8::Message> message, |
| 3607 v8::Handle<Value>) { |
| 3608 v8::Handle<v8::Value> name_val = message->GetScriptResourceName(); |
| 3609 CHECK(!name_val.IsEmpty() && name_val->IsString()); |
| 3610 v8::String::AsciiValue name(message->GetScriptResourceName()); |
| 3611 CHECK_EQ(script_resource_name, *name); |
| 3612 CHECK_EQ(3, message->GetLineNumber()); |
| 3613 v8::String::AsciiValue source_line(message->GetSourceLine()); |
| 3614 CHECK_EQ(" new o.foo();", *source_line); |
| 3615 } |
| 3616 |
| 3617 TEST(ExceptionInNativeScript) { |
| 3618 v8::HandleScope scope; |
| 3619 LocalContext env; |
| 3620 v8::V8::AddMessageListener(ExceptionInNativeScriptTestListener); |
| 3621 |
| 3622 Local<v8::FunctionTemplate> fun = v8::FunctionTemplate::New(TroubleCallback); |
| 3623 v8::Local<v8::Object> global = env->Global(); |
| 3624 global->Set(v8_str("trouble"), fun->GetFunction()); |
| 3625 |
| 3626 Script::Compile(v8_str("function trouble() {\n" |
| 3627 " var o = {};\n" |
| 3628 " new o.foo();\n" |
| 3629 "};"), v8::String::New(script_resource_name))->Run(); |
| 3630 Local<Value> trouble = global->Get(v8_str("trouble")); |
| 3631 CHECK(trouble->IsFunction()); |
| 3632 Function::Cast(*trouble)->Call(global, 0, NULL); |
| 3633 v8::V8::RemoveMessageListeners(ExceptionInNativeScriptTestListener); |
| 3634 } |
| 3635 |
3605 | 3636 |
3606 TEST(CompilationErrorUsingTryCatchHandler) { | 3637 TEST(CompilationErrorUsingTryCatchHandler) { |
3607 v8::HandleScope scope; | 3638 v8::HandleScope scope; |
3608 LocalContext env; | 3639 LocalContext env; |
3609 v8::TryCatch try_catch; | 3640 v8::TryCatch try_catch; |
3610 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile.")); | 3641 Script::Compile(v8_str("This doesn't &*&@#$&*^ compile.")); |
3611 CHECK_NE(NULL, *try_catch.Exception()); | 3642 CHECK_NE(NULL, *try_catch.Exception()); |
3612 CHECK(try_catch.HasCaught()); | 3643 CHECK(try_catch.HasCaught()); |
3613 } | 3644 } |
3614 | 3645 |
(...skipping 5088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8703 CompileRun(source_exception); | 8734 CompileRun(source_exception); |
8704 other_context->Exit(); | 8735 other_context->Exit(); |
8705 v8::internal::Heap::CollectAllGarbage(false); | 8736 v8::internal::Heap::CollectAllGarbage(false); |
8706 if (GetGlobalObjectsCount() == 1) break; | 8737 if (GetGlobalObjectsCount() == 1) break; |
8707 } | 8738 } |
8708 CHECK_GE(2, gc_count); | 8739 CHECK_GE(2, gc_count); |
8709 CHECK_EQ(1, GetGlobalObjectsCount()); | 8740 CHECK_EQ(1, GetGlobalObjectsCount()); |
8710 | 8741 |
8711 other_context.Dispose(); | 8742 other_context.Dispose(); |
8712 } | 8743 } |
OLD | NEW |