/* * Tencent is pleased to support the open source community by making Puerts available. * Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved. * Puerts is licensed under the BSD 3-Clause License, except for the third-party components listed in the file 'LICENSE' which may * be subject to their corresponding license terms. This file is subject to the terms and conditions defined in file 'LICENSE', * which is part of this source code package. */ #include "DataTransfer.h" #include "ObjectMapper.h" #if USING_IN_UNREAL_ENGINE #include "V8Utils.h" #endif namespace PUERTS_NAMESPACE { v8::Local DataTransfer::FindOrAddCData( v8::Isolate* Isolate, v8::Local Context, const void* TypeId, const void* Ptr, bool PassByPointer) { return IsolateData(Isolate)->FindOrAddCppObject( Isolate, Context, TypeId, const_cast(Ptr), PassByPointer); } bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) { return IsolateData(Isolate)->IsInstanceOfCppObject(Isolate, TypeId, JsObject); } v8::Local DataTransfer::UnRef(v8::Isolate* Isolate, const v8::Local& Value) { v8::Local Context = Isolate->GetCurrentContext(); v8::Local ReturnValue = Value->ToObject(Context).ToLocalChecked()->Get(Context, 0).ToLocalChecked(); return ReturnValue; } void DataTransfer::UpdateRef(v8::Isolate* Isolate, v8::Local Outer, const v8::Local& Value) { v8::Local Context = Isolate->GetCurrentContext(); auto Ret = Outer->ToObject(Context).ToLocalChecked()->Set(Context, 0, Value); } std::weak_ptr DataTransfer::GetJsEnvLifeCycleTracker(v8::Isolate* Isolate) { return IsolateData(Isolate)->GetJsEnvLifeCycleTracker(); } #if USING_IN_UNREAL_ENGINE FString DataTransfer::ToFString(v8::Isolate* Isolate, v8::Local Value) { return FV8Utils::ToFString(Isolate, Value); } v8::Local DataTransfer::FindOrAddObject( v8::Isolate* Isolate, v8::Local& Context, UClass* Class, UObject* UEObject) { return FV8Utils::IsolateData(Isolate)->FindOrAdd(Isolate, Context, Class, UEObject); } v8::Local DataTransfer::FindOrAddStruct( v8::Isolate* Isolate, v8::Local Context, UScriptStruct* ScriptStruct, void* Ptr, bool PassByPointer) { return FV8Utils::IsolateData(Isolate)->FindOrAddStruct(Isolate, Context, ScriptStruct, Ptr, PassByPointer); } bool DataTransfer::IsInstanceOf(v8::Isolate* Isolate, UStruct* Struct, v8::Local JsObject) { return FV8Utils::IsolateData(Isolate)->IsInstanceOf(Struct, JsObject); } void DataTransfer::ThrowException(v8::Isolate* Isolate, const char* Message) { FV8Utils::ThrowException(Isolate, Message); } #endif } // namespace PUERTS_NAMESPACE