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

Side by Side Diff: test/cctest/test-strings.cc

Issue 23480051: Correctly stringify mixed encoding indirect strings. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « src/json-stringifier.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 " (non_ascii[j] + external_non_ascii[i - j])) return 12;" 1010 " (non_ascii[j] + external_non_ascii[i - j])) return 12;"
1011 " }" 1011 " }"
1012 " }" 1012 " }"
1013 " return 0;" 1013 " return 0;"
1014 "};" 1014 "};"
1015 "test()"; 1015 "test()";
1016 CHECK_EQ(0, CompileRun(source)->Int32Value()); 1016 CHECK_EQ(0, CompileRun(source)->Int32Value());
1017 } 1017 }
1018 1018
1019 1019
1020 TEST(JSONStringifySliceMadeExternal) {
1021 Isolate* isolate = Isolate::Current();
1022 Zone zone(isolate);
1023 CcTest::InitializeVM();
1024
1025 // Create a sliced string from a two-byte string. The latter is turned
1026 // into a one-byte external string. Check that JSON.stringify works.
1027 { v8::HandleScope handle_scope(CcTest::isolate());
1028 v8::Handle<v8::String> underlying =
1029 CompileRun("var underlying = '\u2603bcdefghijklmnopqrstuvwxyz';"
1030 "underlying")->ToString();
1031 v8::Handle<v8::String> slice =
1032 CompileRun("var slice = underlying.slice(1);"
1033 "slice")->ToString();
1034 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
1035 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqTwoByteString());
1036
1037 int length = underlying->Length();
1038 uint8_t* one_byte = zone.NewArray<uint8_t>(length + 1);
1039 underlying->WriteOneByte(one_byte);
1040 AsciiResource* resource =
1041 new(&zone) AsciiResource(Vector<const char>(
1042 reinterpret_cast<char*>(one_byte), length));
1043 CHECK(underlying->MakeExternal(resource));
1044 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
1045 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalAsciiString());
1046
1047 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"",
1048 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)")));
1049 }
1050
1051 // Create a sliced string from a one-byte string. The latter is turned
1052 // into a two-byte external string. Check that JSON.stringify works.
1053 { v8::HandleScope handle_scope(CcTest::isolate());
1054 v8::Handle<v8::String> underlying =
1055 CompileRun("var underlying = 'abcdefghijklmnopqrstuvwxyz';"
1056 "underlying")->ToString();
1057 v8::Handle<v8::String> slice =
1058 CompileRun("var slice = underlying.slice(1);"
1059 "slice")->ToString();
1060 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
1061 CHECK(v8::Utils::OpenHandle(*underlying)->IsSeqOneByteString());
1062
1063 int length = underlying->Length();
1064 uc16* two_byte = zone.NewArray<uc16>(length + 1);
1065 underlying->Write(two_byte);
1066 Resource* resource =
1067 new(&zone) Resource(Vector<const uc16>(two_byte, length));
1068 CHECK(underlying->MakeExternal(resource));
1069 CHECK(v8::Utils::OpenHandle(*slice)->IsSlicedString());
1070 CHECK(v8::Utils::OpenHandle(*underlying)->IsExternalTwoByteString());
1071
1072 CHECK_EQ("\"bcdefghijklmnopqrstuvwxyz\"",
1073 *v8::String::Utf8Value(CompileRun("JSON.stringify(slice)")));
1074 }
1075 }
1076
1077
1020 TEST(CachedHashOverflow) { 1078 TEST(CachedHashOverflow) {
1021 // We incorrectly allowed strings to be tagged as array indices even if their 1079 // We incorrectly allowed strings to be tagged as array indices even if their
1022 // values didn't fit in the hash field. 1080 // values didn't fit in the hash field.
1023 // See http://code.google.com/p/v8/issues/detail?id=728 1081 // See http://code.google.com/p/v8/issues/detail?id=728
1024 Isolate* isolate = Isolate::Current(); 1082 Isolate* isolate = Isolate::Current();
1025 Zone zone(isolate); 1083 Zone zone(isolate);
1026 1084
1027 CcTest::InitializeVM(); 1085 CcTest::InitializeVM();
1028 v8::HandleScope handle_scope(CcTest::isolate()); 1086 v8::HandleScope handle_scope(CcTest::isolate());
1029 // Lines must be executed sequentially. Combining them into one script 1087 // Lines must be executed sequentially. Combining them into one script
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 CheckCanonicalEquivalence(c, test); 1407 CheckCanonicalEquivalence(c, test);
1350 continue; 1408 continue;
1351 } 1409 }
1352 if (upper != c && lower != c) { 1410 if (upper != c && lower != c) {
1353 CheckCanonicalEquivalence(c, test); 1411 CheckCanonicalEquivalence(c, test);
1354 continue; 1412 continue;
1355 } 1413 }
1356 CHECK_EQ(Min(upper, lower), test); 1414 CHECK_EQ(Min(upper, lower), test);
1357 } 1415 }
1358 } 1416 }
OLDNEW
« no previous file with comments | « src/json-stringifier.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698