Skip to content

Commit ed83538

Browse files
JSC fix utf8 string creation
1 parent 3794fde commit ed83538

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

Core/Node-API/Source/js_native_api_javascriptcore.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <stdexcept>
88
#include <string>
99
#include <vector>
10-
#include <locale>
11-
#include <codecvt>
1210

1311
struct napi_callback_info__ {
1412
napi_value newTarget;
@@ -108,9 +106,11 @@ namespace {
108106
return JSStringCreateWithUTF8CString(string);
109107
}
110108

111-
std::u16string u16str{std::wstring_convert<
112-
std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(string, string + length)};
113-
return JSStringCreateWithCharacters(reinterpret_cast<JSChar*>(u16str.data()), u16str.size());
109+
// Create a null-terminated copy so JSStringCreateWithUTF8CString can be
110+
// used directly, avoiding the deprecated and error-prone
111+
// std::wstring_convert / std::codecvt_utf8_utf16 path.
112+
std::string str(string, length);
113+
return JSStringCreateWithUTF8CString(str.c_str());
114114
}
115115

116116
JSString(JSStringRef string)

0 commit comments

Comments
 (0)