| 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 871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 DeleteArray<char>(foo); | 882 DeleteArray<char>(foo); |
| 883 } | 883 } |
| 884 | 884 |
| 885 | 885 |
| 886 TEST(Utf8Conversion) { | 886 TEST(Utf8Conversion) { |
| 887 // Smoke test for converting strings to utf-8. | 887 // Smoke test for converting strings to utf-8. |
| 888 CcTest::InitializeVM(); | 888 CcTest::InitializeVM(); |
| 889 v8::HandleScope handle_scope(CcTest::isolate()); | 889 v8::HandleScope handle_scope(CcTest::isolate()); |
| 890 // A simple ascii string | 890 // A simple ascii string |
| 891 const char* ascii_string = "abcdef12345"; | 891 const char* ascii_string = "abcdef12345"; |
| 892 int len = | 892 int len = v8::String::NewFromUtf8(CcTest::isolate(), ascii_string, |
| 893 v8::String::New(ascii_string, | 893 v8::String::kNormalString, |
| 894 StrLength(ascii_string))->Utf8Length(); | 894 StrLength(ascii_string))->Utf8Length(); |
| 895 CHECK_EQ(StrLength(ascii_string), len); | 895 CHECK_EQ(StrLength(ascii_string), len); |
| 896 // A mixed ascii and non-ascii string | 896 // A mixed ascii and non-ascii string |
| 897 // U+02E4 -> CB A4 | 897 // U+02E4 -> CB A4 |
| 898 // U+0064 -> 64 | 898 // U+0064 -> 64 |
| 899 // U+12E4 -> E1 8B A4 | 899 // U+12E4 -> E1 8B A4 |
| 900 // U+0030 -> 30 | 900 // U+0030 -> 30 |
| 901 // U+3045 -> E3 81 85 | 901 // U+3045 -> E3 81 85 |
| 902 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045}; | 902 const uint16_t mixed_string[] = {0x02E4, 0x0064, 0x12E4, 0x0030, 0x3045}; |
| 903 // The characters we expect to be output | 903 // The characters we expect to be output |
| 904 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, | 904 const unsigned char as_utf8[11] = {0xCB, 0xA4, 0x64, 0xE1, 0x8B, 0xA4, 0x30, |
| 905 0xE3, 0x81, 0x85, 0x00}; | 905 0xE3, 0x81, 0x85, 0x00}; |
| 906 // The number of bytes expected to be written for each length | 906 // The number of bytes expected to be written for each length |
| 907 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11}; | 907 const int lengths[12] = {0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11}; |
| 908 const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5}; | 908 const int char_lengths[12] = {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5}; |
| 909 v8::Handle<v8::String> mixed = v8::String::New(mixed_string, 5); | 909 v8::Handle<v8::String> mixed = v8::String::NewFromTwoByte( |
| 910 CcTest::isolate(), mixed_string, v8::String::kNormalString, 5); |
| 910 CHECK_EQ(10, mixed->Utf8Length()); | 911 CHECK_EQ(10, mixed->Utf8Length()); |
| 911 // Try encoding the string with all capacities | 912 // Try encoding the string with all capacities |
| 912 char buffer[11]; | 913 char buffer[11]; |
| 913 const char kNoChar = static_cast<char>(-1); | 914 const char kNoChar = static_cast<char>(-1); |
| 914 for (int i = 0; i <= 11; i++) { | 915 for (int i = 0; i <= 11; i++) { |
| 915 // Clear the buffer before reusing it | 916 // Clear the buffer before reusing it |
| 916 for (int j = 0; j < 11; j++) | 917 for (int j = 0; j < 11; j++) |
| 917 buffer[j] = kNoChar; | 918 buffer[j] = kNoChar; |
| 918 int chars_written; | 919 int chars_written; |
| 919 int written = mixed->WriteUtf8(buffer, i, &chars_written); | 920 int written = mixed->WriteUtf8(buffer, i, &chars_written); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 isolate->factory()->undefined_value(), | 1077 isolate->factory()->undefined_value(), |
| 1077 isolate->factory()->undefined_value(), | 1078 isolate->factory()->undefined_value(), |
| 1078 thirtyseven, | 1079 thirtyseven, |
| 1079 fortytwo, | 1080 fortytwo, |
| 1080 thirtyseven // Bug yielded 42 here. | 1081 thirtyseven // Bug yielded 42 here. |
| 1081 }; | 1082 }; |
| 1082 | 1083 |
| 1083 const char* line; | 1084 const char* line; |
| 1084 for (int i = 0; (line = lines[i]); i++) { | 1085 for (int i = 0; (line = lines[i]); i++) { |
| 1085 printf("%s\n", line); | 1086 printf("%s\n", line); |
| 1086 v8::Local<v8::Value> result = | 1087 v8::Local<v8::Value> result = v8::Script::Compile( |
| 1087 v8::Script::Compile(v8::String::New(line))->Run(); | 1088 v8::String::NewFromUtf8(CcTest::isolate(), line))->Run(); |
| 1088 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); | 1089 CHECK_EQ(results[i]->IsUndefined(), result->IsUndefined()); |
| 1089 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); | 1090 CHECK_EQ(results[i]->IsNumber(), result->IsNumber()); |
| 1090 if (result->IsNumber()) { | 1091 if (result->IsNumber()) { |
| 1091 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), | 1092 CHECK_EQ(Smi::cast(results[i]->ToSmi()->ToObjectChecked())->value(), |
| 1092 result->ToInt32()->Value()); | 1093 result->ToInt32()->Value()); |
| 1093 } | 1094 } |
| 1094 } | 1095 } |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 | 1098 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 "var two_14 = Math.pow(2, 14);" | 1224 "var two_14 = Math.pow(2, 14);" |
| 1224 "var two_17 = Math.pow(2, 17);" | 1225 "var two_17 = Math.pow(2, 17);" |
| 1225 "var s = Array(two_17 + 1).join('c');" | 1226 "var s = Array(two_17 + 1).join('c');" |
| 1226 "var a = ['bad'];" | 1227 "var a = ['bad'];" |
| 1227 "for (var i = 1; i <= two_14; i++) a.push(s);" | 1228 "for (var i = 1; i <= two_14; i++) a.push(s);" |
| 1228 "a.join("");"; | 1229 "a.join("");"; |
| 1229 | 1230 |
| 1230 v8::HandleScope scope(CcTest::isolate()); | 1231 v8::HandleScope scope(CcTest::isolate()); |
| 1231 LocalContext context; | 1232 LocalContext context; |
| 1232 v8::V8::IgnoreOutOfMemoryException(); | 1233 v8::V8::IgnoreOutOfMemoryException(); |
| 1233 v8::Local<v8::Script> script = | 1234 v8::Local<v8::Script> script = v8::Script::Compile( |
| 1234 v8::Script::Compile(v8::String::New(join_causing_out_of_memory)); | 1235 v8::String::NewFromUtf8(CcTest::isolate(), join_causing_out_of_memory)); |
| 1235 v8::Local<v8::Value> result = script->Run(); | 1236 v8::Local<v8::Value> result = script->Run(); |
| 1236 | 1237 |
| 1237 // Check for out of memory state. | 1238 // Check for out of memory state. |
| 1238 CHECK(result.IsEmpty()); | 1239 CHECK(result.IsEmpty()); |
| 1239 CHECK(context->HasOutOfMemoryException()); | 1240 CHECK(context->HasOutOfMemoryException()); |
| 1240 } | 1241 } |
| 1241 | 1242 |
| 1242 | 1243 |
| 1243 static void CheckException(const char* source) { | 1244 static void CheckException(const char* source) { |
| 1244 // An empty handle is returned upon exception. | 1245 // An empty handle is returned upon exception. |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 CheckCanonicalEquivalence(c, test); | 1380 CheckCanonicalEquivalence(c, test); |
| 1380 continue; | 1381 continue; |
| 1381 } | 1382 } |
| 1382 if (upper != c && lower != c) { | 1383 if (upper != c && lower != c) { |
| 1383 CheckCanonicalEquivalence(c, test); | 1384 CheckCanonicalEquivalence(c, test); |
| 1384 continue; | 1385 continue; |
| 1385 } | 1386 } |
| 1386 CHECK_EQ(Min(upper, lower), test); | 1387 CHECK_EQ(Min(upper, lower), test); |
| 1387 } | 1388 } |
| 1388 } | 1389 } |
| OLD | NEW |