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 2652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2663 Extension* extension = new Extension("autotest", kSimpleExtensionSource); | 2663 Extension* extension = new Extension("autotest", kSimpleExtensionSource); |
2664 extension->set_auto_enable(true); | 2664 extension->set_auto_enable(true); |
2665 v8::RegisterExtension(extension); | 2665 v8::RegisterExtension(extension); |
2666 v8::Handle<Context> context = Context::New(); | 2666 v8::Handle<Context> context = Context::New(); |
2667 Context::Scope lock(context); | 2667 Context::Scope lock(context); |
2668 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); | 2668 v8::Handle<Value> result = Script::Compile(v8_str("Foo()"))->Run(); |
2669 CHECK_EQ(result, v8::Integer::New(4)); | 2669 CHECK_EQ(result, v8::Integer::New(4)); |
2670 } | 2670 } |
2671 | 2671 |
2672 | 2672 |
| 2673 static const char* kSyntaxErrorInExtensionSource = |
| 2674 "["; |
| 2675 |
| 2676 |
| 2677 // Test that a syntax error in an extension does not cause a fatal |
| 2678 // error but results in an empty context. |
| 2679 THREADED_TEST(SyntaxErrorExtensions) { |
| 2680 v8::HandleScope handle_scope; |
| 2681 v8::RegisterExtension(new Extension("syntaxerror", |
| 2682 kSyntaxErrorInExtensionSource)); |
| 2683 const char* extension_names[] = { "syntaxerror" }; |
| 2684 v8::ExtensionConfiguration extensions(1, extension_names); |
| 2685 v8::Handle<Context> context = Context::New(&extensions); |
| 2686 CHECK(context.IsEmpty()); |
| 2687 } |
| 2688 |
| 2689 |
| 2690 static const char* kExceptionInExtensionSource = |
| 2691 "throw 42"; |
| 2692 |
| 2693 |
| 2694 // Test that an exception when installing an extension does not cause |
| 2695 // a fatal error but results in an empty context. |
| 2696 THREADED_TEST(ExceptionExtensions) { |
| 2697 v8::HandleScope handle_scope; |
| 2698 v8::RegisterExtension(new Extension("exception", |
| 2699 kExceptionInExtensionSource)); |
| 2700 const char* extension_names[] = { "exception" }; |
| 2701 v8::ExtensionConfiguration extensions(1, extension_names); |
| 2702 v8::Handle<Context> context = Context::New(&extensions); |
| 2703 CHECK(context.IsEmpty()); |
| 2704 } |
| 2705 |
| 2706 |
2673 static void CheckDependencies(const char* name, const char* expected) { | 2707 static void CheckDependencies(const char* name, const char* expected) { |
2674 v8::HandleScope handle_scope; | 2708 v8::HandleScope handle_scope; |
2675 v8::ExtensionConfiguration config(1, &name); | 2709 v8::ExtensionConfiguration config(1, &name); |
2676 LocalContext context(&config); | 2710 LocalContext context(&config); |
2677 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); | 2711 CHECK_EQ(String::New(expected), context->Global()->Get(v8_str("loaded"))); |
2678 } | 2712 } |
2679 | 2713 |
2680 | 2714 |
2681 /* | 2715 /* |
2682 * Configuration: | 2716 * Configuration: |
(...skipping 5709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8392 " i++;" | 8426 " i++;" |
8393 " return s(o);" | 8427 " return s(o);" |
8394 " }" | 8428 " }" |
8395 " }" | 8429 " }" |
8396 "};" | 8430 "};" |
8397 "s(o);"); | 8431 "s(o);"); |
8398 CHECK(try_catch.HasCaught()); | 8432 CHECK(try_catch.HasCaught()); |
8399 v8::String::Utf8Value value(try_catch.Exception()); | 8433 v8::String::Utf8Value value(try_catch.Exception()); |
8400 CHECK_EQ(0, strcmp(*value, "Hey!")); | 8434 CHECK_EQ(0, strcmp(*value, "Hey!")); |
8401 } | 8435 } |
OLD | NEW |