| 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 5757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5768 url = NewString("lib.dart"); | 5768 url = NewString("lib.dart"); |
| 5769 source = NewString(kLibraryChars); | 5769 source = NewString(kLibraryChars); |
| 5770 Dart_LoadLibrary(url, source); | 5770 Dart_LoadLibrary(url, source); |
| 5771 | 5771 |
| 5772 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 5772 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
| 5773 EXPECT_VALID(result); | 5773 EXPECT_VALID(result); |
| 5774 } | 5774 } |
| 5775 | 5775 |
| 5776 | 5776 |
| 5777 void NewNativePort_send123(Dart_Port dest_port_id, | 5777 void NewNativePort_send123(Dart_Port dest_port_id, |
| 5778 Dart_Port reply_port_id, | |
| 5779 Dart_CObject *message) { | 5778 Dart_CObject *message) { |
| 5780 // Gets a null message. | 5779 // Gets a send port message. |
| 5781 EXPECT_NOTNULL(message); | 5780 EXPECT_NOTNULL(message); |
| 5782 EXPECT_EQ(Dart_CObject_kNull, message->type); | 5781 EXPECT_EQ(Dart_CObject_kArray, message->type); |
| 5782 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
| 5783 | 5783 |
| 5784 // Post integer value. | 5784 // Post integer value. |
| 5785 Dart_CObject* response = | 5785 Dart_CObject* response = |
| 5786 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 5786 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
| 5787 response->type = Dart_CObject_kInt32; | 5787 response->type = Dart_CObject_kInt32; |
| 5788 response->value.as_int32 = 123; | 5788 response->value.as_int32 = 123; |
| 5789 Dart_PostCObject(reply_port_id, response); | 5789 Dart_PostCObject( |
| 5790 message->value.as_array.values[0]->value.as_send_port, response); |
| 5790 } | 5791 } |
| 5791 | 5792 |
| 5792 | 5793 |
| 5793 void NewNativePort_send321(Dart_Port dest_port_id, | 5794 void NewNativePort_send321(Dart_Port dest_port_id, |
| 5794 Dart_Port reply_port_id, | |
| 5795 Dart_CObject* message) { | 5795 Dart_CObject* message) { |
| 5796 // Gets a null message. | 5796 // Gets a null message. |
| 5797 EXPECT_NOTNULL(message); | 5797 EXPECT_NOTNULL(message); |
| 5798 EXPECT_EQ(Dart_CObject_kNull, message->type); | 5798 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
| 5799 | 5799 |
| 5800 // Post integer value. | 5800 // Post integer value. |
| 5801 Dart_CObject* response = | 5801 Dart_CObject* response = |
| 5802 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 5802 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
| 5803 response->type = Dart_CObject_kInt32; | 5803 response->type = Dart_CObject_kInt32; |
| 5804 response->value.as_int32 = 321; | 5804 response->value.as_int32 = 321; |
| 5805 Dart_PostCObject(reply_port_id, response); | 5805 Dart_PostCObject( |
| 5806 message->value.as_array.values[0]->value.as_send_port, response); |
| 5806 } | 5807 } |
| 5807 | 5808 |
| 5808 | 5809 |
| 5809 UNIT_TEST_CASE(NewNativePort) { | 5810 UNIT_TEST_CASE(NewNativePort) { |
| 5810 // Create a port with a bogus handler. | 5811 // Create a port with a bogus handler. |
| 5811 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); | 5812 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); |
| 5812 EXPECT_EQ(ILLEGAL_PORT, error_port); | 5813 EXPECT_EQ(ILLEGAL_PORT, error_port); |
| 5813 | 5814 |
| 5814 // Create the port w/o a current isolate, just to make sure that works. | 5815 // Create the port w/o a current isolate, just to make sure that works. |
| 5815 Dart_Port port_id1 = | 5816 Dart_Port port_id1 = |
| 5816 Dart_NewNativePort("Port123", NewNativePort_send123, true); | 5817 Dart_NewNativePort("Port123", NewNativePort_send123, true); |
| 5817 | 5818 |
| 5818 TestIsolateScope __test_isolate__; | 5819 TestIsolateScope __test_isolate__; |
| 5819 const char* kScriptChars = | 5820 const char* kScriptChars = |
| 5820 "import 'dart:isolate';\n" | 5821 "import 'dart:isolate';\n" |
| 5821 "void callPort(SendPort port) {\n" | 5822 "void callPort(SendPort port) {\n" |
| 5822 " var receivePort = new RawReceivePort();\n" | 5823 " var receivePort = new RawReceivePort();\n" |
| 5823 " port.send(null, receivePort.sendPort);\n" | 5824 " var replyPort = receivePort.sendPort;\n" |
| 5825 " port.send([replyPort]);\n" |
| 5824 " receivePort.handler = (message) {\n" | 5826 " receivePort.handler = (message) {\n" |
| 5825 " receivePort.close();\n" | 5827 " receivePort.close();\n" |
| 5826 " throw new Exception(message);\n" | 5828 " throw new Exception(message);\n" |
| 5827 " };\n" | 5829 " };\n" |
| 5828 "}\n"; | 5830 "}\n"; |
| 5829 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5831 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 5830 Dart_EnterScope(); | 5832 Dart_EnterScope(); |
| 5831 | 5833 |
| 5832 // Create a port w/ a current isolate, to make sure that works too. | 5834 // Create a port w/ a current isolate, to make sure that works too. |
| 5833 Dart_Port port_id2 = | 5835 Dart_Port port_id2 = |
| (...skipping 1563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7397 NewString("main"), | 7399 NewString("main"), |
| 7398 0, | 7400 0, |
| 7399 NULL); | 7401 NULL); |
| 7400 int64_t value = 0; | 7402 int64_t value = 0; |
| 7401 result = Dart_IntegerToInt64(result, &value); | 7403 result = Dart_IntegerToInt64(result, &value); |
| 7402 EXPECT_VALID(result); | 7404 EXPECT_VALID(result); |
| 7403 EXPECT_EQ(8, value); | 7405 EXPECT_EQ(8, value); |
| 7404 } | 7406 } |
| 7405 | 7407 |
| 7406 } // namespace dart | 7408 } // namespace dart |
| OLD | NEW |