| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // Check that we can traverse very deep stacks of ConsStrings using | 28 // Check that we can traverse very deep stacks of ConsStrings using |
| 29 // StringCharacterStram. Check that Get(int) works on very deep stacks | 29 // StringCharacterStram. Check that Get(int) works on very deep stacks |
| 30 // of ConsStrings. These operations may not be very fast, but they | 30 // of ConsStrings. These operations may not be very fast, but they |
| 31 // should be possible without getting errors due to too deep recursion. | 31 // should be possible without getting errors due to too deep recursion. |
| 32 | 32 |
| 33 // TODO(jochen): Remove this after the setting is turned on globally. |
| 34 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 35 |
| 33 #include <stdlib.h> | 36 #include <stdlib.h> |
| 34 | 37 |
| 35 #include "src/v8.h" | 38 #include "src/v8.h" |
| 36 | 39 |
| 37 #include "src/api.h" | 40 #include "src/api.h" |
| 38 #include "src/factory.h" | 41 #include "src/factory.h" |
| 39 #include "src/messages.h" | 42 #include "src/messages.h" |
| 40 #include "src/objects.h" | 43 #include "src/objects.h" |
| 41 #include "src/unicode-decoder.h" | 44 #include "src/unicode-decoder.h" |
| 42 #include "test/cctest/cctest.h" | 45 #include "test/cctest/cctest.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 187 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
| 185 } | 188 } |
| 186 break; | 189 break; |
| 187 } | 190 } |
| 188 case 2: { | 191 case 2: { |
| 189 uc16* buf = NewArray<uc16>(len); | 192 uc16* buf = NewArray<uc16>(len); |
| 190 for (int j = 0; j < len; j++) { | 193 for (int j = 0; j < len; j++) { |
| 191 buf[j] = rng->next(0x10000); | 194 buf[j] = rng->next(0x10000); |
| 192 } | 195 } |
| 193 Resource* resource = new Resource(buf, len); | 196 Resource* resource = new Resource(buf, len); |
| 194 building_blocks[i] = | 197 building_blocks[i] = v8::Utils::OpenHandle( |
| 195 v8::Utils::OpenHandle( | 198 *v8::String::NewExternalTwoByte(CcTest::isolate(), resource) |
| 196 *v8::String::NewExternal(CcTest::isolate(), resource)); | 199 .ToLocalChecked()); |
| 197 for (int j = 0; j < len; j++) { | 200 for (int j = 0; j < len; j++) { |
| 198 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 201 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
| 199 } | 202 } |
| 200 break; | 203 break; |
| 201 } | 204 } |
| 202 case 3: { | 205 case 3: { |
| 203 char* buf = NewArray<char>(len); | 206 char* buf = NewArray<char>(len); |
| 204 for (int j = 0; j < len; j++) { | 207 for (int j = 0; j < len; j++) { |
| 205 buf[j] = rng->next(0x80); | 208 buf[j] = rng->next(0x80); |
| 206 } | 209 } |
| 207 OneByteResource* resource = new OneByteResource(buf, len); | 210 OneByteResource* resource = new OneByteResource(buf, len); |
| 208 building_blocks[i] = | 211 building_blocks[i] = v8::Utils::OpenHandle( |
| 209 v8::Utils::OpenHandle( | 212 *v8::String::NewExternalOneByte(CcTest::isolate(), resource) |
| 210 *v8::String::NewExternal(CcTest::isolate(), resource)); | 213 .ToLocalChecked()); |
| 211 for (int j = 0; j < len; j++) { | 214 for (int j = 0; j < len; j++) { |
| 212 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 215 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
| 213 } | 216 } |
| 214 break; | 217 break; |
| 215 } | 218 } |
| 216 } | 219 } |
| 217 for (int j = slice_depth; j > 0; j--) { | 220 for (int j = slice_depth; j > 0; j--) { |
| 218 building_blocks[i] = factory->NewSubString( | 221 building_blocks[i] = factory->NewSubString( |
| 219 building_blocks[i], | 222 building_blocks[i], |
| 220 slice_head_chars, | 223 slice_head_chars, |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 } | 876 } |
| 874 | 877 |
| 875 | 878 |
| 876 TEST(Utf8Conversion) { | 879 TEST(Utf8Conversion) { |
| 877 // Smoke test for converting strings to utf-8. | 880 // Smoke test for converting strings to utf-8. |
| 878 CcTest::InitializeVM(); | 881 CcTest::InitializeVM(); |
| 879 v8::HandleScope handle_scope(CcTest::isolate()); | 882 v8::HandleScope handle_scope(CcTest::isolate()); |
| 880 // A simple one-byte string | 883 // A simple one-byte string |
| 881 const char* one_byte_string = "abcdef12345"; | 884 const char* one_byte_string = "abcdef12345"; |
| 882 int len = v8::String::NewFromUtf8(CcTest::isolate(), one_byte_string, | 885 int len = v8::String::NewFromUtf8(CcTest::isolate(), one_byte_string, |
| 883 v8::String::kNormalString, | 886 v8::NewStringType::kNormal, |
| 884 StrLength(one_byte_string))->Utf8Length(); | 887 StrLength(one_byte_string)) |
| 888 .ToLocalChecked() |
| 889 ->Utf8Length(); |
| 885 CHECK_EQ(StrLength(one_byte_string), len); | 890 CHECK_EQ(StrLength(one_byte_string), len); |
| 886 // A mixed one-byte and two-byte string | 891 // A mixed one-byte and two-byte string |
| 887 // U+02E4 -> CB A4 | 892 // U+02E4 -> CB A4 |
| 888 // U+0064 -> 64 | 893 // U+0064 -> 64 |
| 889 // U+12E4 -> E1 8B A4 | 894 // U+12E4 -> E1 8B A4 |
| 890 // U+0030 -> 30 | 895 // U+0030 -> 30 |
| 891 // U+3045 -> E3 81 85 | 896 // U+3045 -> E3 81 85 |
| 892 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045}; | 897 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045}; |
| 893 // The characters we expect to be output | 898 // The characters we expect to be output |
| 894 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, | 899 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, |
| 895 0xE3, 0x81, 0x85, 0x00}; | 900 0xE3, 0x81, 0x85, 0x00}; |
| 896 // The number of bytes expected to be written for each length | 901 // The number of bytes expected to be written for each length |
| 897 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11}; | 902 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11}; |
| 898 const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5}; | 903 const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5}; |
| 899 v8::Handle<v8::String> mixed = v8::String::NewFromTwoByte( | 904 v8::Local<v8::String> mixed = |
| 900 CcTest::isolate(), mixed_string, v8::String::kNormalString, 5); | 905 v8::String::NewFromTwoByte(CcTest::isolate(), mixed_string, |
| 906 v8::NewStringType::kNormal, 5) |
| 907 .ToLocalChecked(); |
| 901 CHECK_EQ(10, mixed->Utf8Length()); | 908 CHECK_EQ(10, mixed->Utf8Length()); |
| 902 // Try encoding the string with all capacities | 909 // Try encoding the string with all capacities |
| 903 char buffer[11]; | 910 char buffer[11]; |
| 904 const char kNoChar = static_cast<char>(-1); | 911 const char kNoChar = static_cast<char>(-1); |
| 905 for (int i = 0; i <= 11; i++) { | 912 for (int i = 0; i <= 11; i++) { |
| 906 // Clear the buffer before reusing it | 913 // Clear the buffer before reusing it |
| 907 for (int j = 0; j < 11; j++) | 914 for (int j = 0; j < 11; j++) |
| 908 buffer[j] = kNoChar; | 915 buffer[j] = kNoChar; |
| 909 int chars_written; | 916 int chars_written; |
| 910 int written = mixed->WriteUtf8(buffer, i, &chars_written); | 917 int written = mixed->WriteUtf8(buffer, i, &chars_written); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 922 | 929 |
| 923 TEST(ExternalShortStringAdd) { | 930 TEST(ExternalShortStringAdd) { |
| 924 LocalContext context; | 931 LocalContext context; |
| 925 v8::HandleScope handle_scope(CcTest::isolate()); | 932 v8::HandleScope handle_scope(CcTest::isolate()); |
| 926 | 933 |
| 927 // Make sure we cover all always-flat lengths and at least one above. | 934 // Make sure we cover all always-flat lengths and at least one above. |
| 928 static const int kMaxLength = 20; | 935 static const int kMaxLength = 20; |
| 929 CHECK_GT(kMaxLength, i::ConsString::kMinLength); | 936 CHECK_GT(kMaxLength, i::ConsString::kMinLength); |
| 930 | 937 |
| 931 // Allocate two JavaScript arrays for holding short strings. | 938 // Allocate two JavaScript arrays for holding short strings. |
| 932 v8::Handle<v8::Array> one_byte_external_strings = | 939 v8::Local<v8::Array> one_byte_external_strings = |
| 933 v8::Array::New(CcTest::isolate(), kMaxLength + 1); | 940 v8::Array::New(CcTest::isolate(), kMaxLength + 1); |
| 934 v8::Handle<v8::Array> non_one_byte_external_strings = | 941 v8::Local<v8::Array> non_one_byte_external_strings = |
| 935 v8::Array::New(CcTest::isolate(), kMaxLength + 1); | 942 v8::Array::New(CcTest::isolate(), kMaxLength + 1); |
| 936 | 943 |
| 937 // Generate short one-byte and two-byte external strings. | 944 // Generate short one-byte and two-byte external strings. |
| 938 for (int i = 0; i <= kMaxLength; i++) { | 945 for (int i = 0; i <= kMaxLength; i++) { |
| 939 char* one_byte = NewArray<char>(i + 1); | 946 char* one_byte = NewArray<char>(i + 1); |
| 940 for (int j = 0; j < i; j++) { | 947 for (int j = 0; j < i; j++) { |
| 941 one_byte[j] = 'a'; | 948 one_byte[j] = 'a'; |
| 942 } | 949 } |
| 943 // Terminating '\0' is left out on purpose. It is not required for external | 950 // Terminating '\0' is left out on purpose. It is not required for external |
| 944 // string data. | 951 // string data. |
| 945 OneByteResource* one_byte_resource = new OneByteResource(one_byte, i); | 952 OneByteResource* one_byte_resource = new OneByteResource(one_byte, i); |
| 946 v8::Local<v8::String> one_byte_external_string = | 953 v8::Local<v8::String> one_byte_external_string = |
| 947 v8::String::NewExternal(CcTest::isolate(), one_byte_resource); | 954 v8::String::NewExternalOneByte(CcTest::isolate(), one_byte_resource) |
| 955 .ToLocalChecked(); |
| 948 | 956 |
| 949 one_byte_external_strings->Set(v8::Integer::New(CcTest::isolate(), i), | 957 one_byte_external_strings->Set(context.local(), |
| 950 one_byte_external_string); | 958 v8::Integer::New(CcTest::isolate(), i), |
| 959 one_byte_external_string) |
| 960 .FromJust(); |
| 951 uc16* non_one_byte = NewArray<uc16>(i + 1); | 961 uc16* non_one_byte = NewArray<uc16>(i + 1); |
| 952 for (int j = 0; j < i; j++) { | 962 for (int j = 0; j < i; j++) { |
| 953 non_one_byte[j] = 0x1234; | 963 non_one_byte[j] = 0x1234; |
| 954 } | 964 } |
| 955 // Terminating '\0' is left out on purpose. It is not required for external | 965 // Terminating '\0' is left out on purpose. It is not required for external |
| 956 // string data. | 966 // string data. |
| 957 Resource* resource = new Resource(non_one_byte, i); | 967 Resource* resource = new Resource(non_one_byte, i); |
| 958 v8::Local<v8::String> non_one_byte_external_string = | 968 v8::Local<v8::String> non_one_byte_external_string = |
| 959 v8::String::NewExternal(CcTest::isolate(), resource); | 969 v8::String::NewExternalTwoByte(CcTest::isolate(), resource) |
| 960 non_one_byte_external_strings->Set(v8::Integer::New(CcTest::isolate(), i), | 970 .ToLocalChecked(); |
| 961 non_one_byte_external_string); | 971 non_one_byte_external_strings->Set(context.local(), |
| 972 v8::Integer::New(CcTest::isolate(), i), |
| 973 non_one_byte_external_string) |
| 974 .FromJust(); |
| 962 } | 975 } |
| 963 | 976 |
| 964 // Add the arrays with the short external strings in the global object. | 977 // Add the arrays with the short external strings in the global object. |
| 965 v8::Handle<v8::Object> global = context->Global(); | 978 v8::Local<v8::Object> global = context->Global(); |
| 966 global->Set(v8_str("external_one_byte"), one_byte_external_strings); | 979 global->Set(context.local(), v8_str("external_one_byte"), |
| 967 global->Set(v8_str("external_non_one_byte"), non_one_byte_external_strings); | 980 one_byte_external_strings) |
| 968 global->Set(v8_str("max_length"), | 981 .FromJust(); |
| 969 v8::Integer::New(CcTest::isolate(), kMaxLength)); | 982 global->Set(context.local(), v8_str("external_non_one_byte"), |
| 983 non_one_byte_external_strings) |
| 984 .FromJust(); |
| 985 global->Set(context.local(), v8_str("max_length"), |
| 986 v8::Integer::New(CcTest::isolate(), kMaxLength)) |
| 987 .FromJust(); |
| 970 | 988 |
| 971 // Add short external one-byte and two-byte strings checking the result. | 989 // Add short external one-byte and two-byte strings checking the result. |
| 972 static const char* source = | 990 static const char* source = |
| 973 "function test() {" | 991 "function test() {" |
| 974 " var one_byte_chars = 'aaaaaaaaaaaaaaaaaaaa';" | 992 " var one_byte_chars = 'aaaaaaaaaaaaaaaaaaaa';" |
| 975 " var non_one_byte_chars = " | 993 " var non_one_byte_chars = " |
| 976 "'\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1" | 994 "'\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1" |
| 977 "234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\" | 995 "234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\u1234\\" |
| 978 "u1234';" // NOLINT | 996 "u1234';" // NOLINT |
| 979 " if (one_byte_chars.length != max_length) return 1;" | 997 " if (one_byte_chars.length != max_length) return 1;" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1005 " (external_non_one_byte[j] + non_one_byte[i - j])) return " | 1023 " (external_non_one_byte[j] + non_one_byte[i - j])) return " |
| 1006 "11;" | 1024 "11;" |
| 1007 " if (non_one_byte[i] !=" | 1025 " if (non_one_byte[i] !=" |
| 1008 " (non_one_byte[j] + external_non_one_byte[i - j])) return " | 1026 " (non_one_byte[j] + external_non_one_byte[i - j])) return " |
| 1009 "12;" | 1027 "12;" |
| 1010 " }" | 1028 " }" |
| 1011 " }" | 1029 " }" |
| 1012 " return 0;" | 1030 " return 0;" |
| 1013 "};" | 1031 "};" |
| 1014 "test()"; | 1032 "test()"; |
| 1015 CHECK_EQ(0, CompileRun(source)->Int32Value()); | 1033 CHECK_EQ(0, CompileRun(source)->Int32Value(context.local()).FromJust()); |
| 1016 } | 1034 } |
| 1017 | 1035 |
| 1018 | 1036 |
| 1019 TEST(JSONStringifySliceMadeExternal) { | 1037 TEST(JSONStringifySliceMadeExternal) { |
| 1020 CcTest::InitializeVM(); | 1038 CcTest::InitializeVM(); |
| 1021 // Create a sliced string from a one-byte string. The latter is turned | 1039 // Create a sliced string from a one-byte string. The latter is turned |
| 1022 // into a two-byte external string. Check that JSON.stringify works. | 1040 // into a two-byte external string. Check that JSON.stringify works. |
| 1023 v8::HandleScope handle_scope(CcTest::isolate()); | 1041 v8::HandleScope handle_scope(CcTest::isolate()); |
| 1024 v8::Handle<v8::String> underlying = | 1042 v8::Local<v8::String> underlying = |
| 1025 CompileRun( | 1043 CompileRun( |
| 1026 "var underlying = 'abcdefghijklmnopqrstuvwxyz';" | 1044 "var underlying = 'abcdefghijklmnopqrstuvwxyz';" |
| 1027 "underlying")->ToString(CcTest::isolate()); | 1045 "underlying") |
| 1028 v8::Handle<v8::String> slice = CompileRun( | 1046 ->ToString(CcTest::isolate()->GetCurrentContext()) |
| 1029 "var slice = '';" | 1047 .ToLocalChecked(); |
| 1030 "slice = underlying.slice(1);" | 1048 v8::Local<v8::String> slice = |
| 1031 "slice")->ToString(CcTest::isolate()); | 1049 CompileRun( |
| 1050 "var slice = '';" |
| 1051 "slice = underlying.slice(1);" |
| 1052 "slice") |
| 1053 ->ToString(CcTest::isolate()->GetCurrentContext()) |
| 1054 .ToLocalChecked(); |
| 1032 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); | 1055 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); |
| 1033 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString()); | 1056 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString()); |
| 1034 | 1057 |
| 1035 int length = underlying->Length(); | 1058 int length = underlying->Length(); |
| 1036 uc16* two_byte = NewArray<uc16>(length + 1); | 1059 uc16* two_byte = NewArray<uc16>(length + 1); |
| 1037 underlying->Write(two_byte); | 1060 underlying->Write(two_byte); |
| 1038 Resource* resource = new Resource(two_byte, length); | 1061 Resource* resource = new Resource(two_byte, length); |
| 1039 CHECK(underlying->MakeExternal(resource)); | 1062 CHECK(underlying->MakeExternal(resource)); |
| 1040 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); | 1063 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString()); |
| 1041 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString()); | 1064 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1072 Handle<Object> results[] = { isolate->factory()->undefined_value(), | 1095 Handle<Object> results[] = { isolate->factory()->undefined_value(), |
| 1073 fortytwo, | 1096 fortytwo, |
| 1074 isolate->factory()->undefined_value(), | 1097 isolate->factory()->undefined_value(), |
| 1075 isolate->factory()->undefined_value(), | 1098 isolate->factory()->undefined_value(), |
| 1076 thirtyseven, | 1099 thirtyseven, |
| 1077 fortytwo, | 1100 fortytwo, |
| 1078 thirtyseven // Bug yielded 42 here. | 1101 thirtyseven // Bug yielded 42 here. |
| 1079 }; | 1102 }; |
| 1080 | 1103 |
| 1081 const char* line; | 1104 const char* line; |
| 1105 v8::Local<v8::Context> context = CcTest::isolate()->GetCurrentContext(); |
| 1082 for (int i = 0; (line = lines[i]); i++) { | 1106 for (int i = 0; (line = lines[i]); i++) { |
| 1083 printf("%s\n", line); | 1107 printf("%s\n", line); |
| 1084 v8::Local<v8::Value> result = v8::Script::Compile( | 1108 v8::Local<v8::Value> result = |
| 1085 v8::String::NewFromUtf8(CcTest::isolate(), line))->Run(); | 1109 v8::Script::Compile(context, |
| 1110 v8::String::NewFromUtf8(CcTest::isolate(), line, |
| 1111 v8::NewStringType::kNormal) |
| 1112 .ToLocalChecked()) |
| 1113 .ToLocalChecked() |
| 1114 ->Run(context) |
| 1115 .ToLocalChecked(); |
| 1086 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); | 1116 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); |
| 1087 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); | 1117 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); |
| 1088 if (result->IsNumber()) { | 1118 if (result->IsNumber()) { |
| 1089 int32_t value = 0; | 1119 int32_t value = 0; |
| 1090 CHECK(results[i]->ToInt32(&value)); | 1120 CHECK(results[i]->ToInt32(&value)); |
| 1091 CHECK_EQ(value, result->ToInt32(CcTest::isolate())->Value()); | 1121 CHECK_EQ(value, result->ToInt32(context).ToLocalChecked()->Value()); |
| 1092 } | 1122 } |
| 1093 } | 1123 } |
| 1094 } | 1124 } |
| 1095 | 1125 |
| 1096 | 1126 |
| 1097 TEST(SliceFromCons) { | 1127 TEST(SliceFromCons) { |
| 1098 FLAG_string_slices = true; | 1128 FLAG_string_slices = true; |
| 1099 CcTest::InitializeVM(); | 1129 CcTest::InitializeVM(); |
| 1100 Factory* factory = CcTest::i_isolate()->factory(); | 1130 Factory* factory = CcTest::i_isolate()->factory(); |
| 1101 v8::HandleScope scope(CcTest::isolate()); | 1131 v8::HandleScope scope(CcTest::isolate()); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1313 CHECK_EQ(0, use_counts[v8::Isolate::kBreakIterator]); | 1343 CHECK_EQ(0, use_counts[v8::Isolate::kBreakIterator]); |
| 1314 v8::Local<v8::Value> result = CompileRun( | 1344 v8::Local<v8::Value> result = CompileRun( |
| 1315 "(function() {" | 1345 "(function() {" |
| 1316 " if (!this.Intl) return 0;" | 1346 " if (!this.Intl) return 0;" |
| 1317 " var iterator = Intl.v8BreakIterator(['en']);" | 1347 " var iterator = Intl.v8BreakIterator(['en']);" |
| 1318 " iterator.adoptText('Now is the time');" | 1348 " iterator.adoptText('Now is the time');" |
| 1319 " iterator.next();" | 1349 " iterator.next();" |
| 1320 " return iterator.next();" | 1350 " return iterator.next();" |
| 1321 "})();"); | 1351 "})();"); |
| 1322 CHECK(result->IsNumber()); | 1352 CHECK(result->IsNumber()); |
| 1323 int uses = result->ToInt32(CcTest::isolate())->Value() == 0 ? 0 : 1; | 1353 int uses = |
| 1354 result->ToInt32(context.local()).ToLocalChecked()->Value() == 0 ? 0 : 1; |
| 1324 CHECK_EQ(uses, use_counts[v8::Isolate::kBreakIterator]); | 1355 CHECK_EQ(uses, use_counts[v8::Isolate::kBreakIterator]); |
| 1325 // Make sure GC cleans up the break iterator, so we don't get a memory leak | 1356 // Make sure GC cleans up the break iterator, so we don't get a memory leak |
| 1326 // reported by ASAN. | 1357 // reported by ASAN. |
| 1327 CcTest::isolate()->LowMemoryNotification(); | 1358 CcTest::isolate()->LowMemoryNotification(); |
| 1328 } | 1359 } |
| 1329 | 1360 |
| 1330 | 1361 |
| 1331 TEST(StringReplaceAtomTwoByteResult) { | 1362 TEST(StringReplaceAtomTwoByteResult) { |
| 1332 CcTest::InitializeVM(); | 1363 CcTest::InitializeVM(); |
| 1333 v8::HandleScope scope(CcTest::isolate()); | 1364 v8::HandleScope scope(CcTest::isolate()); |
| 1334 LocalContext context; | 1365 LocalContext context; |
| 1335 v8::Local<v8::Value> result = CompileRun( | 1366 v8::Local<v8::Value> result = CompileRun( |
| 1336 "var subject = 'one_byte~only~string~'; " | 1367 "var subject = 'one_byte~only~string~'; " |
| 1337 "var replace = '\x80'; " | 1368 "var replace = '\x80'; " |
| 1338 "subject.replace(/~/g, replace); "); | 1369 "subject.replace(/~/g, replace); "); |
| 1339 CHECK(result->IsString()); | 1370 CHECK(result->IsString()); |
| 1340 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); | 1371 Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); |
| 1341 CHECK(string->IsSeqTwoByteString()); | 1372 CHECK(string->IsSeqTwoByteString()); |
| 1342 | 1373 |
| 1343 v8::Local<v8::String> expected = v8_str("one_byte\x80only\x80string\x80"); | 1374 v8::Local<v8::String> expected = v8_str("one_byte\x80only\x80string\x80"); |
| 1344 CHECK(expected->Equals(result)); | 1375 CHECK(expected->Equals(context.local(), result).FromJust()); |
| 1345 } | 1376 } |
| 1346 | 1377 |
| 1347 | 1378 |
| 1348 TEST(IsAscii) { | 1379 TEST(IsAscii) { |
| 1349 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); | 1380 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); |
| 1350 CHECK(String::IsOneByte(static_cast<uc16*>(NULL), 0)); | 1381 CHECK(String::IsOneByte(static_cast<uc16*>(NULL), 0)); |
| 1351 } | 1382 } |
| 1352 | 1383 |
| 1353 | 1384 |
| 1354 | 1385 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1473 Handle<String> arg0 = isolate->factory()->NewStringFromAsciiChecked("arg0"); | 1504 Handle<String> arg0 = isolate->factory()->NewStringFromAsciiChecked("arg0"); |
| 1474 Handle<String> arg1 = isolate->factory()->NewStringFromAsciiChecked("arg1"); | 1505 Handle<String> arg1 = isolate->factory()->NewStringFromAsciiChecked("arg1"); |
| 1475 Handle<String> arg2 = isolate->factory()->NewStringFromAsciiChecked("arg2"); | 1506 Handle<String> arg2 = isolate->factory()->NewStringFromAsciiChecked("arg2"); |
| 1476 Handle<String> result = | 1507 Handle<String> result = |
| 1477 MessageTemplate::FormatMessage(MessageTemplate::kPropertyNotFunction, | 1508 MessageTemplate::FormatMessage(MessageTemplate::kPropertyNotFunction, |
| 1478 arg0, arg1, arg2).ToHandleChecked(); | 1509 arg0, arg1, arg2).ToHandleChecked(); |
| 1479 Handle<String> expected = isolate->factory()->NewStringFromAsciiChecked( | 1510 Handle<String> expected = isolate->factory()->NewStringFromAsciiChecked( |
| 1480 "'arg0' returned for property 'arg1' of object 'arg2' is not a function"); | 1511 "'arg0' returned for property 'arg1' of object 'arg2' is not a function"); |
| 1481 CHECK(String::Equals(result, expected)); | 1512 CHECK(String::Equals(result, expected)); |
| 1482 } | 1513 } |
| OLD | NEW |