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