Skip to content

Commit fd56652

Browse files
caseqmarco-ippolito
authored andcommitted
deps: V8: cherry-pick 182d9c05e78b
Original commit message: Define UChar as char16_t We used to have UChar defined as uint16_t which does not go along with STL these days if you try to have an std::basic_string<> of it, as there are no standard std::char_traits<> specialization for uint16_t. This switches UChar to char16_t where practical, introducing a few compatibility shims to keep CL size small, as (1) this would likely have to be back-ported and (2) crdtp extensively uses uint16_t for wide chars. Bug: b:296390693 Change-Id: I66a32d8f0050915225b187de56896c26dd76163d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4789966 Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Commit-Queue: Jaroslav Sevcik <jarin@chromium.org> Auto-Submit: Andrey Kosyakov <caseq@chromium.org> Cr-Commit-Position: refs/heads/main@{#89559} Refs: v8/v8@182d9c0 PR-URL: #58342 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
1 parent 447481e commit fd56652

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.27',
39+
'v8_embedder_string': '-node.28',
4040

4141
##### V8 defaults for Node.js #####
4242

deps/v8/src/inspector/string-16.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bool isSpaceOrNewLine(UChar c) {
2727
return isASCII(c) && c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
2828
}
2929

30-
int64_t charactersToInteger(const UChar* characters, size_t length,
30+
int64_t charactersToInteger(const uint16_t* characters, size_t length,
3131
bool* ok = nullptr) {
3232
std::vector<char> buffer;
3333
buffer.reserve(length + 1);
@@ -50,6 +50,8 @@ int64_t charactersToInteger(const UChar* characters, size_t length,
5050

5151
String16::String16(const UChar* characters, size_t size)
5252
: m_impl(characters, size) {}
53+
String16::String16(const uint16_t* characters, size_t size)
54+
: m_impl(reinterpret_cast<const UChar*>(characters), size) {}
5355

5456
String16::String16(const UChar* characters) : m_impl(characters) {}
5557

@@ -241,6 +243,10 @@ String16 String16::fromUTF16LE(const UChar* stringStart, size_t length) {
241243
#endif // V8_TARGET_BIG_ENDIAN
242244
}
243245

246+
String16 String16::fromUTF16LE(const uint16_t* stringStart, size_t length) {
247+
return fromUTF16LE(reinterpret_cast<const UChar*>(stringStart), length);
248+
}
249+
244250
std::string String16::utf8() const {
245251
return UTF16ToUTF8(m_impl.data(), m_impl.size());
246252
}

deps/v8/src/inspector/string-16.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define V8_INSPECTOR_STRING_16_H_
77

88
#include <stdint.h>
9+
#include <uchar.h>
910

1011
#include <cctype>
1112
#include <climits>
@@ -17,7 +18,7 @@
1718

1819
namespace v8_inspector {
1920

20-
using UChar = uint16_t;
21+
using UChar = char16_t;
2122

2223
class String16 {
2324
public:
@@ -27,6 +28,7 @@ class String16 {
2728
String16(const String16&) V8_NOEXCEPT = default;
2829
String16(String16&&) V8_NOEXCEPT = default;
2930
String16(const UChar* characters, size_t size);
31+
String16(const uint16_t* characters, size_t size);
3032
V8_EXPORT String16(const UChar* characters);
3133
V8_EXPORT String16(const char* characters);
3234
String16(const char* characters, size_t size);
@@ -48,7 +50,9 @@ class String16 {
4850
int toInteger(bool* ok = nullptr) const;
4951
std::pair<size_t, size_t> getTrimmedOffsetAndLength() const;
5052
String16 stripWhiteSpace() const;
51-
const UChar* characters16() const { return m_impl.c_str(); }
53+
const uint16_t* characters16() const {
54+
return reinterpret_cast<const uint16_t*>(m_impl.c_str());
55+
}
5256
size_t length() const { return m_impl.length(); }
5357
bool isEmpty() const { return !m_impl.length(); }
5458
UChar operator[](size_t index) const { return m_impl[index]; }
@@ -78,6 +82,8 @@ class String16 {
7882
// On Big endian architectures, byte order needs to be flipped.
7983
V8_EXPORT static String16 fromUTF16LE(const UChar* stringStart,
8084
size_t length);
85+
V8_EXPORT static String16 fromUTF16LE(const uint16_t* stringStart,
86+
size_t length);
8187

8288
std::size_t hash() const {
8389
if (!hash_code) {

deps/v8/src/inspector/v8-string-conversions.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace v8_inspector {
1414
namespace {
15-
using UChar = uint16_t;
15+
using UChar = char16_t;
1616
using UChar32 = uint32_t;
1717

1818
bool isASCII(UChar c) { return !(c & ~0x7F); }
@@ -386,7 +386,7 @@ std::string UTF16ToUTF8(const UChar* stringStart, size_t length) {
386386

387387
std::basic_string<UChar> UTF8ToUTF16(const char* stringStart, size_t length) {
388388
if (!stringStart || !length) return std::basic_string<UChar>();
389-
std::vector<uint16_t> buffer(length);
389+
std::vector<UChar> buffer(length);
390390
UChar* bufferStart = buffer.data();
391391

392392
UChar* bufferCurrent = bufferStart;
@@ -395,7 +395,7 @@ std::basic_string<UChar> UTF8ToUTF16(const char* stringStart, size_t length) {
395395
reinterpret_cast<const char*>(stringStart + length),
396396
&bufferCurrent, bufferCurrent + buffer.size(), nullptr,
397397
true) != conversionOK)
398-
return std::basic_string<uint16_t>();
398+
return std::basic_string<UChar>();
399399
size_t utf16Length = bufferCurrent - bufferStart;
400400
return std::basic_string<UChar>(bufferStart, bufferStart + utf16Length);
401401
}

deps/v8/src/inspector/v8-string-conversions.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
#ifndef V8_INSPECTOR_V8_STRING_CONVERSIONS_H_
66
#define V8_INSPECTOR_V8_STRING_CONVERSIONS_H_
77

8+
#include <uchar.h>
9+
810
#include <cstdint>
911
#include <string>
1012

1113
// Conversion routines between UT8 and UTF16, used by string-16.{h,cc}. You may
1214
// want to use string-16.h directly rather than these.
1315
namespace v8_inspector {
14-
std::basic_string<uint16_t> UTF8ToUTF16(const char* stringStart, size_t length);
15-
std::string UTF16ToUTF8(const uint16_t* stringStart, size_t length);
16+
std::basic_string<char16_t> UTF8ToUTF16(const char* stringStart, size_t length);
17+
std::string UTF16ToUTF8(const char16_t* stringStart, size_t length);
1618
} // namespace v8_inspector
1719

1820
#endif // V8_INSPECTOR_V8_STRING_CONVERSIONS_H_

deps/v8/third_party/inspector_protocol/crdtp/test_platform_v8.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
namespace v8_crdtp {
1212

1313
std::string UTF16ToUTF8(span<uint16_t> in) {
14-
return v8_inspector::UTF16ToUTF8(in.data(), in.size());
14+
return v8_inspector::UTF16ToUTF8(reinterpret_cast<const char16_t*>(in.data()),
15+
in.size());
1516
}
1617

1718
std::vector<uint16_t> UTF8ToUTF16(span<uint8_t> in) {
18-
std::basic_string<uint16_t> utf16 = v8_inspector::UTF8ToUTF16(
19+
std::basic_string<char16_t> utf16 = v8_inspector::UTF8ToUTF16(
1920
reinterpret_cast<const char*>(in.data()), in.size());
20-
return std::vector<uint16_t>(utf16.begin(), utf16.end());
21+
return std::vector<uint16_t>(
22+
reinterpret_cast<const uint16_t*>(utf16.data()),
23+
reinterpret_cast<const uint16_t*>(utf16.data()) + utf16.size());
2124
}
2225

2326
} // namespace v8_crdtp

0 commit comments

Comments
 (0)