Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 2977143002: Revert "Option to truncate integers to 64 bits, part 2" (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/dart_api_impl.h" 5 #include "vm/dart_api_impl.h"
6 #include "bin/builtin.h" 6 #include "bin/builtin.h"
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "include/dart_tools_api.h" 10 #include "include/dart_tools_api.h"
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 EXPECT_VALID(result); 837 EXPECT_VALID(result);
838 EXPECT(fits); 838 EXPECT(fits);
839 839
840 Dart_Handle val2 = Dart_NewInteger(kIntegerVal2); 840 Dart_Handle val2 = Dart_NewInteger(kIntegerVal2);
841 EXPECT(Dart_IsInteger(val2)); 841 EXPECT(Dart_IsInteger(val2));
842 result = Dart_IntegerFitsIntoInt64(val2, &fits); 842 result = Dart_IntegerFitsIntoInt64(val2, &fits);
843 EXPECT_VALID(result); 843 EXPECT_VALID(result);
844 EXPECT(fits); 844 EXPECT(fits);
845 845
846 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3); 846 Dart_Handle val3 = Dart_NewIntegerFromHexCString(kIntegerVal3);
847 if (FLAG_limit_ints_to_64_bits) { 847 EXPECT(Dart_IsInteger(val3));
848 EXPECT(Dart_IsApiError(val3)); 848 result = Dart_IntegerFitsIntoInt64(val3, &fits);
849 } else { 849 EXPECT_VALID(result);
850 EXPECT(Dart_IsInteger(val3)); 850 EXPECT(!fits);
851 result = Dart_IntegerFitsIntoInt64(val3, &fits);
852 EXPECT_VALID(result);
853 EXPECT(!fits);
854 }
855 851
856 int64_t out = 0; 852 int64_t out = 0;
857 result = Dart_IntegerToInt64(val1, &out); 853 result = Dart_IntegerToInt64(val1, &out);
858 EXPECT_VALID(result); 854 EXPECT_VALID(result);
859 EXPECT_EQ(kIntegerVal1, out); 855 EXPECT_EQ(kIntegerVal1, out);
860 856
861 result = Dart_IntegerToInt64(val2, &out); 857 result = Dart_IntegerToInt64(val2, &out);
862 EXPECT_VALID(result); 858 EXPECT_VALID(result);
863 EXPECT_EQ(kIntegerVal2, out); 859 EXPECT_EQ(kIntegerVal2, out);
864 860
865 const char* chars = NULL; 861 const char* chars = NULL;
866 result = Dart_IntegerToHexCString(val3, &chars); 862 result = Dart_IntegerToHexCString(val3, &chars);
867 EXPECT_VALID(result); 863 EXPECT_VALID(result);
868 EXPECT(!strcmp(kIntegerVal3, chars)); 864 EXPECT(!strcmp(kIntegerVal3, chars));
869 865
870 Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4); 866 Dart_Handle val4 = Dart_NewIntegerFromUint64(kIntegerVal4);
871 if (FLAG_limit_ints_to_64_bits) { 867 EXPECT_VALID(val4);
872 EXPECT(Dart_IsApiError(val4)); 868 uint64_t out4 = 0;
873 } else { 869 result = Dart_IntegerToUint64(val4, &out4);
874 EXPECT_VALID(val4); 870 EXPECT_VALID(result);
875 uint64_t out4 = 0; 871 EXPECT_EQ(kIntegerVal4, out4);
876 result = Dart_IntegerToUint64(val4, &out4);
877 EXPECT_VALID(result);
878 EXPECT_EQ(kIntegerVal4, out4);
879 }
880 872
881 Dart_Handle val5 = Dart_NewInteger(-1); 873 Dart_Handle val5 = Dart_NewInteger(-1);
882 EXPECT_VALID(val5); 874 EXPECT_VALID(val5);
883 uint64_t out5 = 0; 875 uint64_t out5 = 0;
884 result = Dart_IntegerToUint64(val5, &out5); 876 result = Dart_IntegerToUint64(val5, &out5);
885 EXPECT(Dart_IsError(result)); 877 EXPECT(Dart_IsError(result));
886 878
887 Dart_Handle val6 = Dart_NewInteger(kIntegerVal5); 879 Dart_Handle val6 = Dart_NewInteger(kIntegerVal5);
888 EXPECT_VALID(val6); 880 EXPECT_VALID(val6);
889 uint64_t out6 = 0; 881 uint64_t out6 = 0;
890 result = Dart_IntegerToUint64(val6, &out6); 882 result = Dart_IntegerToUint64(val6, &out6);
891 EXPECT(Dart_IsError(result)); 883 EXPECT(Dart_IsError(result));
892 } 884 }
893 885
894 TEST_CASE(IntegerFitsIntoInt64) { 886 TEST_CASE(IntegerFitsIntoInt64) {
895 Dart_Handle max = Dart_NewInteger(kMaxInt64); 887 Dart_Handle max = Dart_NewInteger(kMaxInt64);
896 EXPECT(Dart_IsInteger(max)); 888 EXPECT(Dart_IsInteger(max));
897 bool fits = false; 889 bool fits = false;
898 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); 890 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits);
899 EXPECT_VALID(result); 891 EXPECT_VALID(result);
900 EXPECT(fits); 892 EXPECT(fits);
901 893
902 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); 894 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000");
903 if (FLAG_limit_ints_to_64_bits) { 895 EXPECT(Dart_IsInteger(above_max));
904 EXPECT(Dart_IsApiError(above_max)); 896 fits = true;
905 } else { 897 result = Dart_IntegerFitsIntoInt64(above_max, &fits);
906 EXPECT(Dart_IsInteger(above_max)); 898 EXPECT_VALID(result);
907 fits = true; 899 EXPECT(!fits);
908 result = Dart_IntegerFitsIntoInt64(above_max, &fits);
909 EXPECT_VALID(result);
910 EXPECT(!fits);
911 }
912 900
913 Dart_Handle min = Dart_NewInteger(kMinInt64); 901 Dart_Handle min = Dart_NewInteger(kMinInt64);
914 EXPECT(Dart_IsInteger(min)); 902 EXPECT(Dart_IsInteger(min));
915 fits = false; 903 fits = false;
916 result = Dart_IntegerFitsIntoInt64(min, &fits); 904 result = Dart_IntegerFitsIntoInt64(min, &fits);
917 EXPECT_VALID(result); 905 EXPECT_VALID(result);
918 EXPECT(fits); 906 EXPECT(fits);
919 907
920 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001"); 908 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001");
921 if (FLAG_limit_ints_to_64_bits) { 909 EXPECT(Dart_IsInteger(below_min));
922 EXPECT(Dart_IsApiError(below_min)); 910 fits = true;
923 } else { 911 result = Dart_IntegerFitsIntoInt64(below_min, &fits);
924 EXPECT(Dart_IsInteger(below_min)); 912 EXPECT_VALID(result);
925 fits = true; 913 EXPECT(!fits);
926 result = Dart_IntegerFitsIntoInt64(below_min, &fits);
927 EXPECT_VALID(result);
928 EXPECT(!fits);
929 }
930 } 914 }
931 915
932 TEST_CASE(IntegerFitsIntoUint64) { 916 TEST_CASE(IntegerFitsIntoUint64) {
933 Dart_Handle max = Dart_NewIntegerFromUint64(kMaxUint64); 917 Dart_Handle max = Dart_NewIntegerFromUint64(kMaxUint64);
934 if (FLAG_limit_ints_to_64_bits) { 918 EXPECT(Dart_IsInteger(max));
935 EXPECT(Dart_IsApiError(max)); 919 bool fits = false;
936 } else { 920 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits);
937 EXPECT(Dart_IsInteger(max)); 921 EXPECT_VALID(result);
938 bool fits = false; 922 EXPECT(fits);
939 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits);
940 EXPECT_VALID(result);
941 EXPECT(fits);
942 }
943 923
944 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000"); 924 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000");
945 if (FLAG_limit_ints_to_64_bits) { 925 EXPECT(Dart_IsInteger(above_max));
946 EXPECT(Dart_IsApiError(above_max)); 926 fits = true;
947 } else { 927 result = Dart_IntegerFitsIntoUint64(above_max, &fits);
948 EXPECT(Dart_IsInteger(above_max)); 928 EXPECT_VALID(result);
949 bool fits = true; 929 EXPECT(!fits);
950 Dart_Handle result = Dart_IntegerFitsIntoUint64(above_max, &fits);
951 EXPECT_VALID(result);
952 EXPECT(!fits);
953 }
954 930
955 Dart_Handle min = Dart_NewInteger(0); 931 Dart_Handle min = Dart_NewInteger(0);
956 EXPECT(Dart_IsInteger(min)); 932 EXPECT(Dart_IsInteger(min));
957 bool fits = false; 933 fits = false;
958 Dart_Handle result = Dart_IntegerFitsIntoUint64(min, &fits); 934 result = Dart_IntegerFitsIntoUint64(min, &fits);
959 EXPECT_VALID(result); 935 EXPECT_VALID(result);
960 EXPECT(fits); 936 EXPECT(fits);
961 937
962 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-1"); 938 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-1");
963 EXPECT(Dart_IsInteger(below_min)); 939 EXPECT(Dart_IsInteger(below_min));
964 fits = true; 940 fits = true;
965 result = Dart_IntegerFitsIntoUint64(below_min, &fits); 941 result = Dart_IntegerFitsIntoUint64(below_min, &fits);
966 EXPECT_VALID(result); 942 EXPECT_VALID(result);
967 EXPECT(!fits); 943 EXPECT(!fits);
968 } 944 }
(...skipping 6884 matching lines...) Expand 10 before | Expand all | Expand 10 after
7853 EXPECT(Dart_IsError(Dart_GetPeer(Dart_False(), &out))); 7829 EXPECT(Dart_IsError(Dart_GetPeer(Dart_False(), &out)));
7854 EXPECT(out == &out); 7830 EXPECT(out == &out);
7855 EXPECT(Dart_IsError(Dart_SetPeer(Dart_False(), &out))); 7831 EXPECT(Dart_IsError(Dart_SetPeer(Dart_False(), &out)));
7856 out = &out; 7832 out = &out;
7857 Dart_Handle smi = Dart_NewInteger(0); 7833 Dart_Handle smi = Dart_NewInteger(0);
7858 EXPECT(Dart_IsError(Dart_GetPeer(smi, &out))); 7834 EXPECT(Dart_IsError(Dart_GetPeer(smi, &out)));
7859 EXPECT(out == &out); 7835 EXPECT(out == &out);
7860 EXPECT(Dart_IsError(Dart_SetPeer(smi, &out))); 7836 EXPECT(Dart_IsError(Dart_SetPeer(smi, &out)));
7861 out = &out; 7837 out = &out;
7862 Dart_Handle big = Dart_NewIntegerFromHexCString("0x10000000000000000"); 7838 Dart_Handle big = Dart_NewIntegerFromHexCString("0x10000000000000000");
7863 if (FLAG_limit_ints_to_64_bits) { 7839 EXPECT(Dart_IsError(Dart_GetPeer(big, &out)));
7864 EXPECT(Dart_IsApiError(big)); 7840 EXPECT(out == &out);
7865 } else { 7841 EXPECT(Dart_IsError(Dart_SetPeer(big, &out)));
7866 EXPECT(Dart_IsError(Dart_GetPeer(big, &out)));
7867 EXPECT(out == &out);
7868 EXPECT(Dart_IsError(Dart_SetPeer(big, &out)));
7869 }
7870 out = &out;
7871 Dart_Handle dbl = Dart_NewDouble(0.0); 7842 Dart_Handle dbl = Dart_NewDouble(0.0);
7872 EXPECT(Dart_IsError(Dart_GetPeer(dbl, &out))); 7843 EXPECT(Dart_IsError(Dart_GetPeer(dbl, &out)));
7873 EXPECT(out == &out); 7844 EXPECT(out == &out);
7874 EXPECT(Dart_IsError(Dart_SetPeer(dbl, &out))); 7845 EXPECT(Dart_IsError(Dart_SetPeer(dbl, &out)));
7875 } 7846 }
7876 7847
7877 // Allocates an object in new space and assigns it a peer. Removes 7848 // Allocates an object in new space and assigns it a peer. Removes
7878 // the peer and checks that the count of peer objects is decremented 7849 // the peer and checks that the count of peer objects is decremented
7879 // by one. 7850 // by one.
7880 TEST_CASE(OneNewSpacePeer) { 7851 TEST_CASE(OneNewSpacePeer) {
(...skipping 1742 matching lines...) Expand 10 before | Expand all | Expand 10 after
9623 EXPECT_VALID(result); 9594 EXPECT_VALID(result);
9624 result = Dart_FinalizeLoading(false); 9595 result = Dart_FinalizeLoading(false);
9625 EXPECT_VALID(result); 9596 EXPECT_VALID(result);
9626 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL); 9597 result = Dart_Invoke(lib, NewString("foozoo"), 0, NULL);
9627 EXPECT(Dart_IsError(result)); 9598 EXPECT(Dart_IsError(result));
9628 } 9599 }
9629 9600
9630 #endif // !PRODUCT 9601 #endif // !PRODUCT
9631 9602
9632 } // namespace dart 9603 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698