Added
Link Here
|
1 |
commit 182d9c05e78b1ddb1cb8242cd3628a7855a0336f |
2 |
Author: Andrey Kosyakov <caseq@chromium.org> |
3 |
Date: 2023-08-17T13:50:11-07:00 |
4 |
|
5 |
Define UChar as char16_t |
6 |
|
7 |
We used to have UChar defined as uint16_t which does not go along |
8 |
with STL these days if you try to have an std::basic_string<> of it, |
9 |
as there are no standard std::char_traits<> specialization for uint16_t. |
10 |
|
11 |
This switches UChar to char16_t where practical, introducing a few |
12 |
compatibility shims to keep CL size small, as (1) this would likely |
13 |
have to be back-ported and (2) crdtp extensively uses uint16_t for |
14 |
wide chars. |
15 |
|
16 |
Bug: b:296390693 |
17 |
Change-Id: I66a32d8f0050915225b187de56896c26dd76163d |
18 |
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4789966 |
19 |
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> |
20 |
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org> |
21 |
Auto-Submit: Andrey Kosyakov <caseq@chromium.org> |
22 |
Cr-Commit-Position: refs/heads/main@{#89559} |
23 |
|
24 |
diff --git deps/v8/src/inspector/string-16.cc deps/v8/src/inspector/string-16.cc |
25 |
index a8b786a8166..6df9963e970 100644 |
26 |
--- deps/v8/src/inspector/string-16.cc |
27 |
+++ deps/v8/src/inspector/string-16.cc |
28 |
@@ -27,7 +27,7 @@ bool isSpaceOrNewLine(UChar c) { |
29 |
return isASCII(c) && c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9)); |
30 |
} |
31 |
|
32 |
-int64_t charactersToInteger(const UChar* characters, size_t length, |
33 |
+int64_t charactersToInteger(const uint16_t* characters, size_t length, |
34 |
bool* ok = nullptr) { |
35 |
std::vector<char> buffer; |
36 |
buffer.reserve(length + 1); |
37 |
@@ -50,6 +50,8 @@ int64_t charactersToInteger(const UChar* characters, size_t length, |
38 |
|
39 |
String16::String16(const UChar* characters, size_t size) |
40 |
: m_impl(characters, size) {} |
41 |
+String16::String16(const uint16_t* characters, size_t size) |
42 |
+ : m_impl(reinterpret_cast<const UChar*>(characters), size) {} |
43 |
|
44 |
String16::String16(const UChar* characters) : m_impl(characters) {} |
45 |
|
46 |
@@ -241,6 +243,10 @@ String16 String16::fromUTF16LE(const UChar* stringStart, size_t length) { |
47 |
#endif // V8_TARGET_BIG_ENDIAN |
48 |
} |
49 |
|
50 |
+String16 String16::fromUTF16LE(const uint16_t* stringStart, size_t length) { |
51 |
+ return fromUTF16LE(reinterpret_cast<const UChar*>(stringStart), length); |
52 |
+} |
53 |
+ |
54 |
std::string String16::utf8() const { |
55 |
return UTF16ToUTF8(m_impl.data(), m_impl.size()); |
56 |
} |
57 |
diff --git deps/v8/src/inspector/string-16.h deps/v8/src/inspector/string-16.h |
58 |
index 1678ffb2e1e..d9f6c466ab1 100644 |
59 |
--- deps/v8/src/inspector/string-16.h |
60 |
+++ deps/v8/src/inspector/string-16.h |
61 |
@@ -6,6 +6,7 @@ |
62 |
#define V8_INSPECTOR_STRING_16_H_ |
63 |
|
64 |
#include <stdint.h> |
65 |
+#include <uchar.h> |
66 |
|
67 |
#include <cctype> |
68 |
#include <climits> |
69 |
@@ -18,7 +19,7 @@ |
70 |
|
71 |
namespace v8_inspector { |
72 |
|
73 |
-using UChar = uint16_t; |
74 |
+using UChar = char16_t; |
75 |
|
76 |
class String16 { |
77 |
public: |
78 |
@@ -28,6 +29,7 @@ class String16 { |
79 |
String16(const String16&) V8_NOEXCEPT = default; |
80 |
String16(String16&&) V8_NOEXCEPT = default; |
81 |
String16(const UChar* characters, size_t size); |
82 |
+ String16(const uint16_t* characters, size_t size); |
83 |
V8_EXPORT String16(const UChar* characters); |
84 |
V8_EXPORT String16(const char* characters); |
85 |
String16(const char* characters, size_t size); |
86 |
@@ -49,7 +51,9 @@ class String16 { |
87 |
int toInteger(bool* ok = nullptr) const; |
88 |
std::pair<size_t, size_t> getTrimmedOffsetAndLength() const; |
89 |
String16 stripWhiteSpace() const; |
90 |
- const UChar* characters16() const { return m_impl.c_str(); } |
91 |
+ const uint16_t* characters16() const { |
92 |
+ return reinterpret_cast<const uint16_t*>(m_impl.c_str()); |
93 |
+ } |
94 |
size_t length() const { return m_impl.length(); } |
95 |
bool isEmpty() const { return !m_impl.length(); } |
96 |
UChar operator[](size_t index) const { return m_impl[index]; } |
97 |
@@ -79,6 +83,8 @@ class String16 { |
98 |
// On Big endian architectures, byte order needs to be flipped. |
99 |
V8_EXPORT static String16 fromUTF16LE(const UChar* stringStart, |
100 |
size_t length); |
101 |
+ V8_EXPORT static String16 fromUTF16LE(const uint16_t* stringStart, |
102 |
+ size_t length); |
103 |
|
104 |
std::size_t hash() const { |
105 |
if (!hash_code) { |
106 |
diff --git deps/v8/src/inspector/v8-string-conversions.cc deps/v8/src/inspector/v8-string-conversions.cc |
107 |
index 0c75e66b972..8cf19be816c 100644 |
108 |
--- deps/v8/src/inspector/v8-string-conversions.cc |
109 |
+++ deps/v8/src/inspector/v8-string-conversions.cc |
110 |
@@ -12,7 +12,7 @@ |
111 |
|
112 |
namespace v8_inspector { |
113 |
namespace { |
114 |
-using UChar = uint16_t; |
115 |
+using UChar = char16_t; |
116 |
using UChar32 = uint32_t; |
117 |
|
118 |
bool isASCII(UChar c) { return !(c & ~0x7F); } |
119 |
@@ -386,7 +386,7 @@ std::string UTF16ToUTF8(const UChar* stringStart, size_t length) { |
120 |
|
121 |
std::basic_string<UChar> UTF8ToUTF16(const char* stringStart, size_t length) { |
122 |
if (!stringStart || !length) return std::basic_string<UChar>(); |
123 |
- std::vector<uint16_t> buffer(length); |
124 |
+ std::vector<UChar> buffer(length); |
125 |
UChar* bufferStart = buffer.data(); |
126 |
|
127 |
UChar* bufferCurrent = bufferStart; |
128 |
@@ -395,7 +395,7 @@ std::basic_string<UChar> UTF8ToUTF16(const char* stringStart, size_t length) { |
129 |
reinterpret_cast<const char*>(stringStart + length), |
130 |
&bufferCurrent, bufferCurrent + buffer.size(), nullptr, |
131 |
true) != conversionOK) |
132 |
- return std::basic_string<uint16_t>(); |
133 |
+ return std::basic_string<UChar>(); |
134 |
size_t utf16Length = bufferCurrent - bufferStart; |
135 |
return std::basic_string<UChar>(bufferStart, bufferStart + utf16Length); |
136 |
} |
137 |
diff --git deps/v8/src/inspector/v8-string-conversions.h deps/v8/src/inspector/v8-string-conversions.h |
138 |
index eb33c6816a5..1126255dac2 100644 |
139 |
--- deps/v8/src/inspector/v8-string-conversions.h |
140 |
+++ deps/v8/src/inspector/v8-string-conversions.h |
141 |
@@ -5,14 +5,16 @@ |
142 |
#ifndef V8_INSPECTOR_V8_STRING_CONVERSIONS_H_ |
143 |
#define V8_INSPECTOR_V8_STRING_CONVERSIONS_H_ |
144 |
|
145 |
+#include <uchar.h> |
146 |
+ |
147 |
#include <cstdint> |
148 |
#include <string> |
149 |
|
150 |
// Conversion routines between UT8 and UTF16, used by string-16.{h,cc}. You may |
151 |
// want to use string-16.h directly rather than these. |
152 |
namespace v8_inspector { |
153 |
-std::basic_string<uint16_t> UTF8ToUTF16(const char* stringStart, size_t length); |
154 |
-std::string UTF16ToUTF8(const uint16_t* stringStart, size_t length); |
155 |
+std::basic_string<char16_t> UTF8ToUTF16(const char* stringStart, size_t length); |
156 |
+std::string UTF16ToUTF8(const char16_t* stringStart, size_t length); |
157 |
} // namespace v8_inspector |
158 |
|
159 |
#endif // V8_INSPECTOR_V8_STRING_CONVERSIONS_H_ |
160 |
diff --git deps/v8/third_party/inspector_protocol/crdtp/test_platform_v8.cc deps/v8/third_party/inspector_protocol/crdtp/test_platform_v8.cc |
161 |
index c9d89eaa42f..1a46d781b89 100644 |
162 |
--- deps/v8/third_party/inspector_protocol/crdtp/test_platform_v8.cc |
163 |
+++ deps/v8/third_party/inspector_protocol/crdtp/test_platform_v8.cc |
164 |
@@ -11,13 +11,16 @@ |
165 |
namespace v8_crdtp { |
166 |
|
167 |
std::string UTF16ToUTF8(span<uint16_t> in) { |
168 |
- return v8_inspector::UTF16ToUTF8(in.data(), in.size()); |
169 |
+ return v8_inspector::UTF16ToUTF8(reinterpret_cast<const char16_t*>(in.data()), |
170 |
+ in.size()); |
171 |
} |
172 |
|
173 |
std::vector<uint16_t> UTF8ToUTF16(span<uint8_t> in) { |
174 |
- std::basic_string<uint16_t> utf16 = v8_inspector::UTF8ToUTF16( |
175 |
+ std::basic_string<char16_t> utf16 = v8_inspector::UTF8ToUTF16( |
176 |
reinterpret_cast<const char*>(in.data()), in.size()); |
177 |
- return std::vector<uint16_t>(utf16.begin(), utf16.end()); |
178 |
+ return std::vector<uint16_t>( |
179 |
+ reinterpret_cast<const uint16_t*>(utf16.data()), |
180 |
+ reinterpret_cast<const uint16_t*>(utf16.data()) + utf16.size()); |
181 |
} |
182 |
|
183 |
} // namespace v8_crdtp |