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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_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 "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 8825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8836 NewString("main"), | 8836 NewString("main"), |
8837 0, | 8837 0, |
8838 NULL); | 8838 NULL); |
8839 int64_t value = 0; | 8839 int64_t value = 0; |
8840 result = Dart_IntegerToInt64(result, &value); | 8840 result = Dart_IntegerToInt64(result, &value); |
8841 EXPECT_VALID(result); | 8841 EXPECT_VALID(result); |
8842 EXPECT_EQ(260, value); | 8842 EXPECT_EQ(260, value); |
8843 } | 8843 } |
8844 | 8844 |
8845 | 8845 |
8846 TEST_CASE(ExternalStringPolymorphicDeoptimize) { | |
8847 const char* kScriptChars = | |
8848 "const strA = 'AAAA';\n" | |
8849 "class A {\n" | |
8850 " static change_str(String s) native 'A_change_str';\n" | |
8851 "}\n" | |
8852 "compare(a, b, [i = 0]) {\n" | |
8853 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" | |
8854 "}\n" | |
8855 "compareA(b, [i = 0]) {\n" | |
8856 " return compare(strA, b, i);\n" | |
8857 "}\n" | |
8858 "main() {\n" | |
8859 " var externalA = 'AA' + 'AA';\n" | |
8860 " A.change_str(externalA);\n" | |
8861 " compare('AA' + 'AA', strA);\n" | |
8862 " compare(externalA, strA);\n" | |
8863 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | |
8864 " A.change_str(strA);\n" | |
8865 " return compareA('AA' + 'AA');\n" | |
8866 "}\n"; | |
8867 Dart_Handle lib = | |
8868 TestCase::LoadTestScript(kScriptChars, | |
8869 &ExternalStringDeoptimize_native_lookup); | |
8870 Dart_Handle result = Dart_Invoke(lib, | |
8871 NewString("main"), | |
8872 0, | |
8873 NULL); | |
8874 EXPECT_VALID(result); | |
8875 bool value = false; | |
8876 result = Dart_BooleanValue(result, &value); | |
8877 EXPECT_VALID(result); | |
8878 EXPECT(value); | |
8879 } | |
8880 | |
8881 | |
8882 TEST_CASE(ExternalStringGuardFieldDeoptimize) { | |
8883 const char* kScriptChars = | |
8884 "const strA = 'AAAA';\n" | |
8885 "class A {\n" | |
8886 " static change_str(String s) native 'A_change_str';\n" | |
8887 "}\n" | |
8888 "class G { var f = 'A'; }\n" | |
8889 "final guard = new G();\n" | |
8890 "var shouldExternalize = false;\n" | |
8891 "ext() { if (shouldExternalize) A.change_str(strA); }\n" | |
8892 "compare(a, b, [i = 0]) {\n" | |
8893 " guard.f = a;\n" | |
8894 " ext();" | |
8895 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" | |
8896 "}\n" | |
8897 "compareA(b, [i = 0]) {\n" | |
8898 " return compare(strA, b, i);\n" | |
8899 "}\n" | |
8900 "main() {\n" | |
8901 " var externalA = 'AA' + 'AA';\n" | |
8902 " A.change_str(externalA);\n" | |
8903 " compare('AA' + 'AA', strA);\n" | |
8904 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | |
8905 " shouldExternalize = true;\n" | |
8906 " return compareA('AA' + 'AA');\n" | |
8907 "}\n"; | |
8908 Dart_Handle lib = | |
8909 TestCase::LoadTestScript(kScriptChars, | |
8910 &ExternalStringDeoptimize_native_lookup); | |
8911 Dart_Handle result = Dart_Invoke(lib, | |
8912 NewString("main"), | |
8913 0, | |
8914 NULL); | |
8915 EXPECT_VALID(result); | |
8916 bool value = false; | |
8917 result = Dart_BooleanValue(result, &value); | |
8918 EXPECT_VALID(result); | |
8919 EXPECT(value); | |
8920 } | |
8921 | |
8922 | |
8923 TEST_CASE(ExternalStringStaticFieldDeoptimize) { | |
8924 const char* kScriptChars = | |
8925 "const strA = 'AAAA';\n" | |
8926 "class A {\n" | |
8927 " static change_str(String s) native 'A_change_str';\n" | |
8928 "}\n" | |
8929 "class G { static final f = strA; }\n" | |
8930 "compare(a, b, [i = 0]) {\n" | |
8931 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" | |
8932 "}\n" | |
8933 "compareA(b, [i = 0]) {\n" | |
8934 " return compare(G.f, b, i);\n" | |
8935 "}\n" | |
8936 "main() {\n" | |
8937 " var externalA = 'AA' + 'AA';\n" | |
8938 " A.change_str(externalA);\n" | |
8939 " compare('AA' + 'AA', strA);\n" | |
8940 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | |
8941 " A.change_str(G.f);" | |
8942 " return compareA('AA' + 'AA');\n" | |
8943 "}\n"; | |
8944 Dart_Handle lib = | |
8945 TestCase::LoadTestScript(kScriptChars, | |
8946 &ExternalStringDeoptimize_native_lookup); | |
8947 Dart_Handle result = Dart_Invoke(lib, | |
8948 NewString("main"), | |
8949 0, | |
8950 NULL); | |
8951 EXPECT_VALID(result); | |
8952 bool value = false; | |
8953 result = Dart_BooleanValue(result, &value); | |
8954 EXPECT_VALID(result); | |
8955 EXPECT(value); | |
8956 } | |
8957 | |
8958 | |
8959 TEST_CASE(ExternalStringTrimDoubleParse) { | 8846 TEST_CASE(ExternalStringTrimDoubleParse) { |
8960 const char* kScriptChars = | 8847 const char* kScriptChars = |
8961 "String str = 'A';\n" | 8848 "String str = 'A';\n" |
8962 "class A {\n" | 8849 "class A {\n" |
8963 " static change_str(String s) native 'A_change_str';\n" | 8850 " static change_str(String s) native 'A_change_str';\n" |
8964 "}\n" | 8851 "}\n" |
8965 "main() {\n" | 8852 "main() {\n" |
8966 " var externalOneByteString = ' 0.2\\xA0 ';\n;" | 8853 " var externalOneByteString = ' 0.2\\xA0 ';\n;" |
8967 " A.change_str(externalOneByteString);\n" | 8854 " A.change_str(externalOneByteString);\n" |
8968 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" | 8855 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9132 result = Dart_Invoke(lib, | 9019 result = Dart_Invoke(lib, |
9133 NewString("testView16"), | 9020 NewString("testView16"), |
9134 1, | 9021 1, |
9135 dart_args); | 9022 dart_args); |
9136 EXPECT_VALID(result); | 9023 EXPECT_VALID(result); |
9137 EXPECT(Dart_IsString(result)); | 9024 EXPECT(Dart_IsString(result)); |
9138 } | 9025 } |
9139 } | 9026 } |
9140 | 9027 |
9141 } // namespace dart | 9028 } // namespace dart |
OLD | NEW |