|
22 | 22 |
|
23 | 23 | namespace v8_inspector { |
24 | 24 |
|
| 25 | +namespace { |
| 26 | +// Build an 8-bit `StringView` directly over a `std::string`'s storage. |
| 27 | +// V8 inspector messages on this side are ASCII/UTF-8 JSON, so the |
| 28 | +// previous `std::string -> std::vector<uint16_t> -> StringView` path |
| 29 | +// inflated each byte to two and then handed it to a 16-bit constructor. |
| 30 | +// Going straight through the 8-bit constructor avoids that doubling AND |
| 31 | +// dodges the libc++ deprecation that prompted the inspector's |
| 32 | +// `UChar = uint16_t -> char16_t` switch. |
| 33 | +StringView Make8BitStringView(const std::string& value) { |
| 34 | + return StringView(reinterpret_cast<const uint8_t*>(value.data()), |
| 35 | + value.size()); |
| 36 | +} |
| 37 | +} // namespace |
| 38 | + |
25 | 39 | #define NOTIFICATION(name) \ |
26 | 40 | [[NSString stringWithFormat:@"%@:NativeScript.Debug.%s", \ |
27 | 41 | [[NSBundle mainBundle] bundleIdentifier], name] UTF8String] |
|
257 | 271 | } |
258 | 272 |
|
259 | 273 | void JsV8InspectorClient::dispatchMessage(const std::string& message) { |
260 | | - std::vector<uint16_t> vector = tns::ToVector(message); |
261 | | - StringView messageView(vector.data(), vector.size()); |
| 274 | + StringView messageView = Make8BitStringView(message); |
262 | 275 | Isolate* isolate = isolate_; |
263 | 276 | v8::Locker locker(isolate); |
264 | 277 | Isolate::Scope isolate_scope(isolate); |
|
343 | 356 | auto returnString = GetReturnMessageFromDomainHandlerResult(result, requestId); |
344 | 357 |
|
345 | 358 | if (returnString.size() > 0) { |
346 | | - std::vector<uint16_t> vector = tns::ToVector(returnString); |
347 | | - StringView messageView(vector.data(), vector.size()); |
| 359 | + StringView messageView = Make8BitStringView(returnString); |
348 | 360 | auto msg = StringBuffer::create(messageView); |
349 | 361 | this->sendNotification(std::move(msg)); |
350 | 362 | } |
|
486 | 498 | Local<v8::String> arg = args[0].As<v8::String>(); |
487 | 499 | std::string message = tns::ToString(isolate, arg); |
488 | 500 |
|
489 | | - std::vector<uint16_t> vector = tns::ToVector(message); |
490 | | - StringView messageView(vector.data(), vector.size()); |
| 501 | + StringView messageView = Make8BitStringView(message); |
491 | 502 | auto msg = StringBuffer::create(messageView); |
492 | 503 | client->sendNotification(std::move(msg)); |
493 | 504 | } |
|
0 commit comments