| 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_PostCObject(reply_port_id, &object); |
| 2833 } | 2836 } |
| 2834 | 2837 |
| 2835 | 2838 |
| 2836 void NewNativePort_send321(Dart_Port dest_port_id, | 2839 void NewNativePort_send321(Dart_Port dest_port_id, |
| 2837 Dart_Port reply_port_id, | 2840 Dart_Port reply_port_id, |
| 2838 uint8_t* data) { | 2841 uint8_t* data) { |
| 2839 intptr_t response = 321; | 2842 // Post integer value. |
| 2840 Dart_PostIntArray(reply_port_id, 1, &response); | 2843 Dart_CObject object; |
| 2844 object.type = Dart_CObject::kInt32; |
| 2845 object.value.as_int32 = 321; |
| 2846 Dart_PostCObject(reply_port_id, &object); |
| 2841 } | 2847 } |
| 2842 | 2848 |
| 2843 | 2849 |
| 2844 UNIT_TEST_CASE(NewNativePort) { | 2850 UNIT_TEST_CASE(NewNativePort) { |
| 2845 // Create a port with a bogus handler. | 2851 // Create a port with a bogus handler. |
| 2846 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); | 2852 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); |
| 2847 EXPECT_EQ(kIllegalPort, error_port); | 2853 EXPECT_EQ(kIllegalPort, error_port); |
| 2848 | 2854 |
| 2849 // Create the port w/o a current isolate, just to make sure that works. | 2855 // Create the port w/o a current isolate, just to make sure that works. |
| 2850 Dart_Port port_id1 = | 2856 Dart_Port port_id1 = |
| 2851 Dart_NewNativePort("Port123", NewNativePort_send123, true); | 2857 Dart_NewNativePort("Port123", NewNativePort_send123, true); |
| 2852 | 2858 |
| 2853 TestIsolateScope __test_isolate__; | 2859 TestIsolateScope __test_isolate__; |
| 2854 const char* kScriptChars = | 2860 const char* kScriptChars = |
| 2855 "void callPort(SendPort port) {\n" | 2861 "void callPort(SendPort port) {\n" |
| 2856 " port.call(null).receive((message, replyTo) {\n" | 2862 " port.call(null).receive((message, replyTo) {\n" |
| 2857 " throw new Exception(message[0]);\n" | 2863 " throw new Exception(message);\n" |
| 2858 " });\n" | 2864 " });\n" |
| 2859 "}\n"; | 2865 "}\n"; |
| 2860 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2866 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 2861 Dart_EnterScope(); | 2867 Dart_EnterScope(); |
| 2862 | 2868 |
| 2863 // Create a port w/ a current isolate, to make sure that works too. | 2869 // Create a port w/ a current isolate, to make sure that works too. |
| 2864 Dart_Port port_id2 = | 2870 Dart_Port port_id2 = |
| 2865 Dart_NewNativePort("Port321", NewNativePort_send321, true); | 2871 Dart_NewNativePort("Port321", NewNativePort_send321, true); |
| 2866 | 2872 |
| 2867 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); | 2873 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. | 3161 // We should have received the expected number of interrupts. |
| 3156 EXPECT_EQ(kInterruptCount, interrupt_count); | 3162 EXPECT_EQ(kInterruptCount, interrupt_count); |
| 3157 | 3163 |
| 3158 // Give the spawned thread enough time to properly exit. | 3164 // Give the spawned thread enough time to properly exit. |
| 3159 Isolate::SetInterruptCallback(saved); | 3165 Isolate::SetInterruptCallback(saved); |
| 3160 } | 3166 } |
| 3161 | 3167 |
| 3162 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 3168 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 3163 | 3169 |
| 3164 } // namespace dart | 3170 } // namespace dart |
| OLD | NEW |