#pragma once #include "isolate/remote_handle.h" #include "transferable.h" #include #include #include #include namespace ivm { namespace detail { /** * Holds common data for ReferenceHandle and ReferenceHandleTransferable */ class ReferenceData { friend class AccessorRunner; public: enum class TypeOf { Null, Undefined, Number, String, Boolean, Object, Function }; explicit ReferenceData(v8::Local value, bool inherit = false); ReferenceData( std::shared_ptr isolate, RemoteHandle reference, RemoteHandle context, TypeOf type_of, bool accessors, bool inherit ); protected: std::shared_ptr isolate; RemoteHandle reference; RemoteHandle context; TypeOf type_of; bool accessors; bool inherit; }; } // namespace detail /** * This will be a reference to any v8 Value in any isolate. */ class ReferenceHandle : public TransferableHandle, public detail::ReferenceData { friend class ApplyRunner; friend class CopyRunner; friend class AccessorRunner; friend class GetRunner; public: using TypeOf = detail::ReferenceData::TypeOf; template explicit ReferenceHandle(Args&&... args) : ReferenceData{std::forward(args)...} {} static auto Definition() -> v8::Local; static auto New(v8::Local value, v8::MaybeLocal options) -> std::unique_ptr; auto TransferOut() -> std::unique_ptr final; auto Deref(v8::MaybeLocal maybe_options) -> v8::Local; auto DerefInto(v8::MaybeLocal maybe_options) -> v8::Local; auto Release() -> v8::Local; auto TypeOfGetter() -> v8::Local; template auto Apply( v8::MaybeLocal recv_handle, v8::Maybe maybe_arguments, v8::MaybeLocal maybe_options ) -> v8::Local; template auto Copy() -> v8::Local; template auto Get( v8::Local key_handle, v8::MaybeLocal maybe_options ) -> v8::Local; template auto Delete(v8::Local key_handle) -> v8::Local; template auto Set( v8::Local key_handle, v8::Local val_handle, v8::MaybeLocal maybe_options ) -> v8::Local; private: void CheckDisposed() const; }; /** * Instances of this turn into a ReferenceHandle when they are transferred in */ class ReferenceHandleTransferable : public Transferable, public detail::ReferenceData { public: template explicit ReferenceHandleTransferable(Args&&... args) : ReferenceData{std::forward(args)...} {} auto TransferIn() -> v8::Local final; }; } // namespace ivm