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_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/json.h" | 10 #include "platform/json.h" |
(...skipping 5718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5729 url = NewString("lib.dart"); | 5729 url = NewString("lib.dart"); |
5730 source = NewString(kLibraryChars); | 5730 source = NewString(kLibraryChars); |
5731 Dart_LoadLibrary(url, source); | 5731 Dart_LoadLibrary(url, source); |
5732 | 5732 |
5733 result = Dart_Invoke(result, NewString("main"), 0, NULL); | 5733 result = Dart_Invoke(result, NewString("main"), 0, NULL); |
5734 EXPECT_VALID(result); | 5734 EXPECT_VALID(result); |
5735 } | 5735 } |
5736 | 5736 |
5737 | 5737 |
5738 void NewNativePort_send123(Dart_Port dest_port_id, | 5738 void NewNativePort_send123(Dart_Port dest_port_id, |
5739 Dart_Port reply_port_id, | |
5740 Dart_CObject *message) { | 5739 Dart_CObject *message) { |
5741 // Gets a null message. | 5740 // Gets a send port message. |
5742 EXPECT_NOTNULL(message); | 5741 EXPECT_NOTNULL(message); |
5743 EXPECT_EQ(Dart_CObject_kNull, message->type); | 5742 EXPECT_EQ(Dart_CObject_kArray, message->type); |
5743 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); | |
5744 | 5744 |
5745 // Post integer value. | 5745 // Post integer value. |
5746 Dart_CObject* response = | 5746 Dart_CObject* response = |
5747 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 5747 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
5748 response->type = Dart_CObject_kInt32; | 5748 response->type = Dart_CObject_kInt32; |
5749 response->value.as_int32 = 123; | 5749 response->value.as_int32 = 123; |
5750 Dart_PostCObject(reply_port_id, response); | 5750 Dart_PostCObject( |
5751 message->value.as_array.values[0]->value.as_send_port, response); | |
5751 } | 5752 } |
5752 | 5753 |
5753 | 5754 |
5754 void NewNativePort_send321(Dart_Port dest_port_id, | 5755 void NewNativePort_send321(Dart_Port dest_port_id, |
5755 Dart_Port reply_port_id, | |
5756 Dart_CObject* message) { | 5756 Dart_CObject* message) { |
5757 // Gets a null message. | 5757 // Gets a null message. |
5758 EXPECT_NOTNULL(message); | 5758 EXPECT_NOTNULL(message); |
5759 EXPECT_EQ(Dart_CObject_kNull, message->type); | 5759 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
5760 | 5760 |
5761 // Post integer value. | 5761 // Post integer value. |
5762 Dart_CObject* response = | 5762 Dart_CObject* response = |
5763 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 5763 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
5764 response->type = Dart_CObject_kInt32; | 5764 response->type = Dart_CObject_kInt32; |
5765 response->value.as_int32 = 321; | 5765 response->value.as_int32 = 321; |
5766 Dart_PostCObject(reply_port_id, response); | 5766 Dart_PostCObject( |
5767 message->value.as_array.values[0]->value.as_send_port, response); | |
5767 } | 5768 } |
5768 | 5769 |
5769 | 5770 |
5770 UNIT_TEST_CASE(NewNativePort) { | 5771 UNIT_TEST_CASE(NewNativePort) { |
5771 // Create a port with a bogus handler. | 5772 // Create a port with a bogus handler. |
5772 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); | 5773 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); |
5773 EXPECT_EQ(ILLEGAL_PORT, error_port); | 5774 EXPECT_EQ(ILLEGAL_PORT, error_port); |
5774 | 5775 |
5775 // Create the port w/o a current isolate, just to make sure that works. | 5776 // Create the port w/o a current isolate, just to make sure that works. |
5776 Dart_Port port_id1 = | 5777 Dart_Port port_id1 = |
5777 Dart_NewNativePort("Port123", NewNativePort_send123, true); | 5778 Dart_NewNativePort("Port123", NewNativePort_send123, true); |
5778 | 5779 |
5779 TestIsolateScope __test_isolate__; | 5780 TestIsolateScope __test_isolate__; |
5780 const char* kScriptChars = | 5781 const char* kScriptChars = |
5781 "import 'dart:isolate';\n" | 5782 "import 'dart:isolate';\n" |
5782 "void callPort(SendPort port) {\n" | 5783 "void callPort(SendPort port) {\n" |
5783 " var receivePort = new ReceivePort();\n" | 5784 " var receivePort = new ReceivePort();\n" |
5784 " port.send(null, receivePort.toSendPort());\n" | 5785 " var replyPort = receivePort.toSendPort();\n" |
floitsch
2013/10/25 18:04:58
This will have to be merged with the isolate API.
Søren Gjesse
2013/10/29 07:42:57
Done.
| |
5786 " port.send([replyPort]);\n" | |
5785 " receivePort.receive((message, _) {\n" | 5787 " receivePort.receive((message, _) {\n" |
5786 " receivePort.close();\n" | 5788 " receivePort.close();\n" |
5787 " throw new Exception(message);\n" | 5789 " throw new Exception(message);\n" |
5788 " });\n" | 5790 " });\n" |
5789 "}\n"; | 5791 "}\n"; |
5790 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 5792 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
5791 Dart_EnterScope(); | 5793 Dart_EnterScope(); |
5792 | 5794 |
5793 // Create a port w/ a current isolate, to make sure that works too. | 5795 // Create a port w/ a current isolate, to make sure that works too. |
5794 Dart_Port port_id2 = | 5796 Dart_Port port_id2 = |
(...skipping 1565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7360 NewString("main"), | 7362 NewString("main"), |
7361 0, | 7363 0, |
7362 NULL); | 7364 NULL); |
7363 int64_t value = 0; | 7365 int64_t value = 0; |
7364 result = Dart_IntegerToInt64(result, &value); | 7366 result = Dart_IntegerToInt64(result, &value); |
7365 EXPECT_VALID(result); | 7367 EXPECT_VALID(result); |
7366 EXPECT_EQ(8, value); | 7368 EXPECT_EQ(8, value); |
7367 } | 7369 } |
7368 | 7370 |
7369 } // namespace dart | 7371 } // namespace dart |
OLD | NEW |