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

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

Issue 1859273002: Add flag to disable string externalization (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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/flow_graph_builder.cc » ('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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "vm/compiler.h" 6 #include "vm/compiler.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"
11 #include "platform/assert.h" 11 #include "platform/assert.h"
12 #include "platform/text_buffer.h" 12 #include "platform/text_buffer.h"
13 #include "platform/utils.h" 13 #include "platform/utils.h"
14 #include "vm/class_finalizer.h" 14 #include "vm/class_finalizer.h"
15 #include "vm/dart_api_impl.h" 15 #include "vm/dart_api_impl.h"
16 #include "vm/dart_api_state.h" 16 #include "vm/dart_api_state.h"
17 #include "vm/lockers.h" 17 #include "vm/lockers.h"
18 #include "vm/timeline.h" 18 #include "vm/timeline.h"
19 #include "vm/unit_test.h" 19 #include "vm/unit_test.h"
20 #include "vm/verifier.h" 20 #include "vm/verifier.h"
21 21
22 namespace dart { 22 namespace dart {
23 23
24 DECLARE_FLAG(bool, verify_acquired_data); 24 DECLARE_FLAG(bool, verify_acquired_data);
25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch); 25 DECLARE_FLAG(bool, ignore_patch_signature_mismatch);
26 DECLARE_FLAG(bool, support_externalizable_strings);
26 27
27 #ifndef PRODUCT 28 #ifndef PRODUCT
28 29
29 TEST_CASE(ErrorHandleBasics) { 30 TEST_CASE(ErrorHandleBasics) {
30 const char* kScriptChars = 31 const char* kScriptChars =
31 "void testMain() {\n" 32 "void testMain() {\n"
32 " throw new Exception(\"bad news\");\n" 33 " throw new Exception(\"bad news\");\n"
33 "}\n"; 34 "}\n";
34 35
35 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 36 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
(...skipping 5532 matching lines...) Expand 10 before | Expand all | Expand 10 after
5568 if (!strcmp(function_name, "NativeArgument_Create")) { 5569 if (!strcmp(function_name, "NativeArgument_Create")) {
5569 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCreate); 5570 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCreate);
5570 } else if (!strcmp(function_name, "NativeArgument_Access")) { 5571 } else if (!strcmp(function_name, "NativeArgument_Access")) {
5571 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentAccess); 5572 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentAccess);
5572 } 5573 }
5573 return NULL; 5574 return NULL;
5574 } 5575 }
5575 5576
5576 5577
5577 TEST_CASE(GetNativeArguments) { 5578 TEST_CASE(GetNativeArguments) {
5579 const bool saved_flag = FLAG_support_externalizable_strings;
5580 FLAG_support_externalizable_strings = true;
5581
5578 const char* kScriptChars = 5582 const char* kScriptChars =
5579 "import 'dart:nativewrappers';" 5583 "import 'dart:nativewrappers';"
5580 "class MyObject extends NativeFieldWrapperClass2 {" 5584 "class MyObject extends NativeFieldWrapperClass2 {"
5581 " static MyObject createObject() native 'NativeArgument_Create';" 5585 " static MyObject createObject() native 'NativeArgument_Create';"
5582 " int accessFields(int arg1," 5586 " int accessFields(int arg1,"
5583 " int arg2," 5587 " int arg2,"
5584 " bool arg3," 5588 " bool arg3,"
5585 " double arg4," 5589 " double arg4,"
5586 " String arg5," 5590 " String arg5,"
5587 " String arg6," 5591 " String arg6,"
(...skipping 26 matching lines...) Expand all
5614 ext_ascii_str, 5618 ext_ascii_str,
5615 size, 5619 size,
5616 reinterpret_cast<void*>(&native_arg_str_peer), 5620 reinterpret_cast<void*>(&native_arg_str_peer),
5617 NULL); 5621 NULL);
5618 5622
5619 Dart_Handle args[1]; 5623 Dart_Handle args[1];
5620 args[0] = extstr; 5624 args[0] = extstr;
5621 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, args); 5625 Dart_Handle result = Dart_Invoke(lib, NewString("testMain"), 1, args);
5622 EXPECT_VALID(result); 5626 EXPECT_VALID(result);
5623 EXPECT(Dart_IsInteger(result)); 5627 EXPECT(Dart_IsInteger(result));
5628
5629 FLAG_support_externalizable_strings = saved_flag;
5624 } 5630 }
5625 5631
5626 5632
5627 static void NativeArgumentCounter(Dart_NativeArguments args) { 5633 static void NativeArgumentCounter(Dart_NativeArguments args) {
5628 Dart_EnterScope(); 5634 Dart_EnterScope();
5629 int count = Dart_GetNativeArgumentCount(args); 5635 int count = Dart_GetNativeArgumentCount(args);
5630 Dart_SetReturnValue(args, Dart_NewInteger(count)); 5636 Dart_SetReturnValue(args, Dart_NewInteger(count));
5631 Dart_ExitScope(); 5637 Dart_ExitScope();
5632 } 5638 }
5633 5639
(...skipping 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after
8490 } 8496 }
8491 8497
8492 8498
8493 // Test API call to make strings external. 8499 // Test API call to make strings external.
8494 static void MakeExternalCback(void* peer) { 8500 static void MakeExternalCback(void* peer) {
8495 *static_cast<int*>(peer) *= 2; 8501 *static_cast<int*>(peer) *= 2;
8496 } 8502 }
8497 8503
8498 8504
8499 TEST_CASE(MakeExternalString) { 8505 TEST_CASE(MakeExternalString) {
8506 const bool saved_flag = FLAG_support_externalizable_strings;
8507 FLAG_support_externalizable_strings = true;
8508
8500 static int peer8 = 40; 8509 static int peer8 = 40;
8501 static int peer16 = 41; 8510 static int peer16 = 41;
8502 static int canonical_str_peer = 42; 8511 static int canonical_str_peer = 42;
8503 intptr_t length = 0; 8512 intptr_t length = 0;
8504 intptr_t expected_length = 0; 8513 intptr_t expected_length = 0;
8505 { 8514 {
8506 Dart_EnterScope(); 8515 Dart_EnterScope();
8507 8516
8508 // First test some negative conditions. 8517 // First test some negative conditions.
8509 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' }; 8518 uint8_t data8[] = { 'h', 'e', 'l', 'l', 'o' };
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
8693 EXPECT_EQ(40, peer8); 8702 EXPECT_EQ(40, peer8);
8694 EXPECT_EQ(41, peer16); 8703 EXPECT_EQ(41, peer16);
8695 EXPECT_EQ(42, canonical_str_peer); 8704 EXPECT_EQ(42, canonical_str_peer);
8696 { 8705 {
8697 TransitionNativeToVM transition(thread); 8706 TransitionNativeToVM transition(thread);
8698 Isolate::Current()->heap()->CollectAllGarbage(); 8707 Isolate::Current()->heap()->CollectAllGarbage();
8699 } 8708 }
8700 EXPECT_EQ(80, peer8); 8709 EXPECT_EQ(80, peer8);
8701 EXPECT_EQ(82, peer16); 8710 EXPECT_EQ(82, peer16);
8702 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC. 8711 EXPECT_EQ(42, canonical_str_peer); // "*" Symbol is not removed on GC.
8712
8713 FLAG_support_externalizable_strings = saved_flag;
8703 } 8714 }
8704 8715
8705 8716
8706 TEST_CASE(ExternalizeConstantStrings) { 8717 TEST_CASE(ExternalizeConstantStrings) {
8718 const bool saved_flag = FLAG_support_externalizable_strings;
8719 FLAG_support_externalizable_strings = true;
8720
8707 const char* kScriptChars = 8721 const char* kScriptChars =
8708 "String testMain() {\n" 8722 "String testMain() {\n"
8709 " return 'constant string';\n" 8723 " return 'constant string';\n"
8710 "}\n"; 8724 "}\n";
8711 8725
8712 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 8726 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
8713 Dart_Handle result = Dart_Invoke(lib, 8727 Dart_Handle result = Dart_Invoke(lib,
8714 NewString("testMain"), 8728 NewString("testMain"),
8715 0, 8729 0,
8716 NULL); 8730 NULL);
8717 const char* expected_str = "constant string"; 8731 const char* expected_str = "constant string";
8718 const intptr_t kExpectedLen = 15; 8732 const intptr_t kExpectedLen = 15;
8719 uint8_t ext_str[kExpectedLen]; 8733 uint8_t ext_str[kExpectedLen];
8720 Dart_Handle str = Dart_MakeExternalString(result, 8734 Dart_Handle str = Dart_MakeExternalString(result,
8721 ext_str, 8735 ext_str,
8722 kExpectedLen, 8736 kExpectedLen,
8723 NULL, 8737 NULL,
8724 NULL); 8738 NULL);
8725 8739
8726 EXPECT(Dart_IsExternalString(str)); 8740 EXPECT(Dart_IsExternalString(str));
8727 for (intptr_t i = 0; i < kExpectedLen; i++) { 8741 for (intptr_t i = 0; i < kExpectedLen; i++) {
8728 EXPECT_EQ(expected_str[i], ext_str[i]); 8742 EXPECT_EQ(expected_str[i], ext_str[i]);
8729 } 8743 }
8744
8745 FLAG_support_externalizable_strings = saved_flag;
8730 } 8746 }
8731 8747
8732 8748
8733 TEST_CASE(LazyLoadDeoptimizes) { 8749 TEST_CASE(LazyLoadDeoptimizes) {
8734 const char* kLoadFirst = 8750 const char* kLoadFirst =
8735 "library L;\n" 8751 "library L;\n"
8736 "start(a) {\n" 8752 "start(a) {\n"
8737 " var obj = (a == 1) ? createB() : new A();\n" 8753 " var obj = (a == 1) ? createB() : new A();\n"
8738 " for (int i = 0; i < 4000; i++) {\n" 8754 " for (int i = 0; i < 4000; i++) {\n"
8739 " var res = obj.foo();\n" 8755 " var res = obj.foo();\n"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
8809 Dart_Handle name, int argument_count, bool* auto_setup_scope) { 8825 Dart_Handle name, int argument_count, bool* auto_setup_scope) {
8810 ASSERT(auto_setup_scope != NULL); 8826 ASSERT(auto_setup_scope != NULL);
8811 *auto_setup_scope = true; 8827 *auto_setup_scope = true;
8812 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native); 8828 return reinterpret_cast<Dart_NativeFunction>(&A_change_str_native);
8813 } 8829 }
8814 8830
8815 8831
8816 // Do not use guarding mechanism on externalizable classes, since their class 8832 // Do not use guarding mechanism on externalizable classes, since their class
8817 // can change on the fly, 8833 // can change on the fly,
8818 TEST_CASE(GuardExternalizedString) { 8834 TEST_CASE(GuardExternalizedString) {
8835 const bool saved_flag = FLAG_support_externalizable_strings;
8836 FLAG_support_externalizable_strings = true;
8837
8819 const char* kScriptChars = 8838 const char* kScriptChars =
8820 "main() {\n" 8839 "main() {\n"
8821 " var a = new A('hello');\n" 8840 " var a = new A('hello');\n"
8822 " var res = runOne(a);\n" 8841 " var res = runOne(a);\n"
8823 " if (res != 10640000) return -1;\n" 8842 " if (res != 10640000) return -1;\n"
8824 " change_str(a.f);\n" 8843 " change_str(a.f);\n"
8825 " res = runOne(a);\n" 8844 " res = runOne(a);\n"
8826 " return res;\n" 8845 " return res;\n"
8827 "}\n" 8846 "}\n"
8828 "runOne(a) {\n" 8847 "runOne(a) {\n"
(...skipping 15 matching lines...) Expand all
8844 TestCase::LoadTestScript(kScriptChars, 8863 TestCase::LoadTestScript(kScriptChars,
8845 &ExternalStringDeoptimize_native_lookup); 8864 &ExternalStringDeoptimize_native_lookup);
8846 Dart_Handle result = Dart_Invoke(lib, 8865 Dart_Handle result = Dart_Invoke(lib,
8847 NewString("main"), 8866 NewString("main"),
8848 0, 8867 0,
8849 NULL); 8868 NULL);
8850 int64_t value = 0; 8869 int64_t value = 0;
8851 result = Dart_IntegerToInt64(result, &value); 8870 result = Dart_IntegerToInt64(result, &value);
8852 EXPECT_VALID(result); 8871 EXPECT_VALID(result);
8853 EXPECT_EQ(10640000, value); 8872 EXPECT_EQ(10640000, value);
8873
8874 FLAG_support_externalizable_strings = saved_flag;
8854 } 8875 }
8855 8876
8856 8877
8857 TEST_CASE(ExternalStringDeoptimize) { 8878 TEST_CASE(ExternalStringDeoptimize) {
8879 const bool saved_flag = FLAG_support_externalizable_strings;
8880 FLAG_support_externalizable_strings = true;
8881
8858 const char* kScriptChars = 8882 const char* kScriptChars =
8859 "String str = 'A';\n" 8883 "String str = 'A';\n"
8860 "class A {\n" 8884 "class A {\n"
8861 " static change_str(String s) native 'A_change_str';\n" 8885 " static change_str(String s) native 'A_change_str';\n"
8862 "}\n" 8886 "}\n"
8863 "sum_chars(String s, bool b) {\n" 8887 "sum_chars(String s, bool b) {\n"
8864 " var result = 0;\n" 8888 " var result = 0;\n"
8865 " for (var i = 0; i < s.length; i++) {\n" 8889 " for (var i = 0; i < s.length; i++) {\n"
8866 " if (b && i == 0) A.change_str(str);\n" 8890 " if (b && i == 0) A.change_str(str);\n"
8867 " result += s.codeUnitAt(i);" 8891 " result += s.codeUnitAt(i);"
(...skipping 11 matching lines...) Expand all
8879 TestCase::LoadTestScript(kScriptChars, 8903 TestCase::LoadTestScript(kScriptChars,
8880 &ExternalStringDeoptimize_native_lookup); 8904 &ExternalStringDeoptimize_native_lookup);
8881 Dart_Handle result = Dart_Invoke(lib, 8905 Dart_Handle result = Dart_Invoke(lib,
8882 NewString("main"), 8906 NewString("main"),
8883 0, 8907 0,
8884 NULL); 8908 NULL);
8885 int64_t value = 0; 8909 int64_t value = 0;
8886 result = Dart_IntegerToInt64(result, &value); 8910 result = Dart_IntegerToInt64(result, &value);
8887 EXPECT_VALID(result); 8911 EXPECT_VALID(result);
8888 EXPECT_EQ(260, value); 8912 EXPECT_EQ(260, value);
8913
8914 FLAG_support_externalizable_strings = saved_flag;
8889 } 8915 }
8890 8916
8891 8917
8892 TEST_CASE(ExternalStringPolymorphicDeoptimize) { 8918 TEST_CASE(ExternalStringPolymorphicDeoptimize) {
8919 const bool saved_flag = FLAG_support_externalizable_strings;
8920 FLAG_support_externalizable_strings = true;
8921
8893 const char* kScriptChars = 8922 const char* kScriptChars =
8894 "const strA = 'AAAA';\n" 8923 "const strA = 'AAAA';\n"
8895 "class A {\n" 8924 "class A {\n"
8896 " static change_str(String s) native 'A_change_str';\n" 8925 " static change_str(String s) native 'A_change_str';\n"
8897 "}\n" 8926 "}\n"
8898 "compare(a, b, [i = 0]) {\n" 8927 "compare(a, b, [i = 0]) {\n"
8899 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" 8928 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n"
8900 "}\n" 8929 "}\n"
8901 "compareA(b, [i = 0]) {\n" 8930 "compareA(b, [i = 0]) {\n"
8902 " return compare(strA, b, i);\n" 8931 " return compare(strA, b, i);\n"
(...skipping 12 matching lines...) Expand all
8915 &ExternalStringDeoptimize_native_lookup); 8944 &ExternalStringDeoptimize_native_lookup);
8916 Dart_Handle result = Dart_Invoke(lib, 8945 Dart_Handle result = Dart_Invoke(lib,
8917 NewString("main"), 8946 NewString("main"),
8918 0, 8947 0,
8919 NULL); 8948 NULL);
8920 EXPECT_VALID(result); 8949 EXPECT_VALID(result);
8921 bool value = false; 8950 bool value = false;
8922 result = Dart_BooleanValue(result, &value); 8951 result = Dart_BooleanValue(result, &value);
8923 EXPECT_VALID(result); 8952 EXPECT_VALID(result);
8924 EXPECT(value); 8953 EXPECT(value);
8954
8955 FLAG_support_externalizable_strings = saved_flag;
8925 } 8956 }
8926 8957
8927 8958
8928 TEST_CASE(ExternalStringGuardFieldDeoptimize) { 8959 TEST_CASE(ExternalStringGuardFieldDeoptimize) {
8960 const bool saved_flag = FLAG_support_externalizable_strings;
8961 FLAG_support_externalizable_strings = true;
8962
8929 const char* kScriptChars = 8963 const char* kScriptChars =
8930 "const strA = 'AAAA';\n" 8964 "const strA = 'AAAA';\n"
8931 "class A {\n" 8965 "class A {\n"
8932 " static change_str(String s) native 'A_change_str';\n" 8966 " static change_str(String s) native 'A_change_str';\n"
8933 "}\n" 8967 "}\n"
8934 "class G { var f = 'A'; }\n" 8968 "class G { var f = 'A'; }\n"
8935 "final guard = new G();\n" 8969 "final guard = new G();\n"
8936 "var shouldExternalize = false;\n" 8970 "var shouldExternalize = false;\n"
8937 "ext() { if (shouldExternalize) A.change_str(strA); }\n" 8971 "ext() { if (shouldExternalize) A.change_str(strA); }\n"
8938 "compare(a, b, [i = 0]) {\n" 8972 "compare(a, b, [i = 0]) {\n"
(...skipping 17 matching lines...) Expand all
8956 &ExternalStringDeoptimize_native_lookup); 8990 &ExternalStringDeoptimize_native_lookup);
8957 Dart_Handle result = Dart_Invoke(lib, 8991 Dart_Handle result = Dart_Invoke(lib,
8958 NewString("main"), 8992 NewString("main"),
8959 0, 8993 0,
8960 NULL); 8994 NULL);
8961 EXPECT_VALID(result); 8995 EXPECT_VALID(result);
8962 bool value = false; 8996 bool value = false;
8963 result = Dart_BooleanValue(result, &value); 8997 result = Dart_BooleanValue(result, &value);
8964 EXPECT_VALID(result); 8998 EXPECT_VALID(result);
8965 EXPECT(value); 8999 EXPECT(value);
9000
9001 FLAG_support_externalizable_strings = saved_flag;
8966 } 9002 }
8967 9003
8968 9004
8969 TEST_CASE(ExternalStringStaticFieldDeoptimize) { 9005 TEST_CASE(ExternalStringStaticFieldDeoptimize) {
9006 const bool saved_flag = FLAG_support_externalizable_strings;
9007 FLAG_support_externalizable_strings = true;
9008
8970 const char* kScriptChars = 9009 const char* kScriptChars =
8971 "const strA = 'AAAA';\n" 9010 "const strA = 'AAAA';\n"
8972 "class A {\n" 9011 "class A {\n"
8973 " static change_str(String s) native 'A_change_str';\n" 9012 " static change_str(String s) native 'A_change_str';\n"
8974 "}\n" 9013 "}\n"
8975 "class G { static final f = strA; }\n" 9014 "class G { static final f = strA; }\n"
8976 "compare(a, b, [i = 0]) {\n" 9015 "compare(a, b, [i = 0]) {\n"
8977 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n" 9016 " return a.codeUnitAt(i) == b.codeUnitAt(i);\n"
8978 "}\n" 9017 "}\n"
8979 "compareA(b, [i = 0]) {\n" 9018 "compareA(b, [i = 0]) {\n"
(...skipping 12 matching lines...) Expand all
8992 &ExternalStringDeoptimize_native_lookup); 9031 &ExternalStringDeoptimize_native_lookup);
8993 Dart_Handle result = Dart_Invoke(lib, 9032 Dart_Handle result = Dart_Invoke(lib,
8994 NewString("main"), 9033 NewString("main"),
8995 0, 9034 0,
8996 NULL); 9035 NULL);
8997 EXPECT_VALID(result); 9036 EXPECT_VALID(result);
8998 bool value = false; 9037 bool value = false;
8999 result = Dart_BooleanValue(result, &value); 9038 result = Dart_BooleanValue(result, &value);
9000 EXPECT_VALID(result); 9039 EXPECT_VALID(result);
9001 EXPECT(value); 9040 EXPECT(value);
9041
9042 FLAG_support_externalizable_strings = saved_flag;
9002 } 9043 }
9003 9044
9004 9045
9005 TEST_CASE(ExternalStringTrimDoubleParse) { 9046 TEST_CASE(ExternalStringTrimDoubleParse) {
9047 const bool saved_flag = FLAG_support_externalizable_strings;
9048 FLAG_support_externalizable_strings = true;
9049
9006 const char* kScriptChars = 9050 const char* kScriptChars =
9007 "String str = 'A';\n" 9051 "String str = 'A';\n"
9008 "class A {\n" 9052 "class A {\n"
9009 " static change_str(String s) native 'A_change_str';\n" 9053 " static change_str(String s) native 'A_change_str';\n"
9010 "}\n" 9054 "}\n"
9011 "main() {\n" 9055 "main() {\n"
9012 " var externalOneByteString = ' 0.2\\xA0 ';\n;" 9056 " var externalOneByteString = ' 0.2\\xA0 ';\n;"
9013 " A.change_str(externalOneByteString);\n" 9057 " A.change_str(externalOneByteString);\n"
9014 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n" 9058 " var externalTwoByteString = ' \\u{2029}0.6\\u{2029} ';\n"
9015 " A.change_str(externalTwoByteString);\n" 9059 " A.change_str(externalTwoByteString);\n"
9016 " var x = double.parse(externalOneByteString);\n" 9060 " var x = double.parse(externalOneByteString);\n"
9017 " var y = double.parse(externalTwoByteString);\n" 9061 " var y = double.parse(externalTwoByteString);\n"
9018 " return ((x + y) * 10).toInt();\n" 9062 " return ((x + y) * 10).toInt();\n"
9019 "}\n"; 9063 "}\n";
9020 Dart_Handle lib = 9064 Dart_Handle lib =
9021 TestCase::LoadTestScript(kScriptChars, 9065 TestCase::LoadTestScript(kScriptChars,
9022 &ExternalStringDeoptimize_native_lookup); 9066 &ExternalStringDeoptimize_native_lookup);
9023 Dart_Handle result = Dart_Invoke(lib, 9067 Dart_Handle result = Dart_Invoke(lib,
9024 NewString("main"), 9068 NewString("main"),
9025 0, 9069 0,
9026 NULL); 9070 NULL);
9027 int64_t value = 0; 9071 int64_t value = 0;
9028 result = Dart_IntegerToInt64(result, &value); 9072 result = Dart_IntegerToInt64(result, &value);
9029 EXPECT_VALID(result); 9073 EXPECT_VALID(result);
9030 EXPECT_EQ(8, value); 9074 EXPECT_EQ(8, value);
9075
9076 FLAG_support_externalizable_strings = saved_flag;
9031 } 9077 }
9032 9078
9033 9079
9034 TEST_CASE(ExternalStringDoubleParse) { 9080 TEST_CASE(ExternalStringDoubleParse) {
9081 const bool saved_flag = FLAG_support_externalizable_strings;
9082 FLAG_support_externalizable_strings = true;
9083
9035 const char* kScriptChars = 9084 const char* kScriptChars =
9036 "String str = 'A';\n" 9085 "String str = 'A';\n"
9037 "class A {\n" 9086 "class A {\n"
9038 " static change_str(String s) native 'A_change_str';\n" 9087 " static change_str(String s) native 'A_change_str';\n"
9039 "}\n" 9088 "}\n"
9040 "main() {\n" 9089 "main() {\n"
9041 " var externalOneByteString = '0.2';\n;" 9090 " var externalOneByteString = '0.2';\n;"
9042 " A.change_str(externalOneByteString);\n" 9091 " A.change_str(externalOneByteString);\n"
9043 " var externalTwoByteString = '0.6';\n" 9092 " var externalTwoByteString = '0.6';\n"
9044 " A.change_str(externalTwoByteString);\n" 9093 " A.change_str(externalTwoByteString);\n"
9045 " var x = double.parse(externalOneByteString);\n" 9094 " var x = double.parse(externalOneByteString);\n"
9046 " var y = double.parse(externalTwoByteString);\n" 9095 " var y = double.parse(externalTwoByteString);\n"
9047 " return ((x + y) * 10).toInt();\n" 9096 " return ((x + y) * 10).toInt();\n"
9048 "}\n"; 9097 "}\n";
9049 Dart_Handle lib = 9098 Dart_Handle lib =
9050 TestCase::LoadTestScript(kScriptChars, 9099 TestCase::LoadTestScript(kScriptChars,
9051 &ExternalStringDeoptimize_native_lookup); 9100 &ExternalStringDeoptimize_native_lookup);
9052 Dart_Handle result = Dart_Invoke(lib, 9101 Dart_Handle result = Dart_Invoke(lib,
9053 NewString("main"), 9102 NewString("main"),
9054 0, 9103 0,
9055 NULL); 9104 NULL);
9056 int64_t value = 0; 9105 int64_t value = 0;
9057 result = Dart_IntegerToInt64(result, &value); 9106 result = Dart_IntegerToInt64(result, &value);
9058 EXPECT_VALID(result); 9107 EXPECT_VALID(result);
9059 EXPECT_EQ(8, value); 9108 EXPECT_EQ(8, value);
9109
9110 FLAG_support_externalizable_strings = saved_flag;
9060 } 9111 }
9061 9112
9062 9113
9063 TEST_CASE(ExternalStringIndexOf) { 9114 TEST_CASE(ExternalStringIndexOf) {
9064 const char* kScriptChars = 9115 const char* kScriptChars =
9065 "main(String pattern) {\n" 9116 "main(String pattern) {\n"
9066 " var str = 'Hello World';\n" 9117 " var str = 'Hello World';\n"
9067 " return str.indexOf(pattern);\n" 9118 " return str.indexOf(pattern);\n"
9068 "}\n"; 9119 "}\n";
9069 Dart_Handle lib = 9120 Dart_Handle lib =
9070 TestCase::LoadTestScript(kScriptChars, NULL); 9121 TestCase::LoadTestScript(kScriptChars, NULL);
9071 9122
9072 uint8_t data8[] = { 'W' }; 9123 uint8_t data8[] = { 'W' };
9073 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8), 9124 Dart_Handle ext8 = Dart_NewExternalLatin1String(data8, ARRAY_SIZE(data8),
9074 data8, NULL); 9125 data8, NULL);
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
10001 result = Dart_Invoke(lib, 10052 result = Dart_Invoke(lib,
10002 NewString("foozoo"), 10053 NewString("foozoo"),
10003 0, 10054 0,
10004 NULL); 10055 NULL);
10005 EXPECT(Dart_IsError(result)); 10056 EXPECT(Dart_IsError(result));
10006 } 10057 }
10007 10058
10008 #endif // !PRODUCT 10059 #endif // !PRODUCT
10009 10060
10010 } // namespace dart 10061 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/flow_graph_builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698