/* * Copyright (c) 2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include namespace Web::Bindings { class Wrappable { public: virtual ~Wrappable(); void set_wrapper(Wrapper&); Wrapper* wrapper() { return m_wrapper; } const Wrapper* wrapper() const { return m_wrapper; } private: WeakPtr m_wrapper; }; template inline Wrapper* wrap_impl(JS::GlobalObject& global_object, NativeObject& native_object) { if (!native_object.wrapper()) { native_object.set_wrapper(*global_object.heap().allocate(global_object, global_object, native_object)); } return native_object.wrapper(); } }