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

Unified Diff: test/cctest/test-code-stub-assembler.cc

Issue 2461363002: [stubs]: Support 1->2 byte copies in CopyStringCharacters (Closed)
Patch Set: Review feedback Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/zone/zone.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-code-stub-assembler.cc
diff --git a/test/cctest/test-code-stub-assembler.cc b/test/cctest/test-code-stub-assembler.cc
index 45c4aefec41edd46482f3dee4cf905cdcc91f912..7fbc69a56a481c8bd2a79e5f870004a683a75060 100644
--- a/test/cctest/test-code-stub-assembler.cc
+++ b/test/cctest/test-code-stub-assembler.cc
@@ -1787,5 +1787,141 @@ TEST(PopAndReturnVariable) {
}
}
+TEST(OneToTwoByteStringCopy) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+
+ CodeStubAssemblerTester m(isolate, 2);
+
+ m.CopyStringCharacters(
+ m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
+ m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
+ String::ONE_BYTE_ENCODING, String::TWO_BYTE_ENCODING,
+ CodeStubAssembler::SMI_PARAMETERS);
+ m.Return(m.SmiConstant(Smi::FromInt(0)));
+
+ Handle<Code> code = m.GenerateCode();
+ CHECK(!code.is_null());
+
+ Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
+ uc16 array[] = {1000, 1001, 1002, 1003, 1004};
+ Vector<const uc16> str(array);
+ Handle<String> string2 =
+ isolate->factory()->NewStringFromTwoByte(str).ToHandleChecked();
+ FunctionTester ft(code, 2);
+ ft.Call(string1, string2);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
+}
+
+TEST(OneToOneByteStringCopy) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+
+ CodeStubAssemblerTester m(isolate, 2);
+
+ m.CopyStringCharacters(
+ m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
+ m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
+ String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING,
+ CodeStubAssembler::SMI_PARAMETERS);
+ m.Return(m.SmiConstant(Smi::FromInt(0)));
+
+ Handle<Code> code = m.GenerateCode();
+ CHECK(!code.is_null());
+
+ Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
+ uint8_t array[] = {100, 101, 102, 103, 104};
+ Vector<const uint8_t> str(array);
+ Handle<String> string2 =
+ isolate->factory()->NewStringFromOneByte(str).ToHandleChecked();
+ FunctionTester ft(code, 2);
+ ft.Call(string1, string2);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[2],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[3],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[4],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
+}
+
+TEST(OneToOneByteStringCopyNonZeroStart) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+
+ CodeStubAssemblerTester m(isolate, 2);
+
+ m.CopyStringCharacters(
+ m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
+ m.SmiConstant(Smi::FromInt(3)), m.SmiConstant(Smi::FromInt(2)),
+ String::ONE_BYTE_ENCODING, String::ONE_BYTE_ENCODING,
+ CodeStubAssembler::SMI_PARAMETERS);
+ m.Return(m.SmiConstant(Smi::FromInt(0)));
+
+ Handle<Code> code = m.GenerateCode();
+ CHECK(!code.is_null());
+
+ Handle<String> string1 = isolate->factory()->InternalizeUtf8String("abcde");
+ uint8_t array[] = {100, 101, 102, 103, 104};
+ Vector<const uint8_t> str(array);
+ Handle<String> string2 =
+ isolate->factory()->NewStringFromOneByte(str).ToHandleChecked();
+ FunctionTester ft(code, 2);
+ ft.Call(string1, string2);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[0],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[3]);
+ CHECK_EQ(Handle<SeqOneByteString>::cast(string1)->GetChars()[1],
+ Handle<SeqOneByteString>::cast(string2)->GetChars()[4]);
+ CHECK_EQ(100, Handle<SeqOneByteString>::cast(string2)->GetChars()[0]);
+ CHECK_EQ(101, Handle<SeqOneByteString>::cast(string2)->GetChars()[1]);
+ CHECK_EQ(102, Handle<SeqOneByteString>::cast(string2)->GetChars()[2]);
+}
+
+TEST(TwoToTwoByteStringCopy) {
+ Isolate* isolate(CcTest::InitIsolateOnce());
+
+ CodeStubAssemblerTester m(isolate, 2);
+
+ m.CopyStringCharacters(
+ m.Parameter(0), m.Parameter(1), m.SmiConstant(Smi::FromInt(0)),
+ m.SmiConstant(Smi::FromInt(0)), m.SmiConstant(Smi::FromInt(5)),
+ String::TWO_BYTE_ENCODING, String::TWO_BYTE_ENCODING,
+ CodeStubAssembler::SMI_PARAMETERS);
+ m.Return(m.SmiConstant(Smi::FromInt(0)));
+
+ Handle<Code> code = m.GenerateCode();
+ CHECK(!code.is_null());
+
+ uc16 array1[] = {2000, 2001, 2002, 2003, 2004};
+ Vector<const uc16> str1(array1);
+ Handle<String> string1 =
+ isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked();
+ uc16 array2[] = {1000, 1001, 1002, 1003, 1004};
+ Vector<const uc16> str2(array2);
+ Handle<String> string2 =
+ isolate->factory()->NewStringFromTwoByte(str2).ToHandleChecked();
+ FunctionTester ft(code, 2);
+ ft.Call(string1, string2);
+ CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[0],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[0]);
+ CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[1],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[1]);
+ CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[2],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[2]);
+ CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[3],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[3]);
+ CHECK_EQ(Handle<SeqTwoByteString>::cast(string1)->GetChars()[4],
+ Handle<SeqTwoByteString>::cast(string2)->GetChars()[4]);
+}
+
} // namespace internal
} // namespace v8
« no previous file with comments | « src/zone/zone.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698