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_debugger_api.h" | 5 #include "include/dart_debugger_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/dart_api_impl.h" | 9 #include "vm/dart_api_impl.h" |
10 #include "vm/dart_api_message.h" | 10 #include "vm/dart_api_message.h" |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 Timer timer2(true, "Snapshot_test"); | 938 Timer timer2(true, "Snapshot_test"); |
939 timer2.Start(); | 939 timer2.Start(); |
940 TestCase::CreateTestIsolateFromSnapshot(buffer); | 940 TestCase::CreateTestIsolateFromSnapshot(buffer); |
941 { | 941 { |
942 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 942 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
943 timer2.Stop(); | 943 timer2.Stop(); |
944 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); | 944 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); |
945 | 945 |
946 // Invoke a function which returns an object. | 946 // Invoke a function which returns an object. |
947 Dart_Handle cls = | 947 Dart_Handle cls = |
948 Dart_GetClass(TestCase::lib(), Dart_NewString("FieldsTest")); | 948 Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); |
949 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 949 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
950 EXPECT_VALID(result); | 950 EXPECT_VALID(result); |
951 Dart_ExitScope(); | 951 Dart_ExitScope(); |
952 } | 952 } |
953 Dart_ShutdownIsolate(); | 953 Dart_ShutdownIsolate(); |
954 free(buffer); | 954 free(buffer); |
955 } | 955 } |
956 | 956 |
957 | 957 |
958 UNIT_TEST_CASE(FullSnapshot1) { | 958 UNIT_TEST_CASE(FullSnapshot1) { |
959 // This buffer has to be static for this to compile with Visual Studio. | 959 // This buffer has to be static for this to compile with Visual Studio. |
(...skipping 20 matching lines...) Expand all Loading... |
980 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 980 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
981 ClassFinalizer::FinalizePendingClasses(); | 981 ClassFinalizer::FinalizePendingClasses(); |
982 timer1.Stop(); | 982 timer1.Stop(); |
983 OS::PrintErr("Without Snapshot: %"Pd64"us\n", timer1.TotalElapsedTime()); | 983 OS::PrintErr("Without Snapshot: %"Pd64"us\n", timer1.TotalElapsedTime()); |
984 | 984 |
985 // Write snapshot with object content. | 985 // Write snapshot with object content. |
986 FullSnapshotWriter writer(&buffer, &malloc_allocator); | 986 FullSnapshotWriter writer(&buffer, &malloc_allocator); |
987 writer.WriteFullSnapshot(); | 987 writer.WriteFullSnapshot(); |
988 | 988 |
989 // Invoke a function which returns an object. | 989 // Invoke a function which returns an object. |
990 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("FieldsTest")); | 990 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); |
991 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 991 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
992 EXPECT_VALID(result); | 992 EXPECT_VALID(result); |
993 } | 993 } |
994 | 994 |
995 // Now Create another isolate using the snapshot and execute a method | 995 // Now Create another isolate using the snapshot and execute a method |
996 // from the script. | 996 // from the script. |
997 Timer timer2(true, "Snapshot_test"); | 997 Timer timer2(true, "Snapshot_test"); |
998 timer2.Start(); | 998 timer2.Start(); |
999 TestCase::CreateTestIsolateFromSnapshot(buffer); | 999 TestCase::CreateTestIsolateFromSnapshot(buffer); |
1000 { | 1000 { |
1001 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1001 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1002 timer2.Stop(); | 1002 timer2.Stop(); |
1003 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); | 1003 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); |
1004 | 1004 |
1005 // Invoke a function which returns an object. | 1005 // Invoke a function which returns an object. |
1006 Dart_Handle cls = Dart_GetClass(TestCase::lib(), | 1006 Dart_Handle cls = Dart_GetClass(TestCase::lib(), |
1007 Dart_NewString("FieldsTest")); | 1007 NewString("FieldsTest")); |
1008 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 1008 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1009 if (Dart_IsError(result)) { | 1009 if (Dart_IsError(result)) { |
1010 // Print the error. It is probably an unhandled exception. | 1010 // Print the error. It is probably an unhandled exception. |
1011 fprintf(stderr, "%s\n", Dart_GetError(result)); | 1011 fprintf(stderr, "%s\n", Dart_GetError(result)); |
1012 } | 1012 } |
1013 EXPECT_VALID(result); | 1013 EXPECT_VALID(result); |
1014 Dart_ExitScope(); | 1014 Dart_ExitScope(); |
1015 } | 1015 } |
1016 Dart_ShutdownIsolate(); | 1016 Dart_ShutdownIsolate(); |
1017 free(buffer); | 1017 free(buffer); |
1018 } | 1018 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 Dart_ExitScope(); | 1078 Dart_ExitScope(); |
1079 } | 1079 } |
1080 | 1080 |
1081 { | 1081 { |
1082 // Create an Isolate using the full snapshot, load a script and create | 1082 // Create an Isolate using the full snapshot, load a script and create |
1083 // a script snapshot of the script. | 1083 // a script snapshot of the script. |
1084 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); | 1084 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
1085 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1085 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1086 | 1086 |
1087 // Load the library. | 1087 // Load the library. |
1088 Dart_Handle import_lib = Dart_LoadLibrary(Dart_NewString("dart:import-lib"), | 1088 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart:import-lib"), |
1089 Dart_NewString(kLibScriptChars)); | 1089 NewString(kLibScriptChars)); |
1090 EXPECT_VALID(import_lib); | 1090 EXPECT_VALID(import_lib); |
1091 | 1091 |
1092 // Create a test library and Load up a test script in it. | 1092 // Create a test library and Load up a test script in it. |
1093 TestCase::LoadTestScript(kScriptChars, NULL); | 1093 TestCase::LoadTestScript(kScriptChars, NULL); |
1094 | 1094 |
1095 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), | 1095 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), |
1096 import_lib, | 1096 import_lib, |
1097 Dart_Null())); | 1097 Dart_Null())); |
1098 | 1098 |
1099 // Get list of library URLs loaded and save the count. | 1099 // Get list of library URLs loaded and save the count. |
(...skipping 22 matching lines...) Expand all Loading... |
1122 EXPECT_VALID(result); | 1122 EXPECT_VALID(result); |
1123 | 1123 |
1124 // Get list of library URLs loaded and compare with expected count. | 1124 // Get list of library URLs loaded and compare with expected count. |
1125 Dart_Handle libs = Dart_GetLibraryURLs(); | 1125 Dart_Handle libs = Dart_GetLibraryURLs(); |
1126 EXPECT(Dart_IsList(libs)); | 1126 EXPECT(Dart_IsList(libs)); |
1127 Dart_ListLength(libs, &actual_num_libs); | 1127 Dart_ListLength(libs, &actual_num_libs); |
1128 | 1128 |
1129 EXPECT_EQ(expected_num_libs, actual_num_libs); | 1129 EXPECT_EQ(expected_num_libs, actual_num_libs); |
1130 | 1130 |
1131 // Invoke a function which returns an object. | 1131 // Invoke a function which returns an object. |
1132 Dart_Handle cls = Dart_GetClass(result, Dart_NewString("FieldsTest")); | 1132 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); |
1133 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 1133 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1134 EXPECT_VALID(result); | 1134 EXPECT_VALID(result); |
1135 Dart_ExitScope(); | 1135 Dart_ExitScope(); |
1136 } | 1136 } |
1137 Dart_ShutdownIsolate(); | 1137 Dart_ShutdownIsolate(); |
1138 free(full_snapshot); | 1138 free(full_snapshot); |
1139 free(script_snapshot); | 1139 free(script_snapshot); |
1140 } | 1140 } |
1141 | 1141 |
1142 | 1142 |
1143 TEST_CASE(IntArrayMessage) { | 1143 TEST_CASE(IntArrayMessage) { |
(...skipping 19 matching lines...) Expand all Loading... |
1163 } | 1163 } |
1164 CheckEncodeDecodeMessage(root); | 1164 CheckEncodeDecodeMessage(root); |
1165 } | 1165 } |
1166 | 1166 |
1167 | 1167 |
1168 // Helper function to call a top level Dart function, serialize the | 1168 // Helper function to call a top level Dart function, serialize the |
1169 // result and deserialize the result into a Dart_CObject structure. | 1169 // result and deserialize the result into a Dart_CObject structure. |
1170 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, | 1170 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, |
1171 const char* dart_function) { | 1171 const char* dart_function) { |
1172 Dart_Handle result; | 1172 Dart_Handle result; |
1173 result = Dart_Invoke(lib, Dart_NewString(dart_function), 0, NULL); | 1173 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); |
1174 EXPECT_VALID(result); | 1174 EXPECT_VALID(result); |
1175 | 1175 |
1176 // Serialize the list into a message. | 1176 // Serialize the list into a message. |
1177 uint8_t* buffer; | 1177 uint8_t* buffer; |
1178 MessageWriter writer(&buffer, &zone_allocator); | 1178 MessageWriter writer(&buffer, &zone_allocator); |
1179 const Object& list = Object::Handle(Api::UnwrapHandle(result)); | 1179 const Object& list = Object::Handle(Api::UnwrapHandle(result)); |
1180 writer.WriteMessage(list); | 1180 writer.WriteMessage(list); |
1181 intptr_t buffer_len = writer.BytesWritten(); | 1181 intptr_t buffer_len = writer.BytesWritten(); |
1182 | 1182 |
1183 // Read object back from the snapshot into a C structure. | 1183 // Read object back from the snapshot into a C structure. |
(...skipping 19 matching lines...) Expand all Loading... |
1203 | 1203 |
1204 TestCase::CreateTestIsolate(); | 1204 TestCase::CreateTestIsolate(); |
1205 Isolate* isolate = Isolate::Current(); | 1205 Isolate* isolate = Isolate::Current(); |
1206 EXPECT(isolate != NULL); | 1206 EXPECT(isolate != NULL); |
1207 Dart_EnterScope(); | 1207 Dart_EnterScope(); |
1208 | 1208 |
1209 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, | 1209 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, |
1210 NULL); | 1210 NULL); |
1211 EXPECT_VALID(lib); | 1211 EXPECT_VALID(lib); |
1212 Dart_Handle smi_result; | 1212 Dart_Handle smi_result; |
1213 smi_result = Dart_Invoke(lib, Dart_NewString("getSmi"), 0, NULL); | 1213 smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL); |
1214 EXPECT_VALID(smi_result); | 1214 EXPECT_VALID(smi_result); |
1215 Dart_Handle bigint_result; | 1215 Dart_Handle bigint_result; |
1216 bigint_result = Dart_Invoke(lib, Dart_NewString("getBigint"), 0, NULL); | 1216 bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL); |
1217 EXPECT_VALID(bigint_result); | 1217 EXPECT_VALID(bigint_result); |
1218 Dart_Handle string_result; | 1218 Dart_Handle string_result; |
1219 string_result = Dart_Invoke(lib, Dart_NewString("getString"), 0, NULL); | 1219 string_result = Dart_Invoke(lib, NewString("getString"), 0, NULL); |
1220 EXPECT_VALID(string_result); | 1220 EXPECT_VALID(string_result); |
1221 EXPECT(Dart_IsString(string_result)); | 1221 EXPECT(Dart_IsString(string_result)); |
1222 | 1222 |
1223 { | 1223 { |
1224 DARTSCOPE_NOCHECKS(isolate); | 1224 DARTSCOPE_NOCHECKS(isolate); |
1225 | 1225 |
1226 { | 1226 { |
1227 StackZone zone(Isolate::Current()); | 1227 StackZone zone(Isolate::Current()); |
1228 uint8_t* buffer; | 1228 uint8_t* buffer; |
1229 MessageWriter writer(&buffer, &zone_allocator); | 1229 MessageWriter writer(&buffer, &zone_allocator); |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1967 " }\n" | 1967 " }\n" |
1968 " messageCount++;\n" | 1968 " messageCount++;\n" |
1969 " if (messageCount == 8) throw new Exception(exception);\n" | 1969 " if (messageCount == 8) throw new Exception(exception);\n" |
1970 " });\n" | 1970 " });\n" |
1971 " return port.toSendPort();\n" | 1971 " return port.toSendPort();\n" |
1972 "}\n"; | 1972 "}\n"; |
1973 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1973 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1974 Dart_EnterScope(); | 1974 Dart_EnterScope(); |
1975 | 1975 |
1976 // xxx | 1976 // xxx |
1977 Dart_Handle send_port = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); | 1977 Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1978 EXPECT_VALID(send_port); | 1978 EXPECT_VALID(send_port); |
1979 Dart_Handle result = Dart_GetField(send_port, Dart_NewString("_id")); | 1979 Dart_Handle result = Dart_GetField(send_port, NewString("_id")); |
1980 ASSERT(!Dart_IsError(result)); | 1980 ASSERT(!Dart_IsError(result)); |
1981 ASSERT(Dart_IsInteger(result)); | 1981 ASSERT(Dart_IsInteger(result)); |
1982 int64_t send_port_id; | 1982 int64_t send_port_id; |
1983 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); | 1983 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); |
1984 ASSERT(!Dart_IsError(result2)); | 1984 ASSERT(!Dart_IsError(result2)); |
1985 | 1985 |
1986 // Setup single object message. | 1986 // Setup single object message. |
1987 Dart_CObject object; | 1987 Dart_CObject object; |
1988 | 1988 |
1989 object.type = Dart_CObject::kNull; | 1989 object.type = Dart_CObject::kNull; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 EXPECT(Dart_ErrorHasException(result)); | 2037 EXPECT(Dart_ErrorHasException(result)); |
2038 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 2038 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
2039 Dart_GetError(result)); | 2039 Dart_GetError(result)); |
2040 | 2040 |
2041 Dart_ExitScope(); | 2041 Dart_ExitScope(); |
2042 } | 2042 } |
2043 | 2043 |
2044 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 2044 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
2045 | 2045 |
2046 } // namespace dart | 2046 } // namespace dart |
OLD | NEW |