/* * 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. */ #pragma once #include "NamespaceDef.h" PRAGMA_DISABLE_UNDEFINED_IDENTIFIER_WARNINGS #pragma warning(push, 0) #include "v8.h" #pragma warning(pop) PRAGMA_ENABLE_UNDEFINED_IDENTIFIER_WARNINGS #include #include "JSClassRegister.h" #include "ObjectCacheNode.h" #include "ObjectMapper.h" namespace PUERTS_NAMESPACE { struct PointerHash { std::size_t operator()(const void* ptr) const { return reinterpret_cast(ptr); } }; struct PointerEqual { bool operator()(const void* lhs, const void* rhs) const { return lhs == rhs; } }; class FCppObjectMapper final : public ICppObjectMapper { public: void Initialize(v8::Isolate* InIsolate, v8::Local InContext); void LoadCppType(const v8::FunctionCallbackInfo& Info); virtual bool IsInstanceOfCppObject(v8::Isolate* Isolate, const void* TypeId, v8::Local JsObject) override; virtual std::weak_ptr GetJsEnvLifeCycleTracker() override; virtual v8::Local FindOrAddCppObject( v8::Isolate* Isolate, v8::Local& Context, const void* TypeId, void* Ptr, bool PassByPointer) override; virtual void UnBindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr) override; virtual void BindCppObject(v8::Isolate* Isolate, JSClassDefinition* ClassDefinition, void* Ptr, v8::Local JSObject, bool PassByPointer) override; virtual void* GetPrivateData(v8::Local Context, v8::Local JSObject) override; virtual void SetPrivateData(v8::Local Context, v8::Local JSObject, void* Ptr) override; virtual v8::MaybeLocal LoadTypeById(v8::Local Context, const void* TypeId) override; void UnInitialize(v8::Isolate* InIsolate); v8::Local GetTemplateOfClass(v8::Isolate* Isolate, const JSClassDefinition* ClassDefinition); private: std::unordered_map CDataCache; std::unordered_map, PointerHash, PointerEqual> TypeIdToTemplateMap; v8::UniquePersistent PointerTemplate; #ifndef WITH_QUICKJS v8::Global PrivateKey; #endif std::shared_ptr Ref = std::make_shared(0); }; } // namespace PUERTS_NAMESPACE