Skip to content

Commit

Permalink
Revert
Browse files Browse the repository at this point in the history
  • Loading branch information
dumganhar committed Jul 31, 2024
1 parent 6b9ec3e commit 03e4270
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions native/cocos/bindings/jswrapper/v8/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,11 @@
#include "ScriptEngine.h"
#include "base/Log.h"
#include "base/Macros.h"
#include "base/UTF8.h"

namespace se {

namespace internal {

namespace {

inline v8::MaybeLocal<v8::String> 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<const uint16_t*>(u16Str.data()), type, static_cast<int>(u16Str.length()));
}
return {};
}

} // namespace {

void jsToSeArgs(const v8::FunctionCallbackInfo<v8::Value> &v8args, ValueArray &outArr) {
v8::Isolate *isolate = v8args.GetIsolate();
for (int i = 0; i < v8args.Length(); i++) {
Expand All @@ -75,8 +62,7 @@ void seToJsValue(v8::Isolate *isolate, const Value &v, v8::Local<v8::Value> *out
*outJsVal = v8::Number::New(isolate, v.toDouble());
break;
case Value::Type::String: {
// v8::MaybeLocal<v8::String> str = v8::String::NewFromUtf8(isolate, v.toString().data(), v8::NewStringType::kNormal, static_cast<int>(v.toString().length()));
auto str = createV8StringFromUtf8(isolate, v.toString(), v8::NewStringType::kNormal);
v8::MaybeLocal<v8::String> str = v8::String::NewFromUtf8(isolate, v.toString().data(), v8::NewStringType::kNormal, static_cast<int>(v.toString().length()));
if (!str.IsEmpty()) {
*outJsVal = str.ToLocalChecked();
} else {
Expand Down Expand Up @@ -195,8 +181,7 @@ void setReturnValueTemplate(const Value &data, const T &argv) {
break;
}
case Value::Type::String: {
// v8::MaybeLocal<v8::String> value = v8::String::NewFromUtf8(argv.GetIsolate(), data.toString().c_str(), v8::NewStringType::kNormal);
auto value = createV8StringFromUtf8(argv.GetIsolate(), data.toString(), v8::NewStringType::kNormal);
v8::MaybeLocal<v8::String> value = v8::String::NewFromUtf8(argv.GetIsolate(), data.toString().c_str(), v8::NewStringType::kNormal);
CC_ASSERT(!value.IsEmpty());
argv.GetReturnValue().Set(value.ToLocalChecked());
break;
Expand Down

0 comments on commit 03e4270

Please sign in to comment.