diff --git a/unreal/Puerts/Source/JsEnv/Private/V8Utils.cpp b/unreal/Puerts/Source/JsEnv/Private/V8Utils.cpp new file mode 100644 index 0000000000..dd5f15eae3 --- /dev/null +++ b/unreal/Puerts/Source/JsEnv/Private/V8Utils.cpp @@ -0,0 +1,19 @@ +#include + +v8::Local puerts::FV8Utils::ToV8String(v8::Isolate* Isolate, const TCHAR* String) +{ +#if WITH_QUICKJS + return v8::String::NewFromUtf8(Isolate, TCHAR_TO_UTF8(String), v8::NewStringType::kNormal).ToLocalChecked(); +#else + return v8::String::NewFromTwoByte(Isolate, TCHAR_TO_UTF16(String), v8::NewStringType::kNormal).ToLocalChecked(); +#endif +} + +FString puerts::FV8Utils::ToFString(v8::Isolate* Isolate, v8::Local Value) +{ +#if WITH_QUICKJS + return UTF8_TO_TCHAR(*(v8::String::Utf8Value(Isolate, Value))); +#else + return UTF16_TO_TCHAR(*(v8::String::Value(Isolate, Value))); +#endif +} \ No newline at end of file diff --git a/unreal/Puerts/Source/JsEnv/Public/V8Utils.h b/unreal/Puerts/Source/JsEnv/Public/V8Utils.h index 6289b6c6c2..5bf0efab27 100644 --- a/unreal/Puerts/Source/JsEnv/Public/V8Utils.h +++ b/unreal/Puerts/Source/JsEnv/Public/V8Utils.h @@ -34,7 +34,7 @@ enum ArgType EArgObject }; -class FV8Utils +class JSENV_API FV8Utils { public: FORCEINLINE static void ThrowException(v8::Isolate* Isolate, const FString& Message) @@ -96,7 +96,7 @@ class FV8Utils FORCEINLINE static v8::Local InternalString(v8::Isolate* Isolate, const FString& String) { - return v8::String::NewFromUtf8(Isolate, TCHAR_TO_UTF8(*String), v8::NewStringType::kNormal).ToLocalChecked(); + return ToV8String(Isolate, String); } FORCEINLINE static v8::Local InternalString(v8::Isolate* Isolate, const char* String) @@ -104,10 +104,7 @@ class FV8Utils return v8::String::NewFromUtf8(Isolate, String, v8::NewStringType::kNormal).ToLocalChecked(); } - FORCEINLINE static FString ToFString(v8::Isolate* Isolate, v8::Local Value) - { - return UTF8_TO_TCHAR(*(v8::String::Utf8Value(Isolate, Value))); - } + static FString ToFString(v8::Isolate* Isolate, v8::Local Value); FORCEINLINE static FName ToFName(v8::Isolate* Isolate, v8::Local Value) { @@ -146,10 +143,7 @@ class FV8Utils return ToV8String(Isolate, String.ToString()); } - FORCEINLINE static v8::Local ToV8String(v8::Isolate* Isolate, const TCHAR* String) - { - return v8::String::NewFromUtf8(Isolate, TCHAR_TO_UTF8(String), v8::NewStringType::kNormal).ToLocalChecked(); - } + static v8::Local ToV8String(v8::Isolate* Isolate, const TCHAR* String); FORCEINLINE static v8::Local ToV8String(v8::Isolate* Isolate, const char* String) {