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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
805 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); | 805 EXPECT(!Dart_IsByteArrayExternal(byte_array1)); |
806 EXPECT(Dart_IsList(byte_array1)); | 806 EXPECT(Dart_IsList(byte_array1)); |
807 | 807 |
808 intptr_t length = 0; | 808 intptr_t length = 0; |
809 Dart_Handle result = Dart_ListLength(byte_array1, &length); | 809 Dart_Handle result = Dart_ListLength(byte_array1, &length); |
810 EXPECT_VALID(result); | 810 EXPECT_VALID(result); |
811 EXPECT_EQ(10, length); | 811 EXPECT_EQ(10, length); |
812 | 812 |
813 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); | 813 result = Dart_ListSetAt(byte_array1, -1, Dart_NewInteger(1)); |
814 EXPECT(Dart_IsError(result)); | 814 EXPECT(Dart_IsError(result)); |
815 result = Dart_ByteArraySetUint8At(byte_array1, -1, 1); | |
816 EXPECT(Dart_IsError(result)); | |
817 | 815 |
818 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); | 816 result = Dart_ListSetAt(byte_array1, 10, Dart_NewInteger(1)); |
819 EXPECT(Dart_IsError(result)); | 817 EXPECT(Dart_IsError(result)); |
820 result = Dart_ByteArraySetUint8At(byte_array1, 10, 1); | |
821 EXPECT(Dart_IsError(result)); | |
822 | 818 |
823 // Set through the List API. | 819 // Set through the List API. |
824 for (intptr_t i = 0; i < 10; ++i) { | 820 for (intptr_t i = 0; i < 10; ++i) { |
825 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1))); | 821 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 1))); |
826 } | 822 } |
827 for (intptr_t i = 0; i < 10; ++i) { | 823 for (intptr_t i = 0; i < 10; ++i) { |
828 // Get through the List API. | 824 // Get through the List API. |
829 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 825 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
830 EXPECT_VALID(integer_obj); | 826 EXPECT_VALID(integer_obj); |
831 int64_t int64_t_value = -1; | 827 int64_t int64_t_value = -1; |
832 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 828 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
833 EXPECT_EQ(i + 1, int64_t_value); | 829 EXPECT_EQ(i + 1, int64_t_value); |
834 // Get through the ByteArray API. | |
835 uint8_t uint8_t_value = 0xFF; | |
836 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
837 EXPECT_EQ(i + 1, uint8_t_value); | |
838 } | |
839 | |
840 // Set through the ByteArray API. | |
841 for (intptr_t i = 0; i < 10; ++i) { | |
842 EXPECT_VALID(Dart_ByteArraySetUint8At(byte_array1, i, i + 2)); | |
843 } | |
844 for (intptr_t i = 0; i < 10; ++i) { | |
845 // Get through the List API. | |
846 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | |
847 EXPECT_VALID(integer_obj); | |
848 int64_t int64_t_value = -1; | |
849 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | |
850 EXPECT_EQ(i + 2, int64_t_value); | |
851 // Get through the ByteArray API. | |
852 uint8_t uint8_t_value = 0xFF; | |
853 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
854 EXPECT_EQ(i + 2, uint8_t_value); | |
855 } | 830 } |
856 | 831 |
857 Dart_Handle byte_array2 = Dart_NewByteArray(10); | 832 Dart_Handle byte_array2 = Dart_NewByteArray(10); |
858 bool is_equal = false; | 833 bool is_equal = false; |
859 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); | 834 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); |
860 EXPECT(!is_equal); | 835 EXPECT(!is_equal); |
861 | 836 |
862 // Set through the List API. | 837 // Set through the List API. |
863 for (intptr_t i = 0; i < 10; ++i) { | 838 for (intptr_t i = 0; i < 10; ++i) { |
| 839 result = Dart_ListSetAt(byte_array1, i, Dart_NewInteger(i + 2)); |
| 840 EXPECT_VALID(result); |
864 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2)); | 841 result = Dart_ListSetAt(byte_array2, i, Dart_NewInteger(i + 2)); |
865 EXPECT_VALID(result); | 842 EXPECT_VALID(result); |
866 } | 843 } |
867 for (intptr_t i = 0; i < 10; ++i) { | 844 for (intptr_t i = 0; i < 10; ++i) { |
868 // Get through the List API. | 845 // Get through the List API. |
869 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); | 846 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); |
870 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); | 847 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); |
871 is_equal = false; | 848 is_equal = false; |
872 Dart_ObjectEquals(e1, e2, &is_equal); | 849 Dart_ObjectEquals(e1, e2, &is_equal); |
873 EXPECT(is_equal); | 850 EXPECT(is_equal); |
874 // Get through the ByteArray API. | |
875 uint8_t v1 = 0xFF; | |
876 uint8_t v2 = 0XFF; | |
877 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &v1)); | |
878 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array2, i, &v2)); | |
879 EXPECT_NE(v1, 0xFF); | |
880 EXPECT_NE(v2, 0xFF); | |
881 EXPECT_EQ(v1, v2); | |
882 } | |
883 | |
884 byte_array2 = Dart_NewByteArray(10); | |
885 is_equal = false; | |
886 Dart_ObjectEquals(byte_array1, byte_array2, &is_equal); | |
887 EXPECT(!is_equal); | |
888 | |
889 // Set through the ByteArray API. | |
890 for (intptr_t i = 0; i < 10; ++i) { | |
891 result = Dart_ByteArraySetUint8At(byte_array2, i, i + 2); | |
892 EXPECT_VALID(result); | |
893 } | |
894 for (intptr_t i = 0; i < 10; ++i) { | |
895 // Get through the List API. | |
896 Dart_Handle e1 = Dart_ListGetAt(byte_array1, i); | |
897 Dart_Handle e2 = Dart_ListGetAt(byte_array2, i); | |
898 is_equal = false; | |
899 Dart_ObjectEquals(e1, e2, &is_equal); | |
900 EXPECT(is_equal); | |
901 // Get through the ByteArray API. | |
902 uint8_t v1 = 0xFF; | |
903 uint8_t v2 = 0XFF; | |
904 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &v1)); | |
905 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array2, i, &v2)); | |
906 EXPECT_NE(v1, 0xFF); | |
907 EXPECT_NE(v2, 0xFF); | |
908 EXPECT_EQ(v1, v2); | |
909 } | 851 } |
910 | 852 |
911 uint8_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; | 853 uint8_t data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; |
912 result = Dart_ListSetAsBytes(byte_array1, 0, data, 10); | |
913 EXPECT_VALID(result); | |
914 for (intptr_t i = 0; i < 10; ++i) { | |
915 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | |
916 EXPECT_VALID(integer_obj); | |
917 int64_t int64_t_value = -1; | |
918 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | |
919 EXPECT_EQ(i, int64_t_value); | |
920 uint8_t uint8_t_value = 0xFF; | |
921 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
922 EXPECT_EQ(i, uint8_t_value); | |
923 } | |
924 | |
925 for (intptr_t i = 0; i < 10; ++i) { | 854 for (intptr_t i = 0; i < 10; ++i) { |
926 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); | 855 EXPECT_VALID(Dart_ListSetAt(byte_array1, i, Dart_NewInteger(10 - i))); |
927 } | 856 } |
928 Dart_ListGetAsBytes(byte_array1, 0, data, 10); | 857 Dart_ListGetAsBytes(byte_array1, 0, data, 10); |
929 for (intptr_t i = 0; i < 10; ++i) { | 858 for (intptr_t i = 0; i < 10; ++i) { |
930 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | 859 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); |
931 EXPECT_VALID(integer_obj); | 860 EXPECT_VALID(integer_obj); |
932 int64_t int64_t_value = -1; | 861 int64_t int64_t_value = -1; |
933 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | 862 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); |
934 EXPECT_EQ(10 - i, int64_t_value); | 863 EXPECT_EQ(10 - i, int64_t_value); |
935 uint8_t uint8_t_value = 0xFF; | |
936 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
937 EXPECT_EQ(10 - i, uint8_t_value); | |
938 } | |
939 | |
940 for (intptr_t i = 0; i < 10; ++i) { | |
941 EXPECT_VALID(Dart_ByteArraySetUint8At(byte_array1, i, 10 + i)); | |
942 } | |
943 Dart_ListGetAsBytes(byte_array1, 0, data, 10); | |
944 for (intptr_t i = 0; i < 10; ++i) { | |
945 Dart_Handle integer_obj = Dart_ListGetAt(byte_array1, i); | |
946 EXPECT_VALID(integer_obj); | |
947 int64_t int64_t_value = -1; | |
948 EXPECT_VALID(Dart_IntegerToInt64(integer_obj, &int64_t_value)); | |
949 EXPECT_EQ(10 + i, int64_t_value); | |
950 uint8_t uint8_t_value = 0xFF; | |
951 EXPECT_VALID(Dart_ByteArrayGetUint8At(byte_array1, i, &uint8_t_value)); | |
952 EXPECT_EQ(10 + i, uint8_t_value); | |
953 } | 864 } |
954 } | 865 } |
955 | 866 |
956 | 867 |
957 TEST_CASE(ByteArrayAlignedMultiByteAccess) { | 868 TEST_CASE(ScalarListDirectAccess) { |
958 intptr_t length = 16; | 869 Dart_Handle str = Dart_NewStringFromCString("junk"); |
959 Dart_Handle byte_array = Dart_NewByteArray(length); | 870 Dart_Handle byte_array = Dart_NewByteArray(10); |
960 intptr_t api_length = 0; | 871 EXPECT_VALID(byte_array); |
961 EXPECT_VALID(Dart_ListLength(byte_array, &api_length)); | 872 Dart_Handle result; |
962 EXPECT_EQ(length, api_length); | 873 result = Dart_ScalarListAcquireData(byte_array, NULL, NULL, NULL); |
| 874 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'type'" |
| 875 " to be non-null."); |
| 876 Dart_Scalar_Type type; |
| 877 result = Dart_ScalarListAcquireData(byte_array, &type, NULL, NULL); |
| 878 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'data'" |
| 879 " to be non-null."); |
| 880 void* data; |
| 881 result = Dart_ScalarListAcquireData(byte_array, &type, &data, NULL); |
| 882 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'len'" |
| 883 " to be non-null."); |
| 884 intptr_t len; |
| 885 result = Dart_ScalarListAcquireData(Dart_Null(), &type, &data, &len); |
| 886 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'array'" |
| 887 " to be non-null."); |
| 888 result = Dart_ScalarListAcquireData(str, &type, &data, &len); |
| 889 EXPECT_ERROR(result, "Dart_ScalarListAcquireData expects argument 'array'" |
| 890 " to be of type 'scalar list'."); |
963 | 891 |
964 // 4-byte aligned sets. | 892 result = Dart_ScalarListReleaseData(Dart_Null()); |
965 | 893 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" |
966 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 0, FLT_MIN)); | 894 " to be non-null."); |
967 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 4, FLT_MAX)); | 895 result = Dart_ScalarListReleaseData(str); |
968 | 896 EXPECT_ERROR(result, "Dart_ScalarListReleaseData expects argument 'array'" |
969 float float_value = 0.0f; | 897 " to be of type 'scalar list'."); |
970 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 0, &float_value)); | |
971 EXPECT_EQ(FLT_MIN, float_value); | |
972 | |
973 float_value = 0.0f; | |
974 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 4, &float_value)); | |
975 EXPECT_EQ(FLT_MAX, float_value); | |
976 | |
977 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 0, 0.0f)); | |
978 float_value = FLT_MAX; | |
979 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 0, &float_value)); | |
980 EXPECT_EQ(0.0f, float_value); | |
981 | |
982 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 4, 1.0f)); | |
983 float_value = FLT_MAX; | |
984 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 4, &float_value)); | |
985 EXPECT_EQ(1.0f, float_value); | |
986 | |
987 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 0, -1.0f)); | |
988 float_value = FLT_MAX; | |
989 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 0, &float_value)); | |
990 EXPECT_EQ(-1.0f, float_value); | |
991 | |
992 // 8-byte aligned sets. | |
993 | |
994 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 0, DBL_MIN)); | |
995 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 8, DBL_MAX)); | |
996 | |
997 double double_value = 0.0; | |
998 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 0, &double_value)); | |
999 EXPECT_EQ(DBL_MIN, double_value); | |
1000 | |
1001 double_value = 0.0; | |
1002 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 8, &double_value)); | |
1003 EXPECT_EQ(DBL_MAX, double_value); | |
1004 | |
1005 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 0, 0.0)); | |
1006 double_value = DBL_MAX; | |
1007 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 0, &double_value)); | |
1008 EXPECT_EQ(0.0, double_value); | |
1009 | |
1010 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 8, 1.0)); | |
1011 double_value = DBL_MAX; | |
1012 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 8, &double_value)); | |
1013 EXPECT_EQ(1.0, double_value); | |
1014 } | |
1015 | |
1016 | |
1017 TEST_CASE(ByteArrayMisalignedMultiByteAccess) { | |
1018 intptr_t length = 17; | |
1019 Dart_Handle byte_array = Dart_NewByteArray(length); | |
1020 intptr_t api_length = 0; | |
1021 EXPECT_VALID(Dart_ListLength(byte_array, &api_length)); | |
1022 EXPECT_EQ(length, api_length); | |
1023 | |
1024 // 4-byte misaligned sets. | |
1025 | |
1026 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 1, FLT_MIN)); | |
1027 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 5, FLT_MAX)); | |
1028 | |
1029 float float_value = 0.0f; | |
1030 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 1, &float_value)); | |
1031 EXPECT_EQ(FLT_MIN, float_value); | |
1032 | |
1033 float_value = 0.0f; | |
1034 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 5, &float_value)); | |
1035 EXPECT_EQ(FLT_MAX, float_value); | |
1036 | |
1037 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 1, 0.0f)); | |
1038 float_value = FLT_MAX; | |
1039 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 1, &float_value)); | |
1040 EXPECT_EQ(0.0f, float_value); | |
1041 | |
1042 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 5, -0.0f)); | |
1043 float_value = FLT_MAX; | |
1044 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 5, &float_value)); | |
1045 EXPECT_EQ(-0.0f, float_value); | |
1046 | |
1047 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 5, 1.0f)); | |
1048 float_value = FLT_MAX; | |
1049 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 5, &float_value)); | |
1050 EXPECT_EQ(1.0f, float_value); | |
1051 | |
1052 EXPECT_VALID(Dart_ByteArraySetFloat32At(byte_array, 1, -1.0f)); | |
1053 float_value = FLT_MAX; | |
1054 EXPECT_VALID(Dart_ByteArrayGetFloat32At(byte_array, 1, &float_value)); | |
1055 EXPECT_EQ(-1.0f, float_value); | |
1056 | |
1057 // 8-byte misaligned sets. | |
1058 | |
1059 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, DBL_MIN)); | |
1060 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 9, DBL_MAX)); | |
1061 | |
1062 double double_value = 0.0; | |
1063 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); | |
1064 EXPECT_EQ(DBL_MIN, double_value); | |
1065 | |
1066 double_value = 0.0; | |
1067 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); | |
1068 EXPECT_EQ(DBL_MAX, double_value); | |
1069 | |
1070 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, 0.0)); | |
1071 double_value = DBL_MAX; | |
1072 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); | |
1073 EXPECT_EQ(0.0, double_value); | |
1074 | |
1075 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 9, -0.0)); | |
1076 double_value = DBL_MAX; | |
1077 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); | |
1078 EXPECT_EQ(-0.0, double_value); | |
1079 | |
1080 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 9, 1.0)); | |
1081 double_value = DBL_MAX; | |
1082 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 9, &double_value)); | |
1083 EXPECT_EQ(1.0, double_value); | |
1084 | |
1085 EXPECT_VALID(Dart_ByteArraySetFloat64At(byte_array, 1, -1.0)); | |
1086 double_value = DBL_MAX; | |
1087 EXPECT_VALID(Dart_ByteArrayGetFloat64At(byte_array, 1, &double_value)); | |
1088 EXPECT_EQ(-1.0, double_value); | |
1089 } | 898 } |
1090 | 899 |
1091 | 900 |
1092 static void ExternalByteArrayAccessTests(Dart_Handle obj, | 901 static void ExternalByteArrayAccessTests(Dart_Handle obj, |
1093 uint8_t data[], | 902 uint8_t data[], |
1094 intptr_t data_length) { | 903 intptr_t data_length) { |
1095 EXPECT_VALID(obj); | 904 EXPECT_VALID(obj); |
1096 EXPECT(Dart_IsByteArray(obj)); | 905 EXPECT(Dart_IsByteArray(obj)); |
1097 EXPECT(Dart_IsByteArrayExternal(obj)); | 906 EXPECT(Dart_IsByteArrayExternal(obj)); |
1098 EXPECT(Dart_IsList(obj)); | 907 EXPECT(Dart_IsList(obj)); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 TestIsolateScope __test_isolate__; | 1046 TestIsolateScope __test_isolate__; |
1238 | 1047 |
1239 Isolate* isolate = Isolate::Current(); | 1048 Isolate* isolate = Isolate::Current(); |
1240 EXPECT(isolate != NULL); | 1049 EXPECT(isolate != NULL); |
1241 ApiState* state = isolate->api_state(); | 1050 ApiState* state = isolate->api_state(); |
1242 EXPECT(state != NULL); | 1051 EXPECT(state != NULL); |
1243 ApiLocalScope* scope = state->top_scope(); | 1052 ApiLocalScope* scope = state->top_scope(); |
1244 Dart_EnterScope(); | 1053 Dart_EnterScope(); |
1245 { | 1054 { |
1246 EXPECT(state->top_scope() != NULL); | 1055 EXPECT(state->top_scope() != NULL); |
1247 DARTSCOPE_NOCHECKS(isolate); | 1056 DARTSCOPE(isolate); |
1248 const String& str1 = String::Handle(String::New("Test String")); | 1057 const String& str1 = String::Handle(String::New("Test String")); |
1249 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); | 1058 Dart_Handle ref = Api::NewHandle(isolate, str1.raw()); |
1250 String& str2 = String::Handle(); | 1059 String& str2 = String::Handle(); |
1251 str2 ^= Api::UnwrapHandle(ref); | 1060 str2 ^= Api::UnwrapHandle(ref); |
1252 EXPECT(str1.Equals(str2)); | 1061 EXPECT(str1.Equals(str2)); |
1253 } | 1062 } |
1254 Dart_ExitScope(); | 1063 Dart_ExitScope(); |
1255 EXPECT(scope == state->top_scope()); | 1064 EXPECT(scope == state->top_scope()); |
1256 } | 1065 } |
1257 | 1066 |
1258 | 1067 |
1259 // Unit test for creating and deleting persistent handles. | 1068 // Unit test for creating and deleting persistent handles. |
1260 UNIT_TEST_CASE(PersistentHandles) { | 1069 UNIT_TEST_CASE(PersistentHandles) { |
1261 const char* kTestString1 = "Test String1"; | 1070 const char* kTestString1 = "Test String1"; |
1262 const char* kTestString2 = "Test String2"; | 1071 const char* kTestString2 = "Test String2"; |
1263 TestCase::CreateTestIsolate(); | 1072 TestCase::CreateTestIsolate(); |
1264 Isolate* isolate = Isolate::Current(); | 1073 Isolate* isolate = Isolate::Current(); |
1265 EXPECT(isolate != NULL); | 1074 EXPECT(isolate != NULL); |
1266 ApiState* state = isolate->api_state(); | 1075 ApiState* state = isolate->api_state(); |
1267 EXPECT(state != NULL); | 1076 EXPECT(state != NULL); |
1268 ApiLocalScope* scope = state->top_scope(); | 1077 ApiLocalScope* scope = state->top_scope(); |
1269 Dart_Handle handles[2000]; | 1078 Dart_Handle handles[2000]; |
1270 Dart_EnterScope(); | 1079 Dart_EnterScope(); |
1271 { | 1080 { |
1272 DARTSCOPE_NOCHECKS(isolate); | 1081 DARTSCOPE(isolate); |
1273 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); | 1082 Dart_Handle ref1 = Api::NewHandle(isolate, String::New(kTestString1)); |
1274 for (int i = 0; i < 1000; i++) { | 1083 for (int i = 0; i < 1000; i++) { |
1275 handles[i] = Dart_NewPersistentHandle(ref1); | 1084 handles[i] = Dart_NewPersistentHandle(ref1); |
1276 } | 1085 } |
1277 Dart_EnterScope(); | 1086 Dart_EnterScope(); |
1278 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); | 1087 Dart_Handle ref2 = Api::NewHandle(isolate, String::New(kTestString2)); |
1279 for (int i = 1000; i < 2000; i++) { | 1088 for (int i = 1000; i < 2000; i++) { |
1280 handles[i] = Dart_NewPersistentHandle(ref2); | 1089 handles[i] = Dart_NewPersistentHandle(ref2); |
1281 } | 1090 } |
1282 for (int i = 500; i < 1500; i++) { | 1091 for (int i = 500; i < 1500; i++) { |
1283 Dart_DeletePersistentHandle(handles[i]); | 1092 Dart_DeletePersistentHandle(handles[i]); |
1284 } | 1093 } |
1285 for (int i = 500; i < 1000; i++) { | 1094 for (int i = 500; i < 1000; i++) { |
1286 handles[i] = Dart_NewPersistentHandle(ref2); | 1095 handles[i] = Dart_NewPersistentHandle(ref2); |
1287 } | 1096 } |
1288 for (int i = 1000; i < 1500; i++) { | 1097 for (int i = 1000; i < 1500; i++) { |
1289 handles[i] = Dart_NewPersistentHandle(ref1); | 1098 handles[i] = Dart_NewPersistentHandle(ref1); |
1290 } | 1099 } |
1291 VERIFY_ON_TRANSITION; | 1100 VERIFY_ON_TRANSITION; |
1292 Dart_ExitScope(); | 1101 Dart_ExitScope(); |
1293 } | 1102 } |
1294 Dart_ExitScope(); | 1103 Dart_ExitScope(); |
1295 { | 1104 { |
1296 StackZone zone(isolate); | 1105 StackZone zone(isolate); |
1297 DARTSCOPE_NOCHECKS(isolate); | 1106 HANDLESCOPE(isolate); |
1298 for (int i = 0; i < 500; i++) { | 1107 for (int i = 0; i < 500; i++) { |
1299 String& str = String::Handle(); | 1108 String& str = String::Handle(); |
1300 str ^= Api::UnwrapHandle(handles[i]); | 1109 str ^= Api::UnwrapHandle(handles[i]); |
1301 EXPECT(str.Equals(kTestString1)); | 1110 EXPECT(str.Equals(kTestString1)); |
1302 } | 1111 } |
1303 for (int i = 500; i < 1000; i++) { | 1112 for (int i = 500; i < 1000; i++) { |
1304 String& str = String::Handle(); | 1113 String& str = String::Handle(); |
1305 str ^= Api::UnwrapHandle(handles[i]); | 1114 str ^= Api::UnwrapHandle(handles[i]); |
1306 EXPECT(str.Equals(kTestString2)); | 1115 EXPECT(str.Equals(kTestString2)); |
1307 } | 1116 } |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 UNIT_TEST_CASE(LocalHandles) { | 2047 UNIT_TEST_CASE(LocalHandles) { |
2239 TestCase::CreateTestIsolate(); | 2048 TestCase::CreateTestIsolate(); |
2240 Isolate* isolate = Isolate::Current(); | 2049 Isolate* isolate = Isolate::Current(); |
2241 EXPECT(isolate != NULL); | 2050 EXPECT(isolate != NULL); |
2242 ApiState* state = isolate->api_state(); | 2051 ApiState* state = isolate->api_state(); |
2243 EXPECT(state != NULL); | 2052 EXPECT(state != NULL); |
2244 ApiLocalScope* scope = state->top_scope(); | 2053 ApiLocalScope* scope = state->top_scope(); |
2245 Dart_Handle handles[300]; | 2054 Dart_Handle handles[300]; |
2246 { | 2055 { |
2247 StackZone zone(isolate); | 2056 StackZone zone(isolate); |
2248 DARTSCOPE_NOCHECKS(isolate); | 2057 HANDLESCOPE(isolate); |
2249 Smi& val = Smi::Handle(); | 2058 Smi& val = Smi::Handle(); |
2250 | 2059 |
2251 // Start a new scope and allocate some local handles. | 2060 // Start a new scope and allocate some local handles. |
2252 Dart_EnterScope(); | 2061 Dart_EnterScope(); |
2253 for (int i = 0; i < 100; i++) { | 2062 for (int i = 0; i < 100; i++) { |
2254 handles[i] = Api::NewHandle(isolate, Smi::New(i)); | 2063 handles[i] = Api::NewHandle(isolate, Smi::New(i)); |
2255 } | 2064 } |
2256 EXPECT_EQ(100, state->CountLocalHandles()); | 2065 EXPECT_EQ(100, state->CountLocalHandles()); |
2257 for (int i = 0; i < 100; i++) { | 2066 for (int i = 0; i < 100; i++) { |
2258 val ^= Api::UnwrapHandle(handles[i]); | 2067 val ^= Api::UnwrapHandle(handles[i]); |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2898 result = Dart_CreateNativeWrapperClass( | 2707 result = Dart_CreateNativeWrapperClass( |
2899 lib, | 2708 lib, |
2900 NewString("NativeFieldsWrapper"), | 2709 NewString("NativeFieldsWrapper"), |
2901 kNumNativeFields); | 2710 kNumNativeFields); |
2902 | 2711 |
2903 // Load up a test script in the test library. | 2712 // Load up a test script in the test library. |
2904 | 2713 |
2905 // Invoke a function which returns an object of type NativeFields. | 2714 // Invoke a function which returns an object of type NativeFields. |
2906 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 2715 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
2907 EXPECT_VALID(result); | 2716 EXPECT_VALID(result); |
2908 DARTSCOPE_NOCHECKS(Isolate::Current()); | 2717 DARTSCOPE(Isolate::Current()); |
2909 Instance& obj = Instance::Handle(); | 2718 Instance& obj = Instance::Handle(); |
2910 obj ^= Api::UnwrapHandle(result); | 2719 obj ^= Api::UnwrapHandle(result); |
2911 const Class& cls = Class::Handle(obj.clazz()); | 2720 const Class& cls = Class::Handle(obj.clazz()); |
2912 // We expect the newly created "NativeFields" object to have | 2721 // We expect the newly created "NativeFields" object to have |
2913 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 2722 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
2914 // Hence the size of an instance of "NativeFields" should be | 2723 // Hence the size of an instance of "NativeFields" should be |
2915 // (1 + 2) * kWordSize + size of object header. | 2724 // (1 + 2) * kWordSize + size of object header. |
2916 // We check to make sure the instance size computed by the VM matches | 2725 // We check to make sure the instance size computed by the VM matches |
2917 // our expectations. | 2726 // our expectations. |
2918 intptr_t header_size = sizeof(RawObject); | 2727 intptr_t header_size = sizeof(RawObject); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2967 Dart_Handle result; | 2776 Dart_Handle result; |
2968 const int kNumNativeFields = 2; | 2777 const int kNumNativeFields = 2; |
2969 | 2778 |
2970 // Load up a test script in the test library. | 2779 // Load up a test script in the test library. |
2971 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, | 2780 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, |
2972 native_field_lookup); | 2781 native_field_lookup); |
2973 | 2782 |
2974 // Invoke a function which returns an object of type NativeFields. | 2783 // Invoke a function which returns an object of type NativeFields. |
2975 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); | 2784 result = Dart_Invoke(lib, NewString("testMain"), 0, NULL); |
2976 EXPECT_VALID(result); | 2785 EXPECT_VALID(result); |
2977 DARTSCOPE_NOCHECKS(Isolate::Current()); | 2786 DARTSCOPE(Isolate::Current()); |
2978 Instance& obj = Instance::Handle(); | 2787 Instance& obj = Instance::Handle(); |
2979 obj ^= Api::UnwrapHandle(result); | 2788 obj ^= Api::UnwrapHandle(result); |
2980 const Class& cls = Class::Handle(obj.clazz()); | 2789 const Class& cls = Class::Handle(obj.clazz()); |
2981 // We expect the newly created "NativeFields" object to have | 2790 // We expect the newly created "NativeFields" object to have |
2982 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. | 2791 // 2 dart instance fields (fld1, fld2) and a reference to the native fields. |
2983 // Hence the size of an instance of "NativeFields" should be | 2792 // Hence the size of an instance of "NativeFields" should be |
2984 // (1 + 2) * kWordSize + size of object header. | 2793 // (1 + 2) * kWordSize + size of object header. |
2985 // We check to make sure the instance size computed by the VM matches | 2794 // We check to make sure the instance size computed by the VM matches |
2986 // our expectations. | 2795 // our expectations. |
2987 intptr_t header_size = sizeof(RawObject); | 2796 intptr_t header_size = sizeof(RawObject); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3222 " static const int fld4 = 10;\n" | 3031 " static const int fld4 = 10;\n" |
3223 "}\n" | 3032 "}\n" |
3224 "NativeFields testMain1() {\n" | 3033 "NativeFields testMain1() {\n" |
3225 " NativeFields obj = new NativeFields(10, 20);\n" | 3034 " NativeFields obj = new NativeFields(10, 20);\n" |
3226 " return obj;\n" | 3035 " return obj;\n" |
3227 "}\n" | 3036 "}\n" |
3228 "Function testMain2() {\n" | 3037 "Function testMain2() {\n" |
3229 " return () {};\n" | 3038 " return () {};\n" |
3230 "}\n"; | 3039 "}\n"; |
3231 Dart_Handle result; | 3040 Dart_Handle result; |
3232 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3041 DARTSCOPE(Isolate::Current()); |
3233 | 3042 |
3234 // Create a test library and Load up a test script in it. | 3043 // Create a test library and Load up a test script in it. |
3235 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3044 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3236 | 3045 |
3237 // Invoke a function which returns an object of type NativeFields. | 3046 // Invoke a function which returns an object of type NativeFields. |
3238 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 3047 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
3239 EXPECT_VALID(retobj); | 3048 EXPECT_VALID(retobj); |
3240 | 3049 |
3241 // Now access and set various native instance fields of the returned object. | 3050 // Now access and set various native instance fields of the returned object. |
3242 // All of these tests are expected to return failure as there are no | 3051 // 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... |
3298 "}\n" | 3107 "}\n" |
3299 "main() {\n" | 3108 "main() {\n" |
3300 " var snd = spawnFunction(echo);\n" | 3109 " var snd = spawnFunction(echo);\n" |
3301 " var obj = new Test(1,2);\n" | 3110 " var obj = new Test(1,2);\n" |
3302 " snd.send(obj, port.toSendPort());\n" | 3111 " snd.send(obj, port.toSendPort());\n" |
3303 " port.receive((msg, reply) {\n" | 3112 " port.receive((msg, reply) {\n" |
3304 " print('from worker ${msg}');\n" | 3113 " print('from worker ${msg}');\n" |
3305 " });\n" | 3114 " });\n" |
3306 "}\n"; | 3115 "}\n"; |
3307 | 3116 |
3308 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3117 DARTSCOPE(Isolate::Current()); |
3309 | 3118 |
3310 // Create a test library and Load up a test script in it. | 3119 // Create a test library and Load up a test script in it. |
3311 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3120 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3312 | 3121 |
3313 // Invoke 'main' which should spawn an isolate and try to send an | 3122 // Invoke 'main' which should spawn an isolate and try to send an |
3314 // object with native fields over to the spawned isolate. This | 3123 // object with native fields over to the spawned isolate. This |
3315 // should result in an unhandled exception which is checked. | 3124 // should result in an unhandled exception which is checked. |
3316 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); | 3125 Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); |
3317 EXPECT(Dart_IsError(retobj)); | 3126 EXPECT(Dart_IsError(retobj)); |
3318 } | 3127 } |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3881 "}\n" | 3690 "}\n" |
3882 "Function getStaticClosure() {\n" | 3691 "Function getStaticClosure() {\n" |
3883 " return Foo.getStaticClosure();\n" | 3692 " return Foo.getStaticClosure();\n" |
3884 "}\n" | 3693 "}\n" |
3885 "Function getStaticClosureWithArgs() {\n" | 3694 "Function getStaticClosureWithArgs() {\n" |
3886 " return Foo.getStaticClosureWithArgs();\n" | 3695 " return Foo.getStaticClosureWithArgs();\n" |
3887 "}\n"; | 3696 "}\n"; |
3888 Dart_Handle result; | 3697 Dart_Handle result; |
3889 Dart_Handle owner; | 3698 Dart_Handle owner; |
3890 Dart_Handle defining_function; | 3699 Dart_Handle defining_function; |
3891 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3700 DARTSCOPE(Isolate::Current()); |
3892 | 3701 |
3893 // Create a test library and Load up a test script in it. | 3702 // Create a test library and Load up a test script in it. |
3894 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3703 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
3895 EXPECT_VALID(lib); | 3704 EXPECT_VALID(lib); |
3896 Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); | 3705 Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); |
3897 EXPECT_VALID(cls); | 3706 EXPECT_VALID(cls); |
3898 | 3707 |
3899 // Invoke a function which returns a closure. | 3708 // Invoke a function which returns a closure. |
3900 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); | 3709 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); |
3901 EXPECT_VALID(retobj); | 3710 EXPECT_VALID(retobj); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4049 " static const int fld4 = 10;\n" | 3858 " static const int fld4 = 10;\n" |
4050 "}\n" | 3859 "}\n" |
4051 "Function testMain1() {\n" | 3860 "Function testMain1() {\n" |
4052 " InvokeClosure obj = new InvokeClosure(10, 20);\n" | 3861 " InvokeClosure obj = new InvokeClosure(10, 20);\n" |
4053 " return obj.method1(10);\n" | 3862 " return obj.method1(10);\n" |
4054 "}\n" | 3863 "}\n" |
4055 "Function testMain2() {\n" | 3864 "Function testMain2() {\n" |
4056 " return InvokeClosure.method2(10);\n" | 3865 " return InvokeClosure.method2(10);\n" |
4057 "}\n"; | 3866 "}\n"; |
4058 Dart_Handle result; | 3867 Dart_Handle result; |
4059 DARTSCOPE_NOCHECKS(Isolate::Current()); | 3868 DARTSCOPE(Isolate::Current()); |
4060 | 3869 |
4061 // Create a test library and Load up a test script in it. | 3870 // Create a test library and Load up a test script in it. |
4062 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 3871 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
4063 | 3872 |
4064 // Invoke a function which returns a closure. | 3873 // Invoke a function which returns a closure. |
4065 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); | 3874 Dart_Handle retobj = Dart_Invoke(lib, NewString("testMain1"), 0, NULL); |
4066 EXPECT_VALID(retobj); | 3875 EXPECT_VALID(retobj); |
4067 | 3876 |
4068 EXPECT(Dart_IsClosure(retobj)); | 3877 EXPECT(Dart_IsClosure(retobj)); |
4069 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); | 3878 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
(...skipping 2842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6912 } | 6721 } |
6913 | 6722 |
6914 | 6723 |
6915 // Allocates an object in new space and assigns it a peer. Allows the | 6724 // Allocates an object in new space and assigns it a peer. Allows the |
6916 // peer referent to be garbage collected and checks that the count of | 6725 // peer referent to be garbage collected and checks that the count of |
6917 // peer objects is decremented by one. | 6726 // peer objects is decremented by one. |
6918 TEST_CASE(CollectOneNewSpacePeer) { | 6727 TEST_CASE(CollectOneNewSpacePeer) { |
6919 Isolate* isolate = Isolate::Current(); | 6728 Isolate* isolate = Isolate::Current(); |
6920 Dart_EnterScope(); | 6729 Dart_EnterScope(); |
6921 { | 6730 { |
6922 DARTSCOPE_NOCHECKS(isolate); | 6731 DARTSCOPE(isolate); |
6923 Dart_Handle str = NewString("a string"); | 6732 Dart_Handle str = NewString("a string"); |
6924 EXPECT_VALID(str); | 6733 EXPECT_VALID(str); |
6925 EXPECT(Dart_IsString(str)); | 6734 EXPECT(Dart_IsString(str)); |
6926 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6735 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
6927 void* out = &out; | 6736 void* out = &out; |
6928 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6737 EXPECT_VALID(Dart_GetPeer(str, &out)); |
6929 EXPECT(out == NULL); | 6738 EXPECT(out == NULL); |
6930 int peer = 1234; | 6739 int peer = 1234; |
6931 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6740 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
6932 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6741 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6985 } | 6794 } |
6986 | 6795 |
6987 | 6796 |
6988 // Allocates two objects in new space and assigns them a peer. Allow | 6797 // Allocates two objects in new space and assigns them a peer. Allow |
6989 // the peer referents to be garbage collected and check that the count | 6798 // the peer referents to be garbage collected and check that the count |
6990 // of peer objects is decremented by two. | 6799 // of peer objects is decremented by two. |
6991 TEST_CASE(CollectTwoNewSpacePeers) { | 6800 TEST_CASE(CollectTwoNewSpacePeers) { |
6992 Isolate* isolate = Isolate::Current(); | 6801 Isolate* isolate = Isolate::Current(); |
6993 Dart_EnterScope(); | 6802 Dart_EnterScope(); |
6994 { | 6803 { |
6995 DARTSCOPE_NOCHECKS(isolate); | 6804 DARTSCOPE(isolate); |
6996 Dart_Handle s1 = NewString("s1"); | 6805 Dart_Handle s1 = NewString("s1"); |
6997 EXPECT_VALID(s1); | 6806 EXPECT_VALID(s1); |
6998 EXPECT(Dart_IsString(s1)); | 6807 EXPECT(Dart_IsString(s1)); |
6999 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6808 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7000 void* o1 = &o1; | 6809 void* o1 = &o1; |
7001 EXPECT(Dart_GetPeer(s1, &o1)); | 6810 EXPECT(Dart_GetPeer(s1, &o1)); |
7002 EXPECT(o1 == NULL); | 6811 EXPECT(o1 == NULL); |
7003 int p1 = 1234; | 6812 int p1 = 1234; |
7004 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 6813 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
7005 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6814 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7069 EXPECT(out == NULL); | 6878 EXPECT(out == NULL); |
7070 int peer = 1234; | 6879 int peer = 1234; |
7071 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6880 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7072 out = &out; | 6881 out = &out; |
7073 EXPECT(Dart_GetPeer(str, &out)); | 6882 EXPECT(Dart_GetPeer(str, &out)); |
7074 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6883 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7075 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6884 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7076 isolate->heap()->CollectGarbage(Heap::kNew); | 6885 isolate->heap()->CollectGarbage(Heap::kNew); |
7077 isolate->heap()->CollectGarbage(Heap::kNew); | 6886 isolate->heap()->CollectGarbage(Heap::kNew); |
7078 { | 6887 { |
7079 DARTSCOPE_NOCHECKS(isolate); | 6888 DARTSCOPE(isolate); |
7080 String& handle = String::Handle(); | 6889 String& handle = String::Handle(); |
7081 handle ^= Api::UnwrapHandle(str); | 6890 handle ^= Api::UnwrapHandle(str); |
7082 EXPECT(handle.IsOld()); | 6891 EXPECT(handle.IsOld()); |
7083 } | 6892 } |
7084 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6893 EXPECT_VALID(Dart_GetPeer(str, &out)); |
7085 EXPECT(out == reinterpret_cast<void*>(&peer)); | 6894 EXPECT(out == reinterpret_cast<void*>(&peer)); |
7086 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6895 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
7087 EXPECT_VALID(Dart_SetPeer(str, NULL)); | 6896 EXPECT_VALID(Dart_SetPeer(str, NULL)); |
7088 out = &out; | 6897 out = &out; |
7089 EXPECT_VALID(Dart_GetPeer(str, &out)); | 6898 EXPECT_VALID(Dart_GetPeer(str, &out)); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7122 } | 6931 } |
7123 | 6932 |
7124 | 6933 |
7125 // Allocates an object in old space and assigns it a peer. Allow the | 6934 // Allocates an object in old space and assigns it a peer. Allow the |
7126 // peer referent to be garbage collected and check that the count of | 6935 // peer referent to be garbage collected and check that the count of |
7127 // peer objects is decremented by one. | 6936 // peer objects is decremented by one. |
7128 TEST_CASE(CollectOneOldSpacePeer) { | 6937 TEST_CASE(CollectOneOldSpacePeer) { |
7129 Isolate* isolate = Isolate::Current(); | 6938 Isolate* isolate = Isolate::Current(); |
7130 Dart_EnterScope(); | 6939 Dart_EnterScope(); |
7131 { | 6940 { |
7132 DARTSCOPE_NOCHECKS(isolate); | 6941 DARTSCOPE(isolate); |
7133 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); | 6942 Dart_Handle str = Api::NewHandle(isolate, String::New("str", Heap::kOld)); |
7134 EXPECT_VALID(str); | 6943 EXPECT_VALID(str); |
7135 EXPECT(Dart_IsString(str)); | 6944 EXPECT(Dart_IsString(str)); |
7136 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 6945 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7137 void* out = &out; | 6946 void* out = &out; |
7138 EXPECT(Dart_GetPeer(str, &out)); | 6947 EXPECT(Dart_GetPeer(str, &out)); |
7139 EXPECT(out == NULL); | 6948 EXPECT(out == NULL); |
7140 int peer = 1234; | 6949 int peer = 1234; |
7141 EXPECT_VALID(Dart_SetPeer(str, &peer)); | 6950 EXPECT_VALID(Dart_SetPeer(str, &peer)); |
7142 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 6951 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7198 } | 7007 } |
7199 | 7008 |
7200 | 7009 |
7201 // Allocates two objects in old space and assigns them a peer. Allows | 7010 // Allocates two objects in old space and assigns them a peer. Allows |
7202 // the peer referents to be garbage collected and checks that the | 7011 // the peer referents to be garbage collected and checks that the |
7203 // count of peer objects is decremented by two. | 7012 // count of peer objects is decremented by two. |
7204 TEST_CASE(CollectTwoOldSpacePeers) { | 7013 TEST_CASE(CollectTwoOldSpacePeers) { |
7205 Isolate* isolate = Isolate::Current(); | 7014 Isolate* isolate = Isolate::Current(); |
7206 Dart_EnterScope(); | 7015 Dart_EnterScope(); |
7207 { | 7016 { |
7208 DARTSCOPE_NOCHECKS(isolate); | 7017 DARTSCOPE(isolate); |
7209 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); | 7018 Dart_Handle s1 = Api::NewHandle(isolate, String::New("s1", Heap::kOld)); |
7210 EXPECT_VALID(s1); | 7019 EXPECT_VALID(s1); |
7211 EXPECT(Dart_IsString(s1)); | 7020 EXPECT(Dart_IsString(s1)); |
7212 EXPECT_EQ(0, isolate->heap()->PeerCount()); | 7021 EXPECT_EQ(0, isolate->heap()->PeerCount()); |
7213 void* o1 = &o1; | 7022 void* o1 = &o1; |
7214 EXPECT(Dart_GetPeer(s1, &o1)); | 7023 EXPECT(Dart_GetPeer(s1, &o1)); |
7215 EXPECT(o1 == NULL); | 7024 EXPECT(o1 == NULL); |
7216 int p1 = 1234; | 7025 int p1 = 1234; |
7217 EXPECT_VALID(Dart_SetPeer(s1, &p1)); | 7026 EXPECT_VALID(Dart_SetPeer(s1, &p1)); |
7218 EXPECT_EQ(1, isolate->heap()->PeerCount()); | 7027 EXPECT_EQ(1, isolate->heap()->PeerCount()); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7512 NULL); | 7321 NULL); |
7513 int64_t value = 0; | 7322 int64_t value = 0; |
7514 result = Dart_IntegerToInt64(result, &value); | 7323 result = Dart_IntegerToInt64(result, &value); |
7515 EXPECT_VALID(result); | 7324 EXPECT_VALID(result); |
7516 EXPECT_EQ(260, value); | 7325 EXPECT_EQ(260, value); |
7517 } | 7326 } |
7518 | 7327 |
7519 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7328 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7520 | 7329 |
7521 } // namespace dart | 7330 } // namespace dart |
OLD | NEW |