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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
867 Timer timer2(true, "Snapshot_test"); | 867 Timer timer2(true, "Snapshot_test"); |
868 timer2.Start(); | 868 timer2.Start(); |
869 TestCase::CreateTestIsolateFromSnapshot(buffer); | 869 TestCase::CreateTestIsolateFromSnapshot(buffer); |
870 { | 870 { |
871 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 871 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
872 timer2.Stop(); | 872 timer2.Stop(); |
873 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); | 873 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); |
874 | 874 |
875 // Invoke a function which returns an object. | 875 // Invoke a function which returns an object. |
876 Dart_Handle cls = | 876 Dart_Handle cls = |
877 Dart_GetClass(TestCase::lib(), Dart_NewString("FieldsTest")); | 877 Dart_GetClass(TestCase::lib(), NewString("FieldsTest")); |
878 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 878 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
879 EXPECT_VALID(result); | 879 EXPECT_VALID(result); |
880 Dart_ExitScope(); | 880 Dart_ExitScope(); |
881 } | 881 } |
882 Dart_ShutdownIsolate(); | 882 Dart_ShutdownIsolate(); |
883 free(buffer); | 883 free(buffer); |
884 } | 884 } |
885 | 885 |
886 | 886 |
887 UNIT_TEST_CASE(FullSnapshot1) { | 887 UNIT_TEST_CASE(FullSnapshot1) { |
888 // This buffer has to be static for this to compile with Visual Studio. | 888 // This buffer has to be static for this to compile with Visual Studio. |
(...skipping 20 matching lines...) Expand all Loading... |
909 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 909 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
910 ClassFinalizer::FinalizePendingClasses(); | 910 ClassFinalizer::FinalizePendingClasses(); |
911 timer1.Stop(); | 911 timer1.Stop(); |
912 OS::PrintErr("Without Snapshot: %"Pd64"us\n", timer1.TotalElapsedTime()); | 912 OS::PrintErr("Without Snapshot: %"Pd64"us\n", timer1.TotalElapsedTime()); |
913 | 913 |
914 // Write snapshot with object content. | 914 // Write snapshot with object content. |
915 FullSnapshotWriter writer(&buffer, &malloc_allocator); | 915 FullSnapshotWriter writer(&buffer, &malloc_allocator); |
916 writer.WriteFullSnapshot(); | 916 writer.WriteFullSnapshot(); |
917 | 917 |
918 // Invoke a function which returns an object. | 918 // Invoke a function which returns an object. |
919 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("FieldsTest")); | 919 Dart_Handle cls = Dart_GetClass(lib, NewString("FieldsTest")); |
920 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 920 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
921 EXPECT_VALID(result); | 921 EXPECT_VALID(result); |
922 } | 922 } |
923 | 923 |
924 // Now Create another isolate using the snapshot and execute a method | 924 // Now Create another isolate using the snapshot and execute a method |
925 // from the script. | 925 // from the script. |
926 Timer timer2(true, "Snapshot_test"); | 926 Timer timer2(true, "Snapshot_test"); |
927 timer2.Start(); | 927 timer2.Start(); |
928 TestCase::CreateTestIsolateFromSnapshot(buffer); | 928 TestCase::CreateTestIsolateFromSnapshot(buffer); |
929 { | 929 { |
930 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 930 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
931 timer2.Stop(); | 931 timer2.Stop(); |
932 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); | 932 OS::PrintErr("From Snapshot: %"Pd64"us\n", timer2.TotalElapsedTime()); |
933 | 933 |
934 // Invoke a function which returns an object. | 934 // Invoke a function which returns an object. |
935 Dart_Handle cls = Dart_GetClass(TestCase::lib(), | 935 Dart_Handle cls = Dart_GetClass(TestCase::lib(), |
936 Dart_NewString("FieldsTest")); | 936 NewString("FieldsTest")); |
937 Dart_Handle result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 937 Dart_Handle result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
938 if (Dart_IsError(result)) { | 938 if (Dart_IsError(result)) { |
939 // Print the error. It is probably an unhandled exception. | 939 // Print the error. It is probably an unhandled exception. |
940 fprintf(stderr, "%s\n", Dart_GetError(result)); | 940 fprintf(stderr, "%s\n", Dart_GetError(result)); |
941 } | 941 } |
942 EXPECT_VALID(result); | 942 EXPECT_VALID(result); |
943 Dart_ExitScope(); | 943 Dart_ExitScope(); |
944 } | 944 } |
945 Dart_ShutdownIsolate(); | 945 Dart_ShutdownIsolate(); |
946 free(buffer); | 946 free(buffer); |
947 } | 947 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1007 Dart_ExitScope(); | 1007 Dart_ExitScope(); |
1008 } | 1008 } |
1009 | 1009 |
1010 { | 1010 { |
1011 // Create an Isolate using the full snapshot, load a script and create | 1011 // Create an Isolate using the full snapshot, load a script and create |
1012 // a script snapshot of the script. | 1012 // a script snapshot of the script. |
1013 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); | 1013 TestCase::CreateTestIsolateFromSnapshot(full_snapshot); |
1014 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. | 1014 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. |
1015 | 1015 |
1016 // Load the library. | 1016 // Load the library. |
1017 Dart_Handle import_lib = Dart_LoadLibrary(Dart_NewString("dart:import-lib"), | 1017 Dart_Handle import_lib = Dart_LoadLibrary(NewString("dart:import-lib"), |
1018 Dart_NewString(kLibScriptChars)); | 1018 NewString(kLibScriptChars)); |
1019 EXPECT_VALID(import_lib); | 1019 EXPECT_VALID(import_lib); |
1020 | 1020 |
1021 // Create a test library and Load up a test script in it. | 1021 // Create a test library and Load up a test script in it. |
1022 TestCase::LoadTestScript(kScriptChars, NULL); | 1022 TestCase::LoadTestScript(kScriptChars, NULL); |
1023 | 1023 |
1024 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), | 1024 EXPECT_VALID(Dart_LibraryImportLibrary(TestCase::lib(), |
1025 import_lib, | 1025 import_lib, |
1026 Dart_Null())); | 1026 Dart_Null())); |
1027 | 1027 |
1028 // Get list of library URLs loaded and save the count. | 1028 // Get list of library URLs loaded and save the count. |
(...skipping 22 matching lines...) Expand all Loading... |
1051 EXPECT_VALID(result); | 1051 EXPECT_VALID(result); |
1052 | 1052 |
1053 // Get list of library URLs loaded and compare with expected count. | 1053 // Get list of library URLs loaded and compare with expected count. |
1054 Dart_Handle libs = Dart_GetLibraryURLs(); | 1054 Dart_Handle libs = Dart_GetLibraryURLs(); |
1055 EXPECT(Dart_IsList(libs)); | 1055 EXPECT(Dart_IsList(libs)); |
1056 Dart_ListLength(libs, &actual_num_libs); | 1056 Dart_ListLength(libs, &actual_num_libs); |
1057 | 1057 |
1058 EXPECT_EQ(expected_num_libs, actual_num_libs); | 1058 EXPECT_EQ(expected_num_libs, actual_num_libs); |
1059 | 1059 |
1060 // Invoke a function which returns an object. | 1060 // Invoke a function which returns an object. |
1061 Dart_Handle cls = Dart_GetClass(result, Dart_NewString("FieldsTest")); | 1061 Dart_Handle cls = Dart_GetClass(result, NewString("FieldsTest")); |
1062 result = Dart_Invoke(cls, Dart_NewString("testMain"), 0, NULL); | 1062 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); |
1063 EXPECT_VALID(result); | 1063 EXPECT_VALID(result); |
1064 Dart_ExitScope(); | 1064 Dart_ExitScope(); |
1065 } | 1065 } |
1066 Dart_ShutdownIsolate(); | 1066 Dart_ShutdownIsolate(); |
1067 free(full_snapshot); | 1067 free(full_snapshot); |
1068 free(script_snapshot); | 1068 free(script_snapshot); |
1069 } | 1069 } |
1070 | 1070 |
1071 | 1071 |
1072 TEST_CASE(IntArrayMessage) { | 1072 TEST_CASE(IntArrayMessage) { |
(...skipping 19 matching lines...) Expand all Loading... |
1092 } | 1092 } |
1093 CheckEncodeDecodeMessage(root); | 1093 CheckEncodeDecodeMessage(root); |
1094 } | 1094 } |
1095 | 1095 |
1096 | 1096 |
1097 // Helper function to call a top level Dart function, serialize the | 1097 // Helper function to call a top level Dart function, serialize the |
1098 // result and deserialize the result into a Dart_CObject structure. | 1098 // result and deserialize the result into a Dart_CObject structure. |
1099 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, | 1099 static Dart_CObject* GetDeserializedDartMessage(Dart_Handle lib, |
1100 const char* dart_function) { | 1100 const char* dart_function) { |
1101 Dart_Handle result; | 1101 Dart_Handle result; |
1102 result = Dart_Invoke(lib, Dart_NewString(dart_function), 0, NULL); | 1102 result = Dart_Invoke(lib, NewString(dart_function), 0, NULL); |
1103 EXPECT_VALID(result); | 1103 EXPECT_VALID(result); |
1104 | 1104 |
1105 // Serialize the list into a message. | 1105 // Serialize the list into a message. |
1106 uint8_t* buffer; | 1106 uint8_t* buffer; |
1107 MessageWriter writer(&buffer, &zone_allocator); | 1107 MessageWriter writer(&buffer, &zone_allocator); |
1108 const Object& list = Object::Handle(Api::UnwrapHandle(result)); | 1108 const Object& list = Object::Handle(Api::UnwrapHandle(result)); |
1109 writer.WriteMessage(list); | 1109 writer.WriteMessage(list); |
1110 intptr_t buffer_len = writer.BytesWritten(); | 1110 intptr_t buffer_len = writer.BytesWritten(); |
1111 | 1111 |
1112 // Read object back from the snapshot into a C structure. | 1112 // Read object back from the snapshot into a C structure. |
(...skipping 19 matching lines...) Expand all Loading... |
1132 | 1132 |
1133 TestCase::CreateTestIsolate(); | 1133 TestCase::CreateTestIsolate(); |
1134 Isolate* isolate = Isolate::Current(); | 1134 Isolate* isolate = Isolate::Current(); |
1135 EXPECT(isolate != NULL); | 1135 EXPECT(isolate != NULL); |
1136 Dart_EnterScope(); | 1136 Dart_EnterScope(); |
1137 | 1137 |
1138 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, | 1138 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, |
1139 NULL); | 1139 NULL); |
1140 EXPECT_VALID(lib); | 1140 EXPECT_VALID(lib); |
1141 Dart_Handle smi_result; | 1141 Dart_Handle smi_result; |
1142 smi_result = Dart_Invoke(lib, Dart_NewString("getSmi"), 0, NULL); | 1142 smi_result = Dart_Invoke(lib, NewString("getSmi"), 0, NULL); |
1143 EXPECT_VALID(smi_result); | 1143 EXPECT_VALID(smi_result); |
1144 Dart_Handle bigint_result; | 1144 Dart_Handle bigint_result; |
1145 bigint_result = Dart_Invoke(lib, Dart_NewString("getBigint"), 0, NULL); | 1145 bigint_result = Dart_Invoke(lib, NewString("getBigint"), 0, NULL); |
1146 EXPECT_VALID(bigint_result); | 1146 EXPECT_VALID(bigint_result); |
1147 Dart_Handle string_result; | 1147 Dart_Handle string_result; |
1148 string_result = Dart_Invoke(lib, Dart_NewString("getString"), 0, NULL); | 1148 string_result = Dart_Invoke(lib, NewString("getString"), 0, NULL); |
1149 EXPECT_VALID(string_result); | 1149 EXPECT_VALID(string_result); |
1150 EXPECT(Dart_IsString(string_result)); | 1150 EXPECT(Dart_IsString(string_result)); |
1151 | 1151 |
1152 { | 1152 { |
1153 DARTSCOPE_NOCHECKS(isolate); | 1153 DARTSCOPE_NOCHECKS(isolate); |
1154 | 1154 |
1155 { | 1155 { |
1156 StackZone zone(Isolate::Current()); | 1156 StackZone zone(Isolate::Current()); |
1157 uint8_t* buffer; | 1157 uint8_t* buffer; |
1158 MessageWriter writer(&buffer, &zone_allocator); | 1158 MessageWriter writer(&buffer, &zone_allocator); |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 " }\n" | 1896 " }\n" |
1897 " messageCount++;\n" | 1897 " messageCount++;\n" |
1898 " if (messageCount == 8) throw new Exception(exception);\n" | 1898 " if (messageCount == 8) throw new Exception(exception);\n" |
1899 " });\n" | 1899 " });\n" |
1900 " return port.toSendPort();\n" | 1900 " return port.toSendPort();\n" |
1901 "}\n"; | 1901 "}\n"; |
1902 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 1902 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
1903 Dart_EnterScope(); | 1903 Dart_EnterScope(); |
1904 | 1904 |
1905 // xxx | 1905 // xxx |
1906 Dart_Handle send_port = Dart_Invoke(lib, Dart_NewString("main"), 0, NULL); | 1906 Dart_Handle send_port = Dart_Invoke(lib, NewString("main"), 0, NULL); |
1907 EXPECT_VALID(send_port); | 1907 EXPECT_VALID(send_port); |
1908 Dart_Handle result = Dart_GetField(send_port, Dart_NewString("_id")); | 1908 Dart_Handle result = Dart_GetField(send_port, NewString("_id")); |
1909 ASSERT(!Dart_IsError(result)); | 1909 ASSERT(!Dart_IsError(result)); |
1910 ASSERT(Dart_IsInteger(result)); | 1910 ASSERT(Dart_IsInteger(result)); |
1911 int64_t send_port_id; | 1911 int64_t send_port_id; |
1912 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); | 1912 Dart_Handle result2 = Dart_IntegerToInt64(result, &send_port_id); |
1913 ASSERT(!Dart_IsError(result2)); | 1913 ASSERT(!Dart_IsError(result2)); |
1914 | 1914 |
1915 // Setup single object message. | 1915 // Setup single object message. |
1916 Dart_CObject object; | 1916 Dart_CObject object; |
1917 | 1917 |
1918 object.type = Dart_CObject::kNull; | 1918 object.type = Dart_CObject::kNull; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 EXPECT(Dart_ErrorHasException(result)); | 1966 EXPECT(Dart_ErrorHasException(result)); |
1967 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", | 1967 EXPECT_SUBSTRING("Exception: nulltruefalse1234563.14[]100123456789\n", |
1968 Dart_GetError(result)); | 1968 Dart_GetError(result)); |
1969 | 1969 |
1970 Dart_ExitScope(); | 1970 Dart_ExitScope(); |
1971 } | 1971 } |
1972 | 1972 |
1973 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1973 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
1974 | 1974 |
1975 } // namespace dart | 1975 } // namespace dart |
OLD | NEW |