View | Details | Raw Unified | Return to bug 282514
Collapse All | Expand All

(-)b/lang/v8/files/patch-182d9c05e78 (+180 lines)
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 src/inspector/string-16.cc src/inspector/string-16.cc
25
index a8b786a8166..6df9963e970 100644
26
--- src/inspector/string-16.cc
27
+++ 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 @@ String16::String16(const UChar* characters, size_t siz
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
@@ -231,6 +233,10 @@ String16 String16::fromUTF16LE(const UChar* stringStar
47
   // No need to do anything on little endian machines.
48
   return String16(stringStart, length);
49
 #endif  // V8_TARGET_BIG_ENDIAN
50
+}
51
+
52
+String16 String16::fromUTF16LE(const uint16_t* stringStart, size_t length) {
53
+  return fromUTF16LE(reinterpret_cast<const UChar*>(stringStart), length);
54
 }
55
 
56
 std::string String16::utf8() const {
57
diff --git src/inspector/string-16.h src/inspector/string-16.h
58
index 1678ffb2e1e..d9f6c466ab1 100644
59
--- src/inspector/string-16.h
60
+++ 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
@@ -17,7 +18,7 @@ namespace v8_inspector {
70
 
71
 namespace v8_inspector {
72
 
73
-using UChar = uint16_t;
74
+using UChar = char16_t;
75
 
76
 class String16 {
77
  public:
78
@@ -27,6 +28,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
@@ -47,7 +49,9 @@ class String16 {
87
   uint64_t toUInt64(bool* ok = nullptr) const;
88
   int toInteger(bool* ok = nullptr) 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
@@ -76,6 +80,8 @@ class String16 {
98
   // Instantiates a String16 in native endianness from UTF16 LE.
99
   // On Big endian architectures, byte order needs to be flipped.
100
   V8_EXPORT static String16 fromUTF16LE(const UChar* stringStart,
101
+                                        size_t length);
102
+  V8_EXPORT static String16 fromUTF16LE(const uint16_t* stringStart,
103
                                         size_t length);
104
 
105
   std::size_t hash() const {
106
diff --git src/inspector/v8-string-conversions.cc src/inspector/v8-string-conversions.cc
107
index 0c75e66b972..8cf19be816c 100644
108
--- src/inspector/v8-string-conversions.cc
109
+++ src/inspector/v8-string-conversions.cc
110
@@ -12,7 +12,7 @@ namespace {
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::basic_string<UChar> UTF8ToUTF16(const char* strin
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* strin
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 src/inspector/v8-string-conversions.h src/inspector/v8-string-conversions.h
138
index eb33c6816a5..1126255dac2 100644
139
--- src/inspector/v8-string-conversions.h
140
+++ src/inspector/v8-string-conversions.h
141
@@ -5,13 +5,15 @@
142
 #ifndef V8_INSPECTOR_V8_STRING_CONVERSIONS_H_
143
 #define V8_INSPECTOR_V8_STRING_CONVERSIONS_H_
144
 
145
+#include <uchar.h>
146
+
147
 #include <string>
148
 
149
 // Conversion routines between UT8 and UTF16, used by string-16.{h,cc}. You may
150
 // want to use string-16.h directly rather than these.
151
 namespace v8_inspector {
152
-std::basic_string<uint16_t> UTF8ToUTF16(const char* stringStart, size_t length);
153
-std::string UTF16ToUTF8(const uint16_t* stringStart, size_t length);
154
+std::basic_string<char16_t> UTF8ToUTF16(const char* stringStart, size_t length);
155
+std::string UTF16ToUTF8(const char16_t* stringStart, size_t length);
156
 }  // namespace v8_inspector
157
 
158
 #endif  // V8_INSPECTOR_V8_STRING_CONVERSIONS_H_
159
--- third_party/inspector_protocol/crdtp/test_platform_v8.cc.orig	2022-07-14 12:21:06 UTC
160
+++ third_party/inspector_protocol/crdtp/test_platform_v8.cc
161
@@ -11,13 +11,16 @@ std::string UTF16ToUTF8(span<uint16_t> in) {
162
 namespace v8_crdtp {
163
 
164
 std::string UTF16ToUTF8(span<uint16_t> in) {
165
-  return v8_inspector::UTF16ToUTF8(in.data(), in.size());
166
+  return v8_inspector::UTF16ToUTF8(reinterpret_cast<const char16_t*>(in.data()),
167
+                                   in.size());
168
 }
169
 
170
 std::vector<uint16_t> UTF8ToUTF16(span<uint8_t> in) {
171
-  std::basic_string<uint16_t> utf16 = v8_inspector::UTF8ToUTF16(
172
+  std::basic_string<char16_t> utf16 = v8_inspector::UTF8ToUTF16(
173
       reinterpret_cast<const char*>(in.data()), in.size());
174
-  return std::vector<uint16_t>(utf16.begin(), utf16.end());
175
+  return std::vector<uint16_t>(
176
+      reinterpret_cast<const uint16_t*>(utf16.data()),
177
+      reinterpret_cast<const uint16_t*>(utf16.data()) + utf16.size());
178
 }
179
 
180
 }  // namespace v8_crdtp

Return to bug 282514