| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 6 | 6 |
| 7 #include "vm/assert.h" | 7 #include "vm/assert.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_api_state.h" | 9 #include "vm/dart_api_state.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| (...skipping 2748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2759 | 2759 |
| 2760 | 2760 |
| 2761 static bool RunLoopTestCallback(void* data, char** error) { | 2761 static bool RunLoopTestCallback(void* data, char** error) { |
| 2762 const char* kScriptChars = | 2762 const char* kScriptChars = |
| 2763 "#import('builtin');\n" | 2763 "#import('builtin');\n" |
| 2764 "class MyIsolate extends Isolate {\n" | 2764 "class MyIsolate extends Isolate {\n" |
| 2765 " MyIsolate() : super() { }\n" | 2765 " MyIsolate() : super() { }\n" |
| 2766 " void main() {\n" | 2766 " void main() {\n" |
| 2767 " port.receive((message, replyTo) {\n" | 2767 " port.receive((message, replyTo) {\n" |
| 2768 " if (message) {\n" | 2768 " if (message) {\n" |
| 2769 " throw new Exception('MakeVMExit');\n" | 2769 " throw new Exception('MakeChildExit');\n" |
| 2770 " } else {\n" | 2770 " } else {\n" |
| 2771 " replyTo.call('hello');\n" | 2771 " replyTo.call('hello');\n" |
| 2772 " port.close();\n" | 2772 " port.close();\n" |
| 2773 " }\n" | 2773 " }\n" |
| 2774 " });\n" | 2774 " });\n" |
| 2775 " }\n" | 2775 " }\n" |
| 2776 "}\n" | 2776 "}\n" |
| 2777 "\n" | 2777 "\n" |
| 2778 "void main(message) {\n" | 2778 "void main(exc_child, exc_parent) {\n" |
| 2779 " new MyIsolate().spawn().then((port) {\n" | 2779 " new MyIsolate().spawn().then((port) {\n" |
| 2780 " port.call(message).receive((message, replyTo) {\n" | 2780 " port.call(exc_child).receive((message, replyTo) {\n" |
| 2781 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n" | 2781 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n" |
| 2782 " if (exc_parent) throw new Exception('MakeParentExit');\n" |
| 2782 " });\n" | 2783 " });\n" |
| 2783 " });\n" | 2784 " });\n" |
| 2784 "}\n"; | 2785 "}\n"; |
| 2785 | 2786 |
| 2786 if (Dart_CurrentIsolate() != NULL) { | 2787 if (Dart_CurrentIsolate() != NULL) { |
| 2787 Dart_ExitIsolate(); | 2788 Dart_ExitIsolate(); |
| 2788 } | 2789 } |
| 2789 Dart_Isolate isolate = TestCase::CreateTestIsolate(); | 2790 Dart_Isolate isolate = TestCase::CreateTestIsolate(); |
| 2790 ASSERT(isolate != NULL); | 2791 ASSERT(isolate != NULL); |
| 2791 Dart_EnterScope(); | 2792 Dart_EnterScope(); |
| 2792 Dart_Handle url = Dart_NewString(TestCase::url()); | 2793 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 2793 Dart_Handle source = Dart_NewString(kScriptChars); | 2794 Dart_Handle source = Dart_NewString(kScriptChars); |
| 2794 Dart_Handle lib = Dart_LoadScript(url, source, TestCase::library_handler); | 2795 Dart_Handle lib = Dart_LoadScript(url, source, TestCase::library_handler); |
| 2795 EXPECT_VALID(lib); | 2796 EXPECT_VALID(lib); |
| 2796 Dart_ExitScope(); | 2797 Dart_ExitScope(); |
| 2797 return true; | 2798 return true; |
| 2798 } | 2799 } |
| 2799 | 2800 |
| 2800 | 2801 |
| 2801 // Common code for RunLoop_Success/RunLoop_Failure. | 2802 // Common code for RunLoop_Success/RunLoop_Failure. |
| 2802 static void RunLoopTest(bool throw_exception) { | 2803 static void RunLoopTest(bool throw_exception_child, |
| 2804 bool throw_exception_parent) { |
| 2803 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); | 2805 Dart_IsolateCreateCallback saved = Isolate::CreateCallback(); |
| 2804 Isolate::SetCreateCallback(RunLoopTestCallback); | 2806 Isolate::SetCreateCallback(RunLoopTestCallback); |
| 2805 RunLoopTestCallback(NULL, NULL); | 2807 RunLoopTestCallback(NULL, NULL); |
| 2806 | 2808 |
| 2807 Dart_EnterScope(); | 2809 Dart_EnterScope(); |
| 2808 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); | 2810 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); |
| 2809 EXPECT_VALID(lib); | 2811 EXPECT_VALID(lib); |
| 2810 | 2812 |
| 2811 Dart_Handle result; | 2813 Dart_Handle result; |
| 2812 Dart_Handle args[1]; | 2814 Dart_Handle args[2]; |
| 2813 args[0] = (throw_exception ? Dart_True() : Dart_False()); | 2815 args[0] = (throw_exception_child ? Dart_True() : Dart_False()); |
| 2816 args[1] = (throw_exception_parent ? Dart_True() : Dart_False()); |
| 2814 result = Dart_InvokeStatic(lib, | 2817 result = Dart_InvokeStatic(lib, |
| 2815 Dart_NewString(""), | 2818 Dart_NewString(""), |
| 2816 Dart_NewString("main"), | 2819 Dart_NewString("main"), |
| 2817 1, | 2820 2, |
| 2818 args); | 2821 args); |
| 2819 EXPECT_VALID(result); | 2822 EXPECT_VALID(result); |
| 2820 result = Dart_RunLoop(); | 2823 result = Dart_RunLoop(); |
| 2821 EXPECT_VALID(result); | 2824 if (throw_exception_parent) { |
| 2825 EXPECT(Dart_IsError(result)); |
| 2826 // TODO(turnidge): Once EXPECT_SUBSTRING is submitted use it here. |
| 2827 } else { |
| 2828 EXPECT_VALID(result); |
| 2829 } |
| 2822 | 2830 |
| 2823 Dart_ExitScope(); | 2831 Dart_ExitScope(); |
| 2824 Dart_ShutdownIsolate(); | 2832 Dart_ShutdownIsolate(); |
| 2825 | 2833 |
| 2826 Isolate::SetCreateCallback(saved); | 2834 Isolate::SetCreateCallback(saved); |
| 2827 } | 2835 } |
| 2828 | 2836 |
| 2829 | 2837 |
| 2830 UNIT_TEST_CASE(RunLoop_Success) { | 2838 UNIT_TEST_CASE(RunLoop_Success) { |
| 2831 RunLoopTest(false); | 2839 RunLoopTest(false, false); |
| 2832 } | 2840 } |
| 2833 | 2841 |
| 2834 | 2842 |
| 2835 UNIT_TEST_CASE(RunLoop_Exception) { | 2843 // This test exits the vm. Listed as FAIL in vm.status. |
| 2836 RunLoopTest(true); | 2844 UNIT_TEST_CASE(RunLoop_ExceptionChild) { |
| 2845 RunLoopTest(true, false); |
| 2846 } |
| 2847 |
| 2848 |
| 2849 UNIT_TEST_CASE(RunLoop_ExceptionParent) { |
| 2850 RunLoopTest(false, true); |
| 2837 } | 2851 } |
| 2838 | 2852 |
| 2839 #endif // TARGET_ARCH_IA32. | 2853 #endif // TARGET_ARCH_IA32. |
| 2840 | 2854 |
| 2841 } // namespace dart | 2855 } // namespace dart |
| OLD | NEW |