Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 27215002: Very simple version of Isolates. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 3654 matching lines...) Expand 10 before | Expand all | Expand 10 after
3665 EXPECT(Dart_IsError(result)); 3665 EXPECT(Dart_IsError(result));
3666 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400); 3666 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
3667 EXPECT(Dart_IsError(result)); 3667 EXPECT(Dart_IsError(result));
3668 } 3668 }
3669 3669
3670 3670
3671 TEST_CASE(NegativeNativeFieldInIsolateMessage) { 3671 TEST_CASE(NegativeNativeFieldInIsolateMessage) {
3672 const char* kScriptChars = 3672 const char* kScriptChars =
3673 "import 'dart:isolate';\n" 3673 "import 'dart:isolate';\n"
3674 "import 'dart:nativewrappers';\n" 3674 "import 'dart:nativewrappers';\n"
3675 "echo() {\n" 3675 "echo(msg) {\n"
3676 " port.receive((msg, reply) {\n" 3676 " var data = msg[0];\n"
3677 " reply.send('echoing ${msg(1)}}');\n" 3677 " var reply = msg[1];\n"
3678 " });\n" 3678 " reply.send('echoing ${data(1)}}');\n"
3679 "}\n" 3679 "}\n"
3680 "class Test extends NativeFieldWrapperClass2 {\n" 3680 "class Test extends NativeFieldWrapperClass2 {\n"
3681 " Test(this.i, this.j);\n" 3681 " Test(this.i, this.j);\n"
3682 " int i, j;\n" 3682 " int i, j;\n"
3683 "}\n" 3683 "}\n"
3684 "main() {\n" 3684 "main() {\n"
3685 " var snd = spawnFunction(echo);\n" 3685 " var port = new RawReceivePort();\n"
3686 " var obj = new Test(1,2);\n" 3686 " var obj = new Test(1,2);\n"
3687 " snd.send(obj, port.toSendPort());\n" 3687 " var msg = [obj, port.sendPort];\n"
3688 " port.receive((msg, reply) {\n" 3688 " var snd = Isolate.spawn(echo, msg);\n"
3689 " port.handler = (msg) {\n"
3690 " port.close();\n"
3689 " print('from worker ${msg}');\n" 3691 " print('from worker ${msg}');\n"
3690 " });\n" 3692 " };\n"
3691 "}\n"; 3693 "}\n";
3692 3694
3693 DARTSCOPE(Isolate::Current()); 3695 DARTSCOPE(Isolate::Current());
3694 3696
3695 // Create a test library and Load up a test script in it. 3697 // Create a test library and Load up a test script in it.
3696 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3698 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3697 3699
3698 // Invoke 'main' which should spawn an isolate and try to send an 3700 // Invoke 'main' which should spawn an isolate and try to send an
3699 // object with native fields over to the spawned isolate. This 3701 // object with native fields over to the spawned isolate. This
3700 // should result in an unhandled exception which is checked. 3702 // should result in an unhandled exception which is checked.
(...skipping 2072 matching lines...) Expand 10 before | Expand all | Expand 10 after
5773 EXPECT_EQ(ILLEGAL_PORT, error_port); 5775 EXPECT_EQ(ILLEGAL_PORT, error_port);
5774 5776
5775 // Create the port w/o a current isolate, just to make sure that works. 5777 // Create the port w/o a current isolate, just to make sure that works.
5776 Dart_Port port_id1 = 5778 Dart_Port port_id1 =
5777 Dart_NewNativePort("Port123", NewNativePort_send123, true); 5779 Dart_NewNativePort("Port123", NewNativePort_send123, true);
5778 5780
5779 TestIsolateScope __test_isolate__; 5781 TestIsolateScope __test_isolate__;
5780 const char* kScriptChars = 5782 const char* kScriptChars =
5781 "import 'dart:isolate';\n" 5783 "import 'dart:isolate';\n"
5782 "void callPort(SendPort port) {\n" 5784 "void callPort(SendPort port) {\n"
5783 " var receivePort = new ReceivePort();\n" 5785 " var receivePort = new RawReceivePort();\n"
5784 " port.send(null, receivePort.toSendPort());\n" 5786 " port.send(null, receivePort.sendPort);\n"
5785 " receivePort.receive((message, _) {\n" 5787 " receivePort.handler = (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 =
5795 Dart_NewNativePort("Port321", NewNativePort_send321, true); 5797 Dart_NewNativePort("Port321", NewNativePort_send321, true);
5796 5798
5797 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); 5799 Dart_Handle send_port1 = Dart_NewSendPort(port_id1);
5798 EXPECT_VALID(send_port1); 5800 EXPECT_VALID(send_port1);
(...skipping 28 matching lines...) Expand all
5827 } 5829 }
5828 5830
5829 5831
5830 static Dart_Isolate RunLoopTestCallback(const char* script_name, 5832 static Dart_Isolate RunLoopTestCallback(const char* script_name,
5831 const char* main, 5833 const char* main,
5832 void* data, 5834 void* data,
5833 char** error) { 5835 char** error) {
5834 const char* kScriptChars = 5836 const char* kScriptChars =
5835 "import 'builtin';\n" 5837 "import 'builtin';\n"
5836 "import 'dart:isolate';\n" 5838 "import 'dart:isolate';\n"
5837 "void entry() {\n" 5839 "void entry(message) {\n"
5838 " port.receive((message, replyTo) {\n" 5840 " var data = message[0];\n"
5839 " if (message) {\n" 5841 " var replyTo = message[1];\n"
5840 " throw new Exception('MakeChildExit');\n" 5842 " if (data) {\n"
5841 " } else {\n" 5843 " throw new Exception('MakeChildExit');\n"
5842 " replyTo.call('hello');\n" 5844 " } else {\n"
5843 " port.close();\n" 5845 " replyTo.send('hello');\n"
5844 " }\n" 5846 " }\n"
5845 " });\n"
5846 "}\n" 5847 "}\n"
5847 "\n" 5848 "\n"
5848 "void main(exc_child, exc_parent) {\n" 5849 "void main(exc_child, exc_parent) {\n"
5849 " var port = spawnFunction(entry);\n" 5850 " var receivePort = new RawReceivePort();\n"
5850 " var receivePort = new ReceivePort();\n" 5851 " Isolate.spawn(entry, [exc_child, receivePort.sendPort]);\n"
5851 " port.send(exc_child, receivePort.toSendPort());\n" 5852 " receivePort.handler = (message) {\n"
5852 " receivePort.receive((message, _) {\n"
5853 " receivePort.close();\n" 5853 " receivePort.close();\n"
5854 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n" 5854 " if (message != 'hello') throw new Exception('ShouldNotHappen');\n"
5855 " if (exc_parent) throw new Exception('MakeParentExit');\n" 5855 " if (exc_parent) throw new Exception('MakeParentExit');\n"
5856 " });\n" 5856 " };\n"
5857 "}\n"; 5857 "}\n";
5858 5858
5859 if (Dart_CurrentIsolate() != NULL) { 5859 if (Dart_CurrentIsolate() != NULL) {
5860 Dart_ExitIsolate(); 5860 Dart_ExitIsolate();
5861 } 5861 }
5862 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 5862 Dart_Isolate isolate = TestCase::CreateTestIsolate();
5863 ASSERT(isolate != NULL); 5863 ASSERT(isolate != NULL);
5864 Dart_EnterScope(); 5864 Dart_EnterScope();
5865 Dart_Handle url = NewString(TestCase::url()); 5865 Dart_Handle url = NewString(TestCase::url());
5866 Dart_Handle source = NewString(kScriptChars); 5866 Dart_Handle source = NewString(kScriptChars);
(...skipping 1493 matching lines...) Expand 10 before | Expand all | Expand 10 after
7360 NewString("main"), 7360 NewString("main"),
7361 0, 7361 0,
7362 NULL); 7362 NULL);
7363 int64_t value = 0; 7363 int64_t value = 0;
7364 result = Dart_IntegerToInt64(result, &value); 7364 result = Dart_IntegerToInt64(result, &value);
7365 EXPECT_VALID(result); 7365 EXPECT_VALID(result);
7366 EXPECT_EQ(8, value); 7366 EXPECT_EQ(8, value);
7367 } 7367 }
7368 7368
7369 } // namespace dart 7369 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/dart_entry.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698