OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/utils.h" | 7 #include "platform/utils.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/thread.h" | 10 #include "vm/thread.h" |
(...skipping 2810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2821 Dart_NewString("main"), | 2821 Dart_NewString("main"), |
2822 0, | 2822 0, |
2823 NULL); | 2823 NULL); |
2824 EXPECT_VALID(result); | 2824 EXPECT_VALID(result); |
2825 } | 2825 } |
2826 | 2826 |
2827 | 2827 |
2828 void NewNativePort_send123(Dart_Port dest_port_id, | 2828 void NewNativePort_send123(Dart_Port dest_port_id, |
2829 Dart_Port reply_port_id, | 2829 Dart_Port reply_port_id, |
2830 uint8_t* data) { | 2830 uint8_t* data) { |
2831 intptr_t response = 123; | 2831 // Post integer value. |
2832 Dart_PostIntArray(reply_port_id, 1, &response); | 2832 Dart_CObject object; |
| 2833 object.type = Dart_CObject::kInt32; |
| 2834 object.value.as_int32 = 123; |
| 2835 Dart_CMessage message; |
| 2836 message.root = &object; |
| 2837 Dart_PostCMessage(reply_port_id, &message); |
2833 } | 2838 } |
2834 | 2839 |
2835 | 2840 |
2836 void NewNativePort_send321(Dart_Port dest_port_id, | 2841 void NewNativePort_send321(Dart_Port dest_port_id, |
2837 Dart_Port reply_port_id, | 2842 Dart_Port reply_port_id, |
2838 uint8_t* data) { | 2843 uint8_t* data) { |
2839 intptr_t response = 321; | 2844 // Post integer value. |
2840 Dart_PostIntArray(reply_port_id, 1, &response); | 2845 Dart_CObject object; |
| 2846 object.type = Dart_CObject::kInt32; |
| 2847 object.value.as_int32 = 321; |
| 2848 Dart_CMessage message; |
| 2849 message.root = &object; |
| 2850 Dart_PostCMessage(reply_port_id, &message); |
2841 } | 2851 } |
2842 | 2852 |
2843 | 2853 |
2844 UNIT_TEST_CASE(NewNativePort) { | 2854 UNIT_TEST_CASE(NewNativePort) { |
2845 // Create a port with a bogus handler. | 2855 // Create a port with a bogus handler. |
2846 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); | 2856 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); |
2847 EXPECT_EQ(kIllegalPort, error_port); | 2857 EXPECT_EQ(kIllegalPort, error_port); |
2848 | 2858 |
2849 // Create the port w/o a current isolate, just to make sure that works. | 2859 // Create the port w/o a current isolate, just to make sure that works. |
2850 Dart_Port port_id1 = | 2860 Dart_Port port_id1 = |
2851 Dart_NewNativePort("Port123", NewNativePort_send123, true); | 2861 Dart_NewNativePort("Port123", NewNativePort_send123, true); |
2852 | 2862 |
2853 TestIsolateScope __test_isolate__; | 2863 TestIsolateScope __test_isolate__; |
2854 const char* kScriptChars = | 2864 const char* kScriptChars = |
2855 "void callPort(SendPort port) {\n" | 2865 "void callPort(SendPort port) {\n" |
2856 " port.call(null).receive((message, replyTo) {\n" | 2866 " port.call(null).receive((message, replyTo) {\n" |
2857 " throw new Exception(message[0]);\n" | 2867 " throw new Exception(message);\n" |
2858 " });\n" | 2868 " });\n" |
2859 "}\n"; | 2869 "}\n"; |
2860 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2870 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2861 Dart_EnterScope(); | 2871 Dart_EnterScope(); |
2862 | 2872 |
2863 // Create a port w/ a current isolate, to make sure that works too. | 2873 // Create a port w/ a current isolate, to make sure that works too. |
2864 Dart_Port port_id2 = | 2874 Dart_Port port_id2 = |
2865 Dart_NewNativePort("Port321", NewNativePort_send321, true); | 2875 Dart_NewNativePort("Port321", NewNativePort_send321, true); |
2866 | 2876 |
2867 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 2877 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 // We should have received the expected number of interrupts. | 3165 // We should have received the expected number of interrupts. |
3156 EXPECT_EQ(kInterruptCount, interrupt_count); | 3166 EXPECT_EQ(kInterruptCount, interrupt_count); |
3157 | 3167 |
3158 // Give the spawned thread enough time to properly exit. | 3168 // Give the spawned thread enough time to properly exit. |
3159 Isolate::SetInterruptCallback(saved); | 3169 Isolate::SetInterruptCallback(saved); |
3160 } | 3170 } |
3161 | 3171 |
3162 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3172 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
3163 | 3173 |
3164 } // namespace dart | 3174 } // namespace dart |
OLD | NEW |