diff --git a/native/cocos/bindings/jswrapper/v8/Utils.cpp b/native/cocos/bindings/jswrapper/v8/Utils.cpp index 6e5334253fa..1a2453f9074 100644 --- a/native/cocos/bindings/jswrapper/v8/Utils.cpp +++ b/native/cocos/bindings/jswrapper/v8/Utils.cpp @@ -33,11 +33,24 @@ #include "ScriptEngine.h" #include "base/Log.h" #include "base/Macros.h" + #include "base/UTF8.h" namespace se { namespace internal { +namespace { + +inline v8::MaybeLocal createV8StringFromUtf8(v8::Isolate* isolate, const ccstd::string &u8Str, v8::NewStringType type = v8::NewStringType::kNormal) { + std::u16string u16Str; + if (cc::StringUtils::UTF8ToUTF16(u8Str, u16Str)) { + return v8::String::NewFromTwoByte(isolate, reinterpret_cast(u16Str.data()), type, static_cast(u16Str.length())); + } + return {}; +} + +} // namespace { + void jsToSeArgs(const v8::FunctionCallbackInfo &v8args, ValueArray &outArr) { v8::Isolate *isolate = v8args.GetIsolate(); for (int i = 0; i < v8args.Length(); i++) { @@ -62,7 +75,8 @@ void seToJsValue(v8::Isolate *isolate, const Value &v, v8::Local *out *outJsVal = v8::Number::New(isolate, v.toDouble()); break; case Value::Type::String: { - v8::MaybeLocal str = v8::String::NewFromUtf8(isolate, v.toString().data(), v8::NewStringType::kNormal, static_cast(v.toString().length())); +// v8::MaybeLocal str = v8::String::NewFromUtf8(isolate, v.toString().data(), v8::NewStringType::kNormal, static_cast(v.toString().length())); + auto str = createV8StringFromUtf8(isolate, v.toString(), v8::NewStringType::kNormal); if (!str.IsEmpty()) { *outJsVal = str.ToLocalChecked(); } else { @@ -181,7 +195,8 @@ void setReturnValueTemplate(const Value &data, const T &argv) { break; } case Value::Type::String: { - v8::MaybeLocal value = v8::String::NewFromUtf8(argv.GetIsolate(), data.toString().c_str(), v8::NewStringType::kNormal); +// v8::MaybeLocal value = v8::String::NewFromUtf8(argv.GetIsolate(), data.toString().c_str(), v8::NewStringType::kNormal); + auto value = createV8StringFromUtf8(argv.GetIsolate(), data.toString(), v8::NewStringType::kNormal); CC_ASSERT(!value.IsEmpty()); argv.GetReturnValue().Set(value.ToLocalChecked()); break; diff --git a/native/external-config.json b/native/external-config.json index 45b7100d021..6fbc71bd2dd 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3.8.4-2" + "checkout": "v3.8.4-3" } } \ No newline at end of file