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_api.h" | 5 #include "include/dart_api.h" |
6 #include "platform/assert.h" | 6 #include "platform/assert.h" |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 | 197 |
198 // Equal objects. | 198 // Equal objects. |
199 EXPECT(!Dart_IdentityEquals(five, five_again)); | 199 EXPECT(!Dart_IdentityEquals(five, five_again)); |
200 | 200 |
201 // Different objects. | 201 // Different objects. |
202 EXPECT(!Dart_IdentityEquals(five, seven)); | 202 EXPECT(!Dart_IdentityEquals(five, seven)); |
203 | 203 |
204 // Non-instance objects. | 204 // Non-instance objects. |
205 { | 205 { |
206 Isolate* isolate = Isolate::Current(); | 206 Isolate* isolate = Isolate::Current(); |
207 DARTSCOPE_NOCHECKS(isolate); | 207 DARTSCOPE(isolate); |
208 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); | 208 Dart_Handle class1 = Api::NewHandle(isolate, Object::null_class()); |
209 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); | 209 Dart_Handle class2 = Api::NewHandle(isolate, Object::class_class()); |
210 | 210 |
211 EXPECT(Dart_IdentityEquals(class1, class1)); | 211 EXPECT(Dart_IdentityEquals(class1, class1)); |
212 | 212 |
213 EXPECT(!Dart_IdentityEquals(class1, class2)); | 213 EXPECT(!Dart_IdentityEquals(class1, class2)); |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 | 217 |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); | 823 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); |
824 EXPECT(Dart_IsList(byte_array1)); | 824 EXPECT(Dart_IsList(byte_array1)); |
825 | 825 |
826 intptr_t length = 0; | 826 intptr_t length = 0; |
827 Dart_Handle result = Dart_ListLength(byte_array1, &length); | 827 Dart_Handle result = Dart_ListLength(byte_array1, &length); |
828 EXPECT_VALID(result); | 828 EXPECT_VALID(result); |
829 EXPECT_EQ(10, length); | 829 EXPECT_EQ(10, length); |
830 | 830 |
831 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); | 831 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); |
832 EXPECT(Dart_IsError(result)); | 832 EXPECT(Dart_IsError(result)); |
833 result = Dart_ByteArraySetUint8At(byte_array1, -1, 1); | |
834 EXPECT(Dart_IsError(result)); | |
835 | 833 |
836 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); | 834 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); |
837 EXPECT(Dart_IsError(result)); | 835 EXPECT(Dart_IsError(result)); |
838 result = Dart_ByteArraySetUint8At(byte_array1, 10, 1); | |
839 EXPECT(Dart_IsError(result)); | |
840 | 836 |
841 // Set through the List API. | 837 // Set through the List API. |
842 for (intptr_t i = 0; i < 10; ++i) { | 838 for (intptr_t i = 0; i < 10; ++i) { |
843 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1))); | 839 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1))); |
844 } | 840 } |
845 for (intptr_t i = 0; i < 10; ++i) { | 841 for (intptr_t i = 0; i < 10; ++i) { |
846 // Get through the List API. | 842 // Get through the List API. |
847 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 843 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
848 EXPECT_VALID(integer_obj); | 844 EXPECT_VALID(integer_obj); |
849 int64_t int64_t_value = -1; | 845 int64_t int64_t_value = -1; |
850 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 846 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
851 EXPECT_EQ(i + 1, int64_t_value); | 847 EXPECT_EQ(i + 1, int64_t_value); |
852 // Get through the ByteArray API. | |
853 uint8_t uint8_t_value = 0xFF; | |
854 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
855 EXPECT_EQ(i + 1, uint8_t_value); | |
856 } | |
857 | |
858 // Set through the ByteArray API. | |
859 for (intptr_t i = 0; i < 10; ++i) { | |
860 EXPECT_VALID(Dart_ByteArraySetUint8At(byte_array1, i, i + 2)); | |
861 } | |
862 for (intptr_t i = 0; i < 10; ++i) { | |
863 // Get through the List API. | |
864 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | |
865 EXPECT_VALID(integer_obj); | |
866 int64_t int64_t_value = -1; | |
867 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | |
868 EXPECT_EQ(i + 2, int64_t_value); | |
869 // Get through the ByteArray API. | |
870 uint8_t uint8_t_value = 0xFF; | |
871 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
872 EXPECT_EQ(i + 2, uint8_t_value); | |
873 } | 848 } |
874 | 849 |
875 Dart_Handle byte_array2 = Dart_NewByteArray(10); | 850 Dart_Handle byte_array2 = Dart_NewByteArray(10); |
876 bool is_equal = false; | 851 bool is_equal = false; |
877 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); | 852 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); |
878 EXPECT(!is_equal); | 853 EXPECT(!is_equal); |
879 | 854 |
880 // Set through the List API. | 855 // Set through the List API. |
881 for (intptr_t i = 0; i < 10; ++i) { | 856 for (intptr_t i = 0; i < 10; ++i) { |
| 857 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 2)); |
| 858 EXPECT_VALID(result); |
882 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2)); | 859 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2)); |
883 EXPECT_VALID(result); | 860 EXPECT_VALID(result); |
884 } | 861 } |
885 for (intptr_t i = 0; i < 10; ++i) { | 862 for (intptr_t i = 0; i < 10; ++i) { |
886 // Get through the List API. | 863 // Get through the List API. |
887 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); | 864 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); |
888 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); | 865 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); |
889 is_equal = false; | 866 is_equal = false; |
890 Dart_ObjectEquals(e1, e2, &is_equal); | 867 Dart_ObjectEquals(e1, e2, &is_equal); |
891 EXPECT(is_equal); | 868 EXPECT(is_equal); |
892 // Get through the ByteArray API. | |
893 uint8_t v1 = 0xFF; | |
894 uint8_t v2 = 0XFF; | |
895 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &v1)); | |
896 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array2, i, &v2)); | |
897 EXPECT_NE(v1, 0xFF); | |
898 EXPECT_NE(v2, 0xFF); | |
899 EXPECT_EQ(v1, v2); | |
900 } | |
901 | |
902 byte_array2 = Dart_NewByteArray(10); | |
903 is_equal = false; | |
904 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); | |
905 EXPECT(!is_equal); | |
906 | |
907 // Set through the ByteArray API. | |
908 for (intptr_t i = 0; i < 10; ++i) { | |
909 result = Dart_ByteArraySetUint8At(byte_array2, i, i + 2); | |
910 EXPECT_VALID(result); | |
911 } | |
912 for (intptr_t i = 0; i < 10; ++i) { | |
913 // Get through the List API. | |
914 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); | |
915 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); | |
916 is_equal = false; | |
917 Dart_ObjectEquals(e1, e2, &is_equal); | |
918 EXPECT(is_equal); | |
919 // Get through the ByteArray API. | |
920 uint8_t v1 = 0xFF; | |
921 uint8_t v2 = 0XFF; | |
922 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &v1)); | |
923 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array2, i, &v2)); | |
924 EXPECT_NE(v1, 0xFF); | |
925 EXPECT_NE(v2, 0xFF); | |
926 EXPECT_EQ(v1, v2); | |
927 } | 869 } |
928 | 870 |
929 uint8_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | 871 uint8_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
930 result = Dart_ListSetAsBytes(byte_array1, 0, data, 10); | |
931 EXPECT_VALID(result); | |
932 for (intptr_t i = 0; i < 10; ++i) { | |
933 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | |
934 EXPECT_VALID(integer_obj); | |
935 int64_t int64_t_value = -1; | |
936 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | |
937 EXPECT_EQ(i, int64_t_value); | |
938 uint8_t uint8_t_value = 0xFF; | |
939 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
940 EXPECT_EQ(i, uint8_t_value); | |
941 } | |
942 | |
943 for (intptr_t i = 0; i < 10; ++i) { | 872 for (intptr_t i = 0; i < 10; ++i) { |
944 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); | 873 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); |
945 } | 874 } |
946 Dart_ListGetAsBytes(byte_array1, 0, data, 10); | 875 Dart_ListGetAsBytes(byte_array1, 0, data, 10); |
947 for (intptr_t i = 0; i < 10; ++i) { | 876 for (intptr_t i = 0; i < 10; ++i) { |
948 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 877 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
949 EXPECT_VALID(integer_obj); | 878 EXPECT_VALID(integer_obj); |
950 int64_t int64_t_value = -1; | 879 int64_t int64_t_value = -1; |
951 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 880 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
952 EXPECT_EQ(10 - i, int64_t_value); | 881 EXPECT_EQ(10 - i, int64_t_value); |
953 uint8_t uint8_t_value = 0xFF; | |
954 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
955 EXPECT_EQ(10 - i, uint8_t_value); | |
956 } | |
957 | |
958 for (intptr_t i = 0; i < 10; ++i) { | |
959 EXPECT_VALID(Dart_ByteArraySetUint8At(byte_array1, i, 10 + i)); | |
960 } | |
961 Dart_ListGetAsBytes(byte_array1, 0, data, 10); | |
962 for (intptr_t i = 0; i < 10; ++i) { | |
963 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | |
964 EXPECT_VALID(integer_obj); | |
965 int64_t int64_t_value = -1; | |
966 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | |
967 EXPECT_EQ(10 + i, int64_t_value); | |
968 uint8_t uint8_t_value = 0xFF; | |
969 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
970 EXPECT_EQ(10 + i, uint8_t_value); | |
971 } | 882 } |
972 } | 883 } |
973 | 884 |
974 | 885 |
975 TEST_CASE(ByteArrayAlignedMultiByteAccess) { | 886 TEST_CASE(ScalarListDirectAccess) { |
976 intptr_t length = 16; | 887 Dart_Handle str = Dart_NewStringFromCString("junk"); |
977 Dart_Handle byte_array = Dart_NewByteArray(length); | 888 Dart_Handle byte_array = Dart_NewByteArray(10); |
978 intptr_t api_length = 0; | 889 EXPECT_VALID(byte_array); |
979 EXPECT_VALID(Dart_ListLength(byte_array, &api_length)); | 890 Dart_Handle result; |
980 EXPECT_EQ(length, api_length); | 891 result = Dart_ScalarListAcquireData(byte_array, NULL, NULL, NULL); |
| 892 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'type'" |
| 893 " to be non-null."); |
| 894 Dart_Scalar_Type type; |
| 895 result = Dart_ScalarListAcquireData(byte_array, &type, NULL, NULL); |
| 896 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'data'" |
| 897 " to be non-null."); |
| 898 void* data; |
| 899 result = Dart_ScalarListAcquireData(byte_array, &type, &data, NULL); |
| 900 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'len'" |
| 901 " to be non-null."); |
| 902 intptr_t len; |
| 903 result = Dart_ScalarListAcquireData(Dart_Null(), &type, &data, &len); |
| 904 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'array'" |
| 905 " to be non-null."); |
| 906 result = Dart_ScalarListAcquireData(str, &type, &data, &len); |
| 907 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'array'" |
| 908 " to be of type 'scalar list'."); |
981 | 909 |
982 // 4-byte aligned sets. | 910 result = Dart_ScalarListReleaseData(Dart_Null()); |
983 | 911 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" |
984 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 0, FLT_MIN)); | 912 " to be non-null."); |
985 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 4, FLT_MAX)); | 913 result = Dart_ScalarListReleaseData(str); |
986 | 914 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" |
987 float float_value = 0.0f; | 915 " to be of type 'scalar list'."); |
988 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 0, &float_value)); | |
989 EXPECT_EQ(FLT_MIN, float_value); | |
990 | |
991 float_value = 0.0f; | |
992 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 4, &float_value)); | |
993 EXPECT_EQ(FLT_MAX, float_value); | |
994 | |
995 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 0, 0.0f)); | |
996 float_value = FLT_MAX; | |
997 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 0, &float_value)); | |
998 EXPECT_EQ(0.0f, float_value); | |
999 | |
1000 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 4, 1.0f)); | |
1001 float_value = FLT_MAX; | |
1002 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 4, &float_value)); | |
1003 EXPECT_EQ(1.0f, float_value); | |
1004 | |
1005 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 0, -1.0f)); | |
1006 float_value = FLT_MAX; | |
1007 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 0, &float_value)); | |
1008 EXPECT_EQ(-1.0f, float_value); | |
1009 | |
1010 // 8-byte aligned sets. | |
1011 | |
1012 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 0, DBL_MIN)); | |
1013 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 8, DBL_MAX)); | |
1014 | |
1015 double double_value = 0.0; | |
1016 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 0, &double_value)); | |
1017 EXPECT_EQ(DBL_MIN, double_value); | |
1018 | |
1019 double_value = 0.0; | |
1020 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 8, &double_value)); | |
1021 EXPECT_EQ(DBL_MAX, double_value); | |
1022 | |
1023 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 0, 0.0)); | |
1024 double_value = DBL_MAX; | |
1025 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 0, &double_value)); | |
1026 EXPECT_EQ(0.0, double_value); | |
1027 | |
1028 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 8, 1.0)); | |
1029 double_value = DBL_MAX; | |
1030 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 8, &double_value)); | |
1031 EXPECT_EQ(1.0, double_value); | |
1032 } | |
1033 | |
1034 | |
1035 TEST_CASE(ByteArrayMisalignedMultiByteAccess) { | |
1036 intptr_t length = 17; | |
1037 Dart_Handle byte_array = Dart_NewByteArray(length); | |
1038 intptr_t api_length = 0; | |
1039 EXPECT_VALID(Dart_ListLength(byte_array, &api_length)); | |
1040 EXPECT_EQ(length, api_length); | |
1041 | |
1042 // 4-byte misaligned sets. | |
1043 | |
1044 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 1, FLT_MIN)); | |
1045 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 5, FLT_MAX)); | |
1046 | |
1047 float float_value = 0.0f; | |
1048 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 1, &float_value)); | |
1049 EXPECT_EQ(FLT_MIN, float_value); | |
1050 | |
1051 float_value = 0.0f; | |
1052 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 5, &float_value)); | |
1053 EXPECT_EQ(FLT_MAX, float_value); | |
1054 | |
1055 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 1, 0.0f)); | |
1056 float_value = FLT_MAX; | |
1057 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 1, &float_value)); | |
1058 EXPECT_EQ(0.0f, float_value); | |
1059 | |
1060 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 5, -0.0f)); | |
1061 float_value = FLT_MAX; | |
1062 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 5, &float_value)); | |
1063 EXPECT_EQ(-0.0f, float_value); | |
1064 | |
1065 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 5, 1.0f)); | |
1066 float_value = FLT_MAX; | |
1067 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 5, &float_value)); | |
1068 EXPECT_EQ(1.0f, float_value); | |
1069 | |
1070 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 1, -1.0f)); | |
1071 float_value = FLT_MAX; | |
1072 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 1, &float_value)); | |
1073 EXPECT_EQ(-1.0f, float_value); | |
1074 | |
1075 // 8-byte misaligned sets. | |
1076 | |
1077 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, DBL_MIN)); | |
1078 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 9, DBL_MAX)); | |
1079 | |
1080 double double_value = 0.0; | |
1081 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); | |
1082 EXPECT_EQ(DBL_MIN, double_value); | |
1083 | |
1084 double_value = 0.0; | |
1085 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); | |
1086 EXPECT_EQ(DBL_MAX, double_value); | |
1087 | |
1088 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, 0.0)); | |
1089 double_value = DBL_MAX; | |
1090 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); | |
1091 EXPECT_EQ(0.0, double_value); | |
1092 | |
1093 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 9, -0.0)); | |
1094 double_value = DBL_MAX; | |
1095 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); | |
1096 EXPECT_EQ(-0.0, double_value); | |
1097 | |
1098 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 9, 1.0)); | |
1099 double_value = DBL_MAX; | |
1100 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); | |
1101 EXPECT_EQ(1.0, double_value); | |
1102 | |
1103 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, -1.0)); | |
1104 double_value = DBL_MAX; | |
1105 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); | |
1106 EXPECT_EQ(-1.0, double_value); | |
1107 } | 916 } |
1108 | 917 |
1109 | 918 |
1110 static void ExternalByteArrayAccessTests(Dart_Handle obj, | 919 static void ExternalByteArrayAccessTests(Dart_Handle obj, |
1111 uint8_t data[], | 920 uint8_t data[], |
1112 intptr_t data_length) { | 921 intptr_t data_length) { |
1113 EXPECT_VALID(obj); | 922 EXPECT_VALID(obj); |
1114 EXPECT(Dart_IsByteArray(obj)); | 923 EXPECT(Dart_IsByteArray(obj)); |
1115 EXPECT(Dart_IsByteArrayExternal(obj)); | 924 EXPECT(Dart_IsByteArrayExternal(obj)); |
1116 EXPECT(Dart_IsList(obj)); | 925 EXPECT(Dart_IsList(obj)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 TestIsolateScope __test_isolate__; | 1064 TestIsolateScope __test_isolate__; |
1256 | 1065 |
1257 Isolate* isolate = Isolate::Current(); | 1066 Isolate* isolate = Isolate::Current(); |
1258 EXPECT(isolate != NULL); | 1067 EXPECT(isolate != NULL); |
1259 ApiState* state = isolate->api_state(); | 1068 ApiState* state = isolate->api_state(); |
1260 EXPECT(state != NULL); | 1069 EXPECT(state != NULL); |
1261 ApiLocalScope* scope = state->top_scope(); | 1070 ApiLocalScope* scope = state->top_scope(); |
1262 Dart_EnterScope(); | 1071 Dart_EnterScope(); |
1263 { | 1072 { |
1264 EXPECT(state->top_scope() != NULL); | 1073 EXPECT(state->top_scope() != NULL); |
1265 DARTSCOPE_NOCHECKS(isolate); | 1074 DARTSCOPE(isolate); |
1266 const String& str1 = String::Handle(String::New("Test String")); | 1075 const String& str1 = String::Handle(String::New("Test String")); |
1267 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); | 1076 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); |
1268 String& str2 = String::Handle(); | 1077 String& str2 = String::Handle(); |
1269 str2 ^= Api::UnwrapHandle(ref); | 1078 str2 ^= Api::UnwrapHandle(ref); |
1270 EXPECT(str1.Equals(str2)); | 1079 EXPECT(str1.Equals(str2)); |
1271 } | 1080 } |
1272 Dart_ExitScope(); | 1081 Dart_ExitScope(); |
1273 EXPECT(scope == state->top_scope()); | 1082 EXPECT(scope == state->top_scope()); |
1274 } | 1083 } |
1275 | 1084 |
1276 | 1085 |
1277 // Unit test for creating and deleting persistent handles. | 1086 // Unit test for creating and deleting persistent handles. |
1278 UNIT_TEST_CASE(PersistentHandles) { | 1087 UNIT_TEST_CASE(PersistentHandles) { |
1279 const char* kTestString1 = "Test String1"; | 1088 const char* kTestString1 = "Test String1"; |
1280 const char* kTestString2 = "Test String2"; | 1089 const char* kTestString2 = "Test String2"; |
1281 TestCase::CreateTestIsolate(); | 1090 TestCase::CreateTestIsolate(); |
1282 Isolate* isolate = Isolate::Current(); | 1091 Isolate* isolate = Isolate::Current(); |
1283 EXPECT(isolate != NULL); | 1092 EXPECT(isolate != NULL); |
1284 ApiState* state = isolate->api_state(); | 1093 ApiState* state = isolate->api_state(); |
1285 EXPECT(state != NULL); | 1094 EXPECT(state != NULL); |
1286 ApiLocalScope* scope = state->top_scope(); | 1095 ApiLocalScope* scope = state->top_scope(); |
1287 Dart_Handle handles[2000]; | 1096 Dart_Handle handles[2000]; |
1288 Dart_EnterScope(); | 1097 Dart_EnterScope(); |
1289 { | 1098 { |
1290 DARTSCOPE_NOCHECKS(isolate); | 1099 DARTSCOPE(isolate); |
1291 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 1100 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
1292 for (int i = 0; i < 1000; i++) { | 1101 for (int i = 0; i < 1000; i++) { |
1293 handles[i] = Dart_NewPersistentHandle(ref1); | 1102 handles[i] = Dart_NewPersistentHandle(ref1); |
1294 } | 1103 } |
1295 Dart_EnterScope(); | 1104 Dart_EnterScope(); |
1296 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); | 1105 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); |
1297 for (int i = 1000; i < 2000; i++) { | 1106 for (int i = 1000; i < 2000; i++) { |
1298 handles[i] = Dart_NewPersistentHandle(ref2); | 1107 handles[i] = Dart_NewPersistentHandle(ref2); |
1299 } | 1108 } |
1300 for (int i = 500; i < 1500; i++) { | 1109 for (int i = 500; i < 1500; i++) { |
1301 Dart_DeletePersistentHandle(handles[i]); | 1110 Dart_DeletePersistentHandle(handles[i]); |
1302 } | 1111 } |
1303 for (int i = 500; i < 1000; i++) { | 1112 for (int i = 500; i < 1000; i++) { |
1304 handles[i] = Dart_NewPersistentHandle(ref2); | 1113 handles[i] = Dart_NewPersistentHandle(ref2); |
1305 } | 1114 } |
1306 for (int i = 1000; i < 1500; i++) { | 1115 for (int i = 1000; i < 1500; i++) { |
1307 handles[i] = Dart_NewPersistentHandle(ref1); | 1116 handles[i] = Dart_NewPersistentHandle(ref1); |
1308 } | 1117 } |
1309 VERIFY_ON_TRANSITION; | 1118 VERIFY_ON_TRANSITION; |
1310 Dart_ExitScope(); | 1119 Dart_ExitScope(); |
1311 } | 1120 } |
1312 Dart_ExitScope(); | 1121 Dart_ExitScope(); |
1313 { | 1122 { |
1314 StackZone zone(isolate); | 1123 StackZone zone(isolate); |
1315 DARTSCOPE_NOCHECKS(isolate); | 1124 HANDLESCOPE(isolate); |
1316 for (int i = 0; i < 500; i++) { | 1125 for (int i = 0; i < 500; i++) { |
1317 String& str = String::Handle(); | 1126 String& str = String::Handle(); |
1318 str ^= Api::UnwrapHandle(handles[i]); | 1127 str ^= Api::UnwrapHandle(handles[i]); |
1319 EXPECT(str.Equals(kTestString1)); | 1128 EXPECT(str.Equals(kTestString1)); |
1320 } | 1129 } |
1321 for (int i = 500; i < 1000; i++) { | 1130 for (int i = 500; i < 1000; i++) { |
1322 String& str = String::Handle(); | 1131 String& str = String::Handle(); |
1323 str ^= Api::UnwrapHandle(handles[i]); | 1132 str ^= Api::UnwrapHandle(handles[i]); |
1324 EXPECT(str.Equals(kTestString2)); | 1133 EXPECT(str.Equals(kTestString2)); |
1325 } | 1134 } |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2256 UNIT_TEST_CASE(LocalHandles) { | 2065 UNIT_TEST_CASE(LocalHandles) { |
2257 TestCase::CreateTestIsolate(); | 2066 TestCase::CreateTestIsolate(); |
2258 Isolate* isolate = Isolate::Current(); | 2067 Isolate* isolate = Isolate::Current(); |
2259 EXPECT(isolate != NULL); | 2068 EXPECT(isolate != NULL); |
2260 ApiState* state = isolate->api_state(); | 2069 ApiState* state = isolate->api_state(); |
2261 EXPECT(state != NULL); | 2070 EXPECT(state != NULL); |
2262 ApiLocalScope* scope = state->top_scope(); | 2071 ApiLocalScope* scope = state->top_scope(); |
2263 Dart_Handle handles[300]; | 2072 Dart_Handle handles[300]; |
2264 { | 2073 { |
2265 StackZone zone(isolate); | 2074 StackZone zone(isolate); |
2266 DARTSCOPE_NOCHECKS(isolate); | 2075 HANDLESCOPE(isolate); |
2267 Smi& val = Smi::Handle(); | 2076 Smi& val = Smi::Handle(); |
2268 | 2077 |
2269 // Start a new scope and allocate some local handles. | 2078 // Start a new scope and allocate some local handles. |
2270 Dart_EnterScope(); | 2079 Dart_EnterScope(); |
2271 for (int i = 0; i < 100; i++) { | 2080 for (int i = 0; i < 100; i++) { |
2272 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 2081 handles[i] = Api::NewHandle(isolate, Smi::New(i)); |
2273 } | 2082 } |
2274 EXPECT_EQ(100, state->CountLocalHandles()); | 2083 EXPECT_EQ(100, state->CountLocalHandles()); |
2275 for (int i = 0; i < 100; i++) { | 2084 for (int i = 0; i < 100; i++) { |
2276 val ^= Api::UnwrapHandle(handles[i]); | 2085 val ^= Api::UnwrapHandle(handles[i]); |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2916 result = Dart_CreateNativeWrapperClass( | 2725 result = Dart_CreateNativeWrapperClass( |
2917 lib, | 2726 lib, |
2918 NewString("NativeFieldsWrapper"), | 2727 NewString("NativeFieldsWrapper"), |
2919 kNumNativeFields); | 2728 kNumNativeFields); |
2920 | 2729 |
2921 // Load up a test script in the test library. | 2730 // Load up a test script in the test library. |
2922 | 2731 |
2923 // Invoke a function which returns an object of type NativeFields. | 2732 // Invoke a function which returns an object of type NativeFields. |
2924 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 2733 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
2925 EXPECT_VALID(result); | 2734 EXPECT_VALID(result); |
2926 DARTSCOPE_NOCHECKS(Isolate::Current()); | 2735 DARTSCOPE(Isolate::Current()); |
2927 Instance& obj = Instance::Handle(); | 2736 Instance& obj = Instance::Handle(); |
2928 obj ^= Api::UnwrapHandle(result); | 2737 obj ^= Api::UnwrapHandle(result); |
2929 const Class& cls = Class::Handle(obj.clazz()); | 2738 const Class& cls = Class::Handle(obj.clazz()); |
2930 // We expect the newly created "NativeFields" object to have | 2739 // We expect the newly created "NativeFields" object to have |
2931 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 2740 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
2932 // Hence the size of an instance of "NativeFields" should be | 2741 // Hence the size of an instance of "NativeFields" should be |
2933 // (1 + 2) * kWordSize + size of object header. | 2742 // (1 + 2) * kWordSize + size of object header. |
2934 // We check to make sure the instance size computed by the VM matches | 2743 // We check to make sure the instance size computed by the VM matches |
2935 // our expectations. | 2744 // our expectations. |
2936 intptr_t header_size = sizeof(RawObject); | 2745 intptr_t header_size = sizeof(RawObject); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2985 Dart_Handle result; | 2794 Dart_Handle result; |
2986 const int kNumNativeFields = 2; | 2795 const int kNumNativeFields = 2; |
2987 | 2796 |
2988 // Load up a test script in the test library. | 2797 // Load up a test script in the test library. |
2989 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 2798 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
2990 native_field_lookup); | 2799 native_field_lookup); |
2991 | 2800 |
2992 // Invoke a function which returns an object of type NativeFields. | 2801 // Invoke a function which returns an object of type NativeFields. |
2993 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 2802 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
2994 EXPECT_VALID(result); | 2803 EXPECT_VALID(result); |
2995 DARTSCOPE_NOCHECKS(Isolate::Current()); | 2804 DARTSCOPE(Isolate::Current()); |
2996 Instance& obj = Instance::Handle(); | 2805 Instance& obj = Instance::Handle(); |
2997 obj ^= Api::UnwrapHandle(result); | 2806 obj ^= Api::UnwrapHandle(result); |
2998 const Class& cls = Class::Handle(obj.clazz()); | 2807 const Class& cls = Class::Handle(obj.clazz()); |
2999 // We expect the newly created "NativeFields" object to have | 2808 // We expect the newly created "NativeFields" object to have |
3000 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 2809 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
3001 // Hence the size of an instance of "NativeFields" should be | 2810 // Hence the size of an instance of "NativeFields" should be |
3002 // (1 + 2) * kWordSize + size of object header. | 2811 // (1 + 2) * kWordSize + size of object header. |
3003 // We check to make sure the instance size computed by the VM matches | 2812 // We check to make sure the instance size computed by the VM matches |
3004 // our expectations. | 2813 // our expectations. |
3005 intptr_t header_size = sizeof(RawObject); | 2814 intptr_t header_size = sizeof(RawObject); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3240 " static const int fld4 = 10;\n" | 3049 " static const int fld4 = 10;\n" |
3241 "}\n" | 3050 "}\n" |
3242 "NativeFields testMain1() {\n" | 3051 "NativeFields testMain1() {\n" |
3243 " NativeFields obj = new NativeFields(10, 20);\n" | 3052 " NativeFields obj = new NativeFields(10, 20);\n" |
3244 " return obj;\n" | 3053 " return obj;\n" |
3245 "}\n" | 3054 "}\n" |
3246 "Function testMain2() {\n" | 3055 "Function testMain2() {\n" |
3247 " return () {};\n" | 3056 " return () {};\n" |
3248 "}\n"; | 3057 "}\n"; |
3249 Dart_Handle result; | 3058 Dart_Handle result; |
3250 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3059 DARTSCOPE(Isolate::Current()); |
3251 | 3060 |
3252 // Create a test library and Load up a test script in it. | 3061 // Create a test library and Load up a test script in it. |
3253 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3062 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3254 | 3063 |
3255 // Invoke a function which returns an object of type NativeFields. | 3064 // Invoke a function which returns an object of type NativeFields. |
3256 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 3065 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
3257 EXPECT_VALID(retobj); | 3066 EXPECT_VALID(retobj); |
3258 | 3067 |
3259 // Now access and set various native instance fields of the returned object. | 3068 // Now access and set various native instance fields of the returned object. |
3260 // All of these tests are expected to return failure as there are no | 3069 // All of these tests are expected to return failure as there are no |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3316 "}\n" | 3125 "}\n" |
3317 "main() {\n" | 3126 "main() {\n" |
3318 " var snd = spawnFunction(echo);\n" | 3127 " var snd = spawnFunction(echo);\n" |
3319 " var obj = new Test(1,2);\n" | 3128 " var obj = new Test(1,2);\n" |
3320 " snd.send(obj, port.toSendPort());\n" | 3129 " snd.send(obj, port.toSendPort());\n" |
3321 " port.receive((msg, reply) {\n" | 3130 " port.receive((msg, reply) {\n" |
3322 " print('from worker ${msg}');\n" | 3131 " print('from worker ${msg}');\n" |
3323 " });\n" | 3132 " });\n" |
3324 "}\n"; | 3133 "}\n"; |
3325 | 3134 |
3326 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3135 DARTSCOPE(Isolate::Current()); |
3327 | 3136 |
3328 // Create a test library and Load up a test script in it. | 3137 // Create a test library and Load up a test script in it. |
3329 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3138 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3330 | 3139 |
3331 // Invoke 'main' which should spawn an isolate and try to send an | 3140 // Invoke 'main' which should spawn an isolate and try to send an |
3332 // object with native fields over to the spawned isolate. This | 3141 // object with native fields over to the spawned isolate. This |
3333 // should result in an unhandled exception which is checked. | 3142 // should result in an unhandled exception which is checked. |
3334 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 3143 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
3335 EXPECT(Dart_IsError(retobj)); | 3144 EXPECT(Dart_IsError(retobj)); |
3336 } | 3145 } |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3899 "}\n" | 3708 "}\n" |
3900 "Function getStaticClosure() {\n" | 3709 "Function getStaticClosure() {\n" |
3901 " return Foo.getStaticClosure();\n" | 3710 " return Foo.getStaticClosure();\n" |
3902 "}\n" | 3711 "}\n" |
3903 "Function getStaticClosureWithArgs() {\n" | 3712 "Function getStaticClosureWithArgs() {\n" |
3904 " return Foo.getStaticClosureWithArgs();\n" | 3713 " return Foo.getStaticClosureWithArgs();\n" |
3905 "}\n"; | 3714 "}\n"; |
3906 Dart_Handle result; | 3715 Dart_Handle result; |
3907 Dart_Handle owner; | 3716 Dart_Handle owner; |
3908 Dart_Handle defining_function; | 3717 Dart_Handle defining_function; |
3909 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3718 DARTSCOPE(Isolate::Current()); |
3910 | 3719 |
3911 // Create a test library and Load up a test script in it. | 3720 // Create a test library and Load up a test script in it. |
3912 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3721 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3913 EXPECT_VALID(lib); | 3722 EXPECT_VALID(lib); |
3914 Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); | 3723 Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); |
3915 EXPECT_VALID(cls); | 3724 EXPECT_VALID(cls); |
3916 | 3725 |
3917 // Invoke a function which returns a closure. | 3726 // Invoke a function which returns a closure. |
3918 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); | 3727 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); |
3919 EXPECT_VALID(retobj); | 3728 EXPECT_VALID(retobj); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4067 " static const int fld4 = 10;\n" | 3876 " static const int fld4 = 10;\n" |
4068 "}\n" | 3877 "}\n" |
4069 "Function testMain1() {\n" | 3878 "Function testMain1() {\n" |
4070 " InvokeClosure obj = new InvokeClosure(10, 20);\n" | 3879 " InvokeClosure obj = new InvokeClosure(10, 20);\n" |
4071 " return obj.method1(10);\n" | 3880 " return obj.method1(10);\n" |
4072 "}\n" | 3881 "}\n" |
4073 "Function testMain2() {\n" | 3882 "Function testMain2() {\n" |
4074 " return InvokeClosure.method2(10);\n" | 3883 " return InvokeClosure.method2(10);\n" |
4075 "}\n"; | 3884 "}\n"; |
4076 Dart_Handle result; | 3885 Dart_Handle result; |
4077 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3886 DARTSCOPE(Isolate::Current()); |
4078 | 3887 |
4079 // Create a test library and Load up a test script in it. | 3888 // Create a test library and Load up a test script in it. |
4080 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3889 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4081 | 3890 |
4082 // Invoke a function which returns a closure. | 3891 // Invoke a function which returns a closure. |
4083 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 3892 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
4084 EXPECT_VALID(retobj); | 3893 EXPECT_VALID(retobj); |
4085 | 3894 |
4086 EXPECT(Dart_IsClosure(retobj)); | 3895 EXPECT(Dart_IsClosure(retobj)); |
4087 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 3896 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
(...skipping 2842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6930 } | 6739 } |
6931 | 6740 |
6932 | 6741 |
6933 // Allocates an object in new space and assigns it a peer. Allows the | 6742 // Allocates an object in new space and assigns it a peer. Allows the |
6934 // peer referent to be garbage collected and checks that the count of | 6743 // peer referent to be garbage collected and checks that the count of |
6935 // peer objects is decremented by one. | 6744 // peer objects is decremented by one. |
6936 TEST_CASE(CollectOneNewSpacePeer) { | 6745 TEST_CASE(CollectOneNewSpacePeer) { |
6937 Isolate* isolate = Isolate::Current(); | 6746 Isolate* isolate = Isolate::Current(); |
6938 Dart_EnterScope(); | 6747 Dart_EnterScope(); |
6939 { | 6748 { |
6940 DARTSCOPE_NOCHECKS(isolate); | 6749 DARTSCOPE(isolate); |
6941 Dart_Handle str = NewString("a string"); | 6750 Dart_Handle str = NewString("a string"); |
6942 EXPECT_VALID(str); | 6751 EXPECT_VALID(str); |
6943 EXPECT(Dart_IsString(str)); | 6752 EXPECT(Dart_IsString(str)); |
6944 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6753 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
6945 void* out = &out; | 6754 void* out = &out; |
6946 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6755 EXPECT_VALID(Dart_GetPeer(str, &out)); |
6947 EXPECT(out == NULL); | 6756 EXPECT(out == NULL); |
6948 int peer = 1234; | 6757 int peer = 1234; |
6949 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6758 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
6950 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6759 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7003 } | 6812 } |
7004 | 6813 |
7005 | 6814 |
7006 // Allocates two objects in new space and assigns them a peer. Allow | 6815 // Allocates two objects in new space and assigns them a peer. Allow |
7007 // the peer referents to be garbage collected and check that the count | 6816 // the peer referents to be garbage collected and check that the count |
7008 // of peer objects is decremented by two. | 6817 // of peer objects is decremented by two. |
7009 TEST_CASE(CollectTwoNewSpacePeers) { | 6818 TEST_CASE(CollectTwoNewSpacePeers) { |
7010 Isolate* isolate = Isolate::Current(); | 6819 Isolate* isolate = Isolate::Current(); |
7011 Dart_EnterScope(); | 6820 Dart_EnterScope(); |
7012 { | 6821 { |
7013 DARTSCOPE_NOCHECKS(isolate); | 6822 DARTSCOPE(isolate); |
7014 Dart_Handle s1 = NewString("s1"); | 6823 Dart_Handle s1 = NewString("s1"); |
7015 EXPECT_VALID(s1); | 6824 EXPECT_VALID(s1); |
7016 EXPECT(Dart_IsString(s1)); | 6825 EXPECT(Dart_IsString(s1)); |
7017 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6826 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7018 void* o1 = &o1; | 6827 void* o1 = &o1; |
7019 EXPECT(Dart_GetPeer(s1, &o1)); | 6828 EXPECT(Dart_GetPeer(s1, &o1)); |
7020 EXPECT(o1 == NULL); | 6829 EXPECT(o1 == NULL); |
7021 int p1 = 1234; | 6830 int p1 = 1234; |
7022 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 6831 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
7023 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6832 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7087 EXPECT(out == NULL); | 6896 EXPECT(out == NULL); |
7088 int peer = 1234; | 6897 int peer = 1234; |
7089 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6898 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7090 out = &out; | 6899 out = &out; |
7091 EXPECT(Dart_GetPeer(str, &out)); | 6900 EXPECT(Dart_GetPeer(str, &out)); |
7092 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6901 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7093 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6902 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7094 isolate->heap()->CollectGarbage(Heap::kNew); | 6903 isolate->heap()->CollectGarbage(Heap::kNew); |
7095 isolate->heap()->CollectGarbage(Heap::kNew); | 6904 isolate->heap()->CollectGarbage(Heap::kNew); |
7096 { | 6905 { |
7097 DARTSCOPE_NOCHECKS(isolate); | 6906 DARTSCOPE(isolate); |
7098 String& handle = String::Handle(); | 6907 String& handle = String::Handle(); |
7099 handle ^= Api::UnwrapHandle(str); | 6908 handle ^= Api::UnwrapHandle(str); |
7100 EXPECT(handle.IsOld()); | 6909 EXPECT(handle.IsOld()); |
7101 } | 6910 } |
7102 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6911 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7103 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6912 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7104 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6913 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7105 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 6914 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
7106 out = &out; | 6915 out = &out; |
7107 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6916 EXPECT_VALID(Dart_GetPeer(str, &out)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7140 } | 6949 } |
7141 | 6950 |
7142 | 6951 |
7143 // Allocates an object in old space and assigns it a peer. Allow the | 6952 // Allocates an object in old space and assigns it a peer. Allow the |
7144 // peer referent to be garbage collected and check that the count of | 6953 // peer referent to be garbage collected and check that the count of |
7145 // peer objects is decremented by one. | 6954 // peer objects is decremented by one. |
7146 TEST_CASE(CollectOneOldSpacePeer) { | 6955 TEST_CASE(CollectOneOldSpacePeer) { |
7147 Isolate* isolate = Isolate::Current(); | 6956 Isolate* isolate = Isolate::Current(); |
7148 Dart_EnterScope(); | 6957 Dart_EnterScope(); |
7149 { | 6958 { |
7150 DARTSCOPE_NOCHECKS(isolate); | 6959 DARTSCOPE(isolate); |
7151 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); | 6960 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); |
7152 EXPECT_VALID(str); | 6961 EXPECT_VALID(str); |
7153 EXPECT(Dart_IsString(str)); | 6962 EXPECT(Dart_IsString(str)); |
7154 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6963 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7155 void* out = &out; | 6964 void* out = &out; |
7156 EXPECT(Dart_GetPeer(str, &out)); | 6965 EXPECT(Dart_GetPeer(str, &out)); |
7157 EXPECT(out == NULL); | 6966 EXPECT(out == NULL); |
7158 int peer = 1234; | 6967 int peer = 1234; |
7159 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6968 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7160 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6969 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7216 } | 7025 } |
7217 | 7026 |
7218 | 7027 |
7219 // Allocates two objects in old space and assigns them a peer. Allows | 7028 // Allocates two objects in old space and assigns them a peer. Allows |
7220 // the peer referents to be garbage collected and checks that the | 7029 // the peer referents to be garbage collected and checks that the |
7221 // count of peer objects is decremented by two. | 7030 // count of peer objects is decremented by two. |
7222 TEST_CASE(CollectTwoOldSpacePeers) { | 7031 TEST_CASE(CollectTwoOldSpacePeers) { |
7223 Isolate* isolate = Isolate::Current(); | 7032 Isolate* isolate = Isolate::Current(); |
7224 Dart_EnterScope(); | 7033 Dart_EnterScope(); |
7225 { | 7034 { |
7226 DARTSCOPE_NOCHECKS(isolate); | 7035 DARTSCOPE(isolate); |
7227 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); | 7036 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); |
7228 EXPECT_VALID(s1); | 7037 EXPECT_VALID(s1); |
7229 EXPECT(Dart_IsString(s1)); | 7038 EXPECT(Dart_IsString(s1)); |
7230 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7039 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7231 void* o1 = &o1; | 7040 void* o1 = &o1; |
7232 EXPECT(Dart_GetPeer(s1, &o1)); | 7041 EXPECT(Dart_GetPeer(s1, &o1)); |
7233 EXPECT(o1 == NULL); | 7042 EXPECT(o1 == NULL); |
7234 int p1 = 1234; | 7043 int p1 = 1234; |
7235 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 7044 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
7236 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7045 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7530 NULL); | 7339 NULL); |
7531 int64_t value = 0; | 7340 int64_t value = 0; |
7532 result = Dart_IntegerToInt64(result, &value); | 7341 result = Dart_IntegerToInt64(result, &value); |
7533 EXPECT_VALID(result); | 7342 EXPECT_VALID(result); |
7534 EXPECT_EQ(260, value); | 7343 EXPECT_EQ(260, value); |
7535 } | 7344 } |
7536 | 7345 |
7537 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7346 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7538 | 7347 |
7539 } // namespace dart | 7348 } // namespace dart |
OLD | NEW |