| 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 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2815 Dart_NewString(""), | 2815 Dart_NewString(""), |
| 2816 Dart_NewString("main"), | 2816 Dart_NewString("main"), |
| 2817 0, | 2817 0, |
| 2818 NULL); | 2818 NULL); |
| 2819 EXPECT_VALID(result); | 2819 EXPECT_VALID(result); |
| 2820 | 2820 |
| 2821 Dart_ExitScope(); // Exit the Dart API scope. | 2821 Dart_ExitScope(); // Exit the Dart API scope. |
| 2822 } | 2822 } |
| 2823 Dart_ShutdownIsolate(); | 2823 Dart_ShutdownIsolate(); |
| 2824 } | 2824 } |
| 2825 |
| 2826 |
| 2827 static void* RunLoopTest_InitCallback(void* data) { |
| 2828 const char* kScriptChars = |
| 2829 "#import('builtin');\n" |
| 2830 "class MyIsolate extends Isolate {\n" |
| 2831 " MyIsolate() : super() { }\n" |
| 2832 " void main() {\n" |
| 2833 " port.receive((message, replyTo) {\n" |
| 2834 " if (message) {\n" |
| 2835 " throw new Exception('MakeVMExit');\n" |
| 2836 " } else {\n" |
| 2837 " replyTo.call('hello');\n" |
| 2838 " port.close();\n" |
| 2839 " }\n" |
| 2840 " });\n" |
| 2841 " }\n" |
| 2842 "}\n" |
| 2843 "\n" |
| 2844 "void main(message) {\n" |
| 2845 " new MyIsolate().spawn().then((port) {\n" |
| 2846 " port.call(message).receive((message, replyTo) {\n" |
| 2847 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n" |
| 2848 " });\n" |
| 2849 " });\n" |
| 2850 "}\n"; |
| 2851 |
| 2852 Dart_EnterScope(); |
| 2853 Dart_Handle url = Dart_NewString(TestCase::url()); |
| 2854 Dart_Handle source = Dart_NewString(kScriptChars); |
| 2855 Dart_Handle lib = Dart_LoadScript(url, source, library_handler); |
| 2856 EXPECT_VALID(lib); |
| 2857 Dart_ExitScope(); |
| 2858 return NULL; |
| 2859 } |
| 2860 |
| 2861 |
| 2862 // Common code for RunLoop_Success/RunLoop_Failure. |
| 2863 static void RunLoopTest(bool throw_exception) { |
| 2864 Dart_IsolateInitCallback saved = Isolate::InitCallback(); |
| 2865 Isolate::SetInitCallback(RunLoopTest_InitCallback); |
| 2866 Dart_CreateIsolate(NULL, NULL); |
| 2867 Dart_EnterScope(); |
| 2868 |
| 2869 Dart_Handle lib = Dart_LookupLibrary(Dart_NewString(TestCase::url())); |
| 2870 EXPECT_VALID(lib); |
| 2871 Dart_Handle result; |
| 2872 Dart_Handle args[1]; |
| 2873 args[0] = (throw_exception ? Dart_True() : Dart_False()); |
| 2874 result = Dart_InvokeStatic(lib, |
| 2875 Dart_NewString(""), |
| 2876 Dart_NewString("main"), |
| 2877 1, |
| 2878 args); |
| 2879 EXPECT_VALID(result); |
| 2880 result = Dart_RunLoop(); |
| 2881 EXPECT_VALID(result); |
| 2882 |
| 2883 Dart_ExitScope(); |
| 2884 Dart_ShutdownIsolate(); |
| 2885 |
| 2886 Isolate::SetInitCallback(saved); |
| 2887 } |
| 2888 |
| 2889 |
| 2890 UNIT_TEST_CASE(RunLoop_Success) { |
| 2891 RunLoopTest(false); |
| 2892 } |
| 2893 |
| 2894 |
| 2895 UNIT_TEST_CASE(RunLoop_Exception) { |
| 2896 RunLoopTest(true); |
| 2897 } |
| 2898 |
| 2825 #endif // TARGET_ARCH_IA32. | 2899 #endif // TARGET_ARCH_IA32. |
| 2826 | 2900 |
| 2827 } // namespace dart | 2901 } // namespace dart |
| OLD | NEW |