Commit e62c8282 authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

[inspector] fix typo in fromUTF16LE and cleanup test

Bug: v8:9355
Change-Id: I42a683f9480435499e603083e844a47150ae57c8
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1676244Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarAlexei Filippov <alph@chromium.org>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#62379}
parent b20ecdbd
......@@ -207,7 +207,7 @@ String16 String16::fromUTF16LE(const UChar* stringStart, size_t length) {
builder.reserveCapacity(length);
for (size_t i = 0; i < length; i++) {
const UChar utf16be_char =
utf16le_str[i] << 8 | (utf16le_str[i] >> 8 & 0x00FF);
stringStart[i] << 8 | (stringStart[i] >> 8 & 0x00FF);
builder.append(utf16be_char);
}
return builder.toString();
......
......@@ -26,7 +26,7 @@ class String16 {
String16(const String16&) V8_NOEXCEPT = default;
String16(String16&&) V8_NOEXCEPT = default;
String16(const UChar* characters, size_t size);
String16(const UChar* characters); // NOLINT(runtime/explicit)
V8_EXPORT String16(const UChar* characters); // NOLINT(runtime/explicit)
String16(const char* characters); // NOLINT(runtime/explicit)
String16(const char* characters, size_t size);
explicit String16(const std::basic_string<UChar>& impl);
......
......@@ -67,14 +67,14 @@ TEST(WrapInsideWrapOnInterrupt) {
}
TEST(String16EndianTest) {
const char* utf8 =
"Hello, \xf0\x9f\x8c\x8e."; // "Hello, earth." in utf8 encoding
const v8_inspector::UChar* expected =
reinterpret_cast<const v8_inspector::UChar*>(u"Hello, \U0001F30E.");
const uint16_t* utf16le = reinterpret_cast<const uint16_t*>(
"H\0e\0l\0l\0o\0,\0 \0\x3c\xd8\x0e\xdf.\0"); // Same text in UTF16LE
// encoding
String16 utf16_str = String16::fromUTF16LE(utf16le, 10);
String16 utf8_str = String16::fromUTF8(utf8, strlen(utf8));
String16 expected_str = expected;
CHECK_EQ(utf16_str.utf8(), utf8_str.utf8());
CHECK_EQ(utf16_str, expected_str);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment