Commit 343eeb15 authored by Milad Farazmand's avatar Milad Farazmand Committed by Commit Bot

[inspector] Remove extra byte swapping on BE machines

With "Value::parseBinary" now being revamped by https://crrev.com/c/2020518
and making use of "cbor::ParseCBOR", the extra endianness check
is not needed anymore as "ParseCBOR" already switches
the byte order in this line:

crdtp/cbor.cc
void ParseUTF16String(CBORTokenizer* tokenizer, ParserHandler* out) {
  ....
  for (size_t ii = 0; ii < rep.size(); ii += 2)
  value.push_back((rep[ii + 1] << 8) | rep[ii]);
  ...

"String16EndianTest" does not go through the newly added pipeline
and "ParseUTF16String" is never used which makes the test redundant.

Change-Id: I6ad59fef7036c70d475b492407fd394977ca98f4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2038716
Commit-Queue: Milad Farazmand <miladfar@ca.ibm.com>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66160}
parent 8732596c
......@@ -208,21 +208,8 @@ String16 String16::fromUTF8(const char* stringStart, size_t length) {
return String16(UTF8ToUTF16(stringStart, length));
}
String16 String16::fromUTF16LE(const UChar* stringStart, size_t length) {
#ifdef V8_TARGET_BIG_ENDIAN
// Need to flip the byte order on big endian machines.
String16Builder builder;
builder.reserveCapacity(length);
for (size_t i = 0; i < length; i++) {
const UChar utf16be_char =
stringStart[i] << 8 | (stringStart[i] >> 8 & 0x00FF);
builder.append(utf16be_char);
}
return builder.toString();
#else
// No need to do anything on little endian machines.
String16 String16::fromUTF16(const UChar* stringStart, size_t length) {
return String16(stringStart, length);
#endif // V8_TARGET_BIG_ENDIAN
}
std::string String16::utf8() const {
......
......@@ -70,11 +70,7 @@ class String16 {
// Convenience methods.
V8_EXPORT std::string utf8() const;
V8_EXPORT static String16 fromUTF8(const char* stringStart, size_t length);
// Instantiates a String16 in native endianness from UTF16 LE.
// On Big endian architectures, byte order needs to be flipped.
V8_EXPORT static String16 fromUTF16LE(const UChar* stringStart,
size_t length);
V8_EXPORT static String16 fromUTF16(const UChar* stringStart, size_t length);
std::size_t hash() const {
if (!hash_code) {
......
......@@ -71,7 +71,7 @@ class StringUtil {
}
static String fromUTF16LE(const uint16_t* data, size_t length) {
return String16::fromUTF16LE(data, length);
return String16::fromUTF16(data, length);
}
static const uint8_t* CharactersLatin1(const String& s) { return nullptr; }
......
......@@ -9,9 +9,7 @@
#include "include/v8-inspector.h"
#include "include/v8.h"
#include "src/inspector/protocol/Runtime.h"
#include "src/inspector/string-16.h"
using v8_inspector::String16;
using v8_inspector::StringBuffer;
using v8_inspector::StringView;
using v8_inspector::V8ContextInfo;
......@@ -65,16 +63,3 @@ TEST(WrapInsideWrapOnInterrupt) {
isolate->RequestInterrupt(&WrapOnInterrupt, session.get());
session->wrapObject(env.local(), v8::Null(isolate), object_group_view, false);
}
TEST(String16EndianTest) {
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 expected_str = expected;
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