Chromium Code Reviews| 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 8811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8822 NewString("main"), | 8822 NewString("main"), |
| 8823 0, | 8823 0, |
| 8824 NULL); | 8824 NULL); |
| 8825 int64_t value = 0; | 8825 int64_t value = 0; |
| 8826 result = Dart_IntegerToInt64(result, &value); | 8826 result = Dart_IntegerToInt64(result, &value); |
| 8827 EXPECT_VALID(result); | 8827 EXPECT_VALID(result); |
| 8828 EXPECT_EQ(260, value); | 8828 EXPECT_EQ(260, value); |
| 8829 } | 8829 } |
| 8830 | 8830 |
| 8831 | 8831 |
| 8832 TEST_CASE(ExternalStringPolymorphicDeoptimize) { | |
| 8833 const char* kScriptChars = | |
| 8834 "const strA = 'AAAA';\n" | |
| 8835 "class A {\n" | |
| 8836 " static change_str(String s) native 'A_change_str';\n" | |
| 8837 "}\n" | |
| 8838 "compare(a, b, [i = 0]) {\n" | |
| 8839 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" | |
| 8840 "}\n" | |
| 8841 "compareA(b, [i = 0]) {\n" | |
| 8842 " return compare(strA, b, i);\n" | |
| 8843 "}\n" | |
| 8844 "main() {\n" | |
| 8845 " var externalA = 'AA' + 'AA';\n" | |
| 8846 " A.change_str(externalA);\n" | |
| 8847 " compare('AA' + 'AA', strA);\n" | |
| 8848 " compare(externalA, strA);\n" | |
| 8849 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | |
| 8850 " A.change_str(strA);\n" | |
| 8851 " return compareA('AA' + 'AA');\n" | |
| 8852 "}\n"; | |
| 8853 Dart_Handle lib = | |
| 8854 TestCase::LoadTestScript(kScriptChars, | |
| 8855 &ExternalStringDeoptimize_native_lookup); | |
| 8856 Dart_Handle result = Dart_Invoke(lib, | |
| 8857 NewString("main"), | |
| 8858 0, | |
| 8859 NULL); | |
|
Florian Schneider
2015/04/17 15:54:17
EXPECT_VALID(result);
| |
| 8860 bool value = false; | |
| 8861 result = Dart_BooleanValue(result, &value); | |
| 8862 EXPECT_VALID(result); | |
| 8863 EXPECT(value); | |
| 8864 } | |
| 8865 | |
| 8866 | |
| 8867 TEST_CASE(ExternalStringGuardFieldDeoptimize) { | |
| 8868 const char* kScriptChars = | |
| 8869 "const strA = 'AAAA';\n" | |
| 8870 "class A {\n" | |
| 8871 " static change_str(String s) native 'A_change_str';\n" | |
| 8872 "}\n" | |
| 8873 "class G { var f = 'A'; }\n" | |
| 8874 "final guard = new G();\n" | |
| 8875 "var shouldExternalize = false;\n" | |
| 8876 "ext() { if (shouldExternalize) A.change_str(strA); }\n" | |
| 8877 "compare(a, b, [i = 0]) {\n" | |
| 8878 " guard.f = a;\n" | |
| 8879 " ext();" | |
| 8880 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" | |
| 8881 "}\n" | |
| 8882 "compareA(b, [i = 0]) {\n" | |
| 8883 " return compare(strA, b, i);\n" | |
| 8884 "}\n" | |
| 8885 "main() {\n" | |
| 8886 " var externalA = 'AA' + 'AA';\n" | |
| 8887 " A.change_str(externalA);\n" | |
| 8888 " compare('AA' + 'AA', strA);\n" | |
| 8889 " for (var i = 0; i < 10000; i++) compareA(strA);\n" | |
| 8890 " shouldExternalize = true;\n" | |
| 8891 " return compareA('AA' + 'AA');\n" | |
| 8892 "}\n"; | |
| 8893 Dart_Handle lib = | |
| 8894 TestCase::LoadTestScript(kScriptChars, | |
| 8895 &ExternalStringDeoptimize_native_lookup); | |
| 8896 Dart_Handle result = Dart_Invoke(lib, | |
| 8897 NewString("main"), | |
| 8898 0, | |
| 8899 NULL); | |
|
Florian Schneider
2015/04/17 15:54:17
EXPECT_VALID(result);
| |
| 8900 bool value = false; | |
| 8901 result = Dart_BooleanValue(result, &value); | |
| 8902 EXPECT_VALID(result); | |
| 8903 EXPECT(value); | |
| 8904 } | |
| 8905 | |
| 8906 | |
| 8832 TEST_CASE(ExternalStringTrimDoubleParse) { | 8907 TEST_CASE(ExternalStringTrimDoubleParse) { |
| 8833 const char* kScriptChars = | 8908 const char* kScriptChars = |
| 8834 "String str = 'A';\n" | 8909 "String str = 'A';\n" |
| 8835 "class A {\n" | 8910 "class A {\n" |
| 8836 " static change_str(String s) native 'A_change_str';\n" | 8911 " static change_str(String s) native 'A_change_str';\n" |
| 8837 "}\n" | 8912 "}\n" |
| 8838 "main() {\n" | 8913 "main() {\n" |
| 8839 " var externalOneByteString = ' 0.2\\xA0 ';\n;" | 8914 " var externalOneByteString = ' 0.2\\xA0 ';\n;" |
| 8840 " A.change_str(externalOneByteString);\n" | 8915 " A.change_str(externalOneByteString);\n" |
| 8841 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" | 8916 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9005 result = Dart_Invoke(lib, | 9080 result = Dart_Invoke(lib, |
| 9006 NewString("testView16"), | 9081 NewString("testView16"), |
| 9007 1, | 9082 1, |
| 9008 dart_args); | 9083 dart_args); |
| 9009 EXPECT_VALID(result); | 9084 EXPECT_VALID(result); |
| 9010 EXPECT(Dart_IsString(result)); | 9085 EXPECT(Dart_IsString(result)); |
| 9011 } | 9086 } |
| 9012 } | 9087 } |
| 9013 | 9088 |
| 9014 } // namespace dart | 9089 } // namespace dart |
| OLD | NEW |