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 "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_tools_api.h" | 7 #include "include/dart_tools_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/clustered_snapshot.h" | 10 #include "vm/clustered_snapshot.h" |
(...skipping 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2918 // Create a native port for posting from C to Dart | 2918 // Create a native port for posting from C to Dart |
2919 TestIsolateScope __test_isolate__; | 2919 TestIsolateScope __test_isolate__; |
2920 const char* kScriptChars = | 2920 const char* kScriptChars = |
2921 "import 'dart:isolate';\n" | 2921 "import 'dart:isolate';\n" |
2922 "main() {\n" | 2922 "main() {\n" |
2923 " var messageCount = 0;\n" | 2923 " var messageCount = 0;\n" |
2924 " var exception = '';\n" | 2924 " var exception = '';\n" |
2925 " var port = new RawReceivePort();\n" | 2925 " var port = new RawReceivePort();\n" |
2926 " var sendPort = port.sendPort;\n" | 2926 " var sendPort = port.sendPort;\n" |
2927 " port.handler = (message) {\n" | 2927 " port.handler = (message) {\n" |
2928 " if (messageCount < 8) {\n" | 2928 " if (messageCount < 9) {\n" |
2929 " exception = '$exception${message}';\n" | 2929 " exception = '$exception${message}';\n" |
2930 " } else {\n" | 2930 " } else {\n" |
2931 " exception = '$exception${message.length}';\n" | 2931 " exception = '$exception${message.length}';\n" |
2932 " for (int i = 0; i < message.length; i++) {\n" | 2932 " for (int i = 0; i < message.length; i++) {\n" |
2933 " exception = '$exception${message[i]}';\n" | 2933 " exception = '$exception${message[i]}';\n" |
2934 " }\n" | 2934 " }\n" |
2935 " }\n" | 2935 " }\n" |
2936 " messageCount++;\n" | 2936 " messageCount++;\n" |
2937 " if (messageCount == 9) throw new Exception(exception);\n" | 2937 " if (messageCount == 10) throw new Exception(exception);\n" |
2938 " };\n" | 2938 " };\n" |
2939 " return sendPort;\n" | 2939 " return sendPort;\n" |
2940 "}\n"; | 2940 "}\n"; |
2941 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 2941 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
2942 Dart_EnterScope(); | 2942 Dart_EnterScope(); |
2943 | 2943 |
2944 Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL); | 2944 Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL); |
2945 EXPECT_VALID(send_port); | 2945 EXPECT_VALID(send_port); |
2946 Dart_Port port_id; | 2946 Dart_Port port_id; |
2947 Dart_Handle result = Dart_SendPortGetId(send_port, &port_id); | 2947 Dart_Handle result = Dart_SendPortGetId(send_port, &port_id); |
(...skipping 18 matching lines...) Expand all Loading... |
2966 EXPECT(Dart_PostCObject(port_id, &object)); | 2966 EXPECT(Dart_PostCObject(port_id, &object)); |
2967 | 2967 |
2968 object.type = Dart_CObject_kString; | 2968 object.type = Dart_CObject_kString; |
2969 object.value.as_string = const_cast<char*>("456"); | 2969 object.value.as_string = const_cast<char*>("456"); |
2970 EXPECT(Dart_PostCObject(port_id, &object)); | 2970 EXPECT(Dart_PostCObject(port_id, &object)); |
2971 | 2971 |
2972 object.type = Dart_CObject_kString; | 2972 object.type = Dart_CObject_kString; |
2973 object.value.as_string = const_cast<char*>("æøå"); | 2973 object.value.as_string = const_cast<char*>("æøå"); |
2974 EXPECT(Dart_PostCObject(port_id, &object)); | 2974 EXPECT(Dart_PostCObject(port_id, &object)); |
2975 | 2975 |
| 2976 object.type = Dart_CObject_kString; |
| 2977 object.value.as_string = const_cast<char*>(""); |
| 2978 EXPECT(Dart_PostCObject(port_id, &object)); |
| 2979 |
2976 object.type = Dart_CObject_kDouble; | 2980 object.type = Dart_CObject_kDouble; |
2977 object.value.as_double = 3.14; | 2981 object.value.as_double = 3.14; |
2978 EXPECT(Dart_PostCObject(port_id, &object)); | 2982 EXPECT(Dart_PostCObject(port_id, &object)); |
2979 | 2983 |
2980 object.type = Dart_CObject_kArray; | 2984 object.type = Dart_CObject_kArray; |
2981 object.value.as_array.length = 0; | 2985 object.value.as_array.length = 0; |
2982 EXPECT(Dart_PostCObject(port_id, &object)); | 2986 EXPECT(Dart_PostCObject(port_id, &object)); |
2983 | 2987 |
2984 static const int kArrayLength = 10; | 2988 static const int kArrayLength = 10; |
2985 Dart_CObject* array = | 2989 Dart_CObject* array = |
(...skipping 28 matching lines...) Expand all Loading... |
3014 StackZone zone(Thread::Current()); | 3018 StackZone zone(Thread::Current()); |
3015 uint8_t* buffer; | 3019 uint8_t* buffer; |
3016 MessageWriter writer(&buffer, &zone_allocator, true); | 3020 MessageWriter writer(&buffer, &zone_allocator, true); |
3017 writer.WriteInlinedObjectHeader(kOmittedObjectId); | 3021 writer.WriteInlinedObjectHeader(kOmittedObjectId); |
3018 // For performance, we'd like single-byte headers when ids are omitted. | 3022 // For performance, we'd like single-byte headers when ids are omitted. |
3019 // If this starts failing, consider renumbering the snapshot ids. | 3023 // If this starts failing, consider renumbering the snapshot ids. |
3020 EXPECT_EQ(1, writer.BytesWritten()); | 3024 EXPECT_EQ(1, writer.BytesWritten()); |
3021 } | 3025 } |
3022 | 3026 |
3023 } // namespace dart | 3027 } // namespace dart |
OLD | NEW |