Skip to content

Commit cf73f5c

Browse files
committed
src: use V8 API for string conversion in inspector
Remove use of Intl in inspector code so that compiling without Intl does not require disabling the inspector.
1 parent 52b1904 commit cf73f5c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/inspector/main_thread_interface.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#include "v8-inspector.h"
66
#include "util-inl.h"
77

8-
#include <unicode/unistr.h>
9-
108
#include <functional>
119
#include <memory>
1210

@@ -289,10 +287,20 @@ Deletable* MainThreadInterface::GetObjectIfExists(int id) {
289287
}
290288

291289
std::unique_ptr<StringBuffer> Utf8ToStringView(const std::string& message) {
292-
icu::UnicodeString utf16 = icu::UnicodeString::fromUTF8(
293-
icu::StringPiece(message.data(), message.length()));
294-
StringView view(reinterpret_cast<const uint16_t*>(utf16.getBuffer()),
295-
utf16.length());
290+
v8::Isolate* isolate = v8::Isolate::TryGetCurrent();
291+
CHECK_NOT_NULL(isolate);
292+
293+
v8::Local<v8::String> myString =
294+
v8::String::NewFromUtf8(isolate,
295+
message.data(),
296+
v8::NewStringType::kNormal,
297+
message.length()).ToLocalChecked();
298+
299+
// Length()+1 to account for null terminator
300+
auto buffer = std::make_unique<uint16_t[]>(myString->Length()+1);
301+
myString->Write(isolate, buffer.get());
302+
StringView view(buffer.get(), myString->Length());
303+
296304
return StringBuffer::create(view);
297305
}
298306

0 commit comments

Comments
 (0)