diff --git a/include/hermes/VM/Handle-inline.h b/include/hermes/VM/Handle-inline.h index 5a66ac6fcdf..a26dcf9be03 100644 --- a/include/hermes/VM/Handle-inline.h +++ b/include/hermes/VM/Handle-inline.h @@ -10,11 +10,28 @@ #include "hermes/VM/Handle.h" +#include "hermes/VM/Casting.h" #include "hermes/VM/HandleRootOwner.h" namespace hermes { namespace vm { +template +template +inline PseudoHandle PseudoHandle::vmcast(PseudoHandle &&other) { + auto result = PseudoHandle::create(hermes::vm::vmcast(other.get())); + other.invalidate(); + return result; +} + +template +template +inline PseudoHandle PseudoHandle::dyn_vmcast(PseudoHandle &&other) { + auto result = PseudoHandle::create(hermes::vm::dyn_vmcast(other.get())); + other.invalidate(); + return result; +} + /// Allocate a new handle in the current GCScope inline HandleBase::HandleBase(HandleRootOwner *runtime, HermesValue value) : handle_(runtime->newHandle(value)) { diff --git a/include/hermes/VM/Handle.h b/include/hermes/VM/Handle.h index 1072b2290d2..ac7db8c88e3 100644 --- a/include/hermes/VM/Handle.h +++ b/include/hermes/VM/Handle.h @@ -153,6 +153,12 @@ class PseudoHandle { static PseudoHandle create(value_type value) { return PseudoHandle(value); } + + template + static inline PseudoHandle vmcast(PseudoHandle &&other); + + template + static inline PseudoHandle dyn_vmcast(PseudoHandle &&other); }; /// A HermesValue in the current GCScope which is trackable by the GC and will diff --git a/include/hermes/VM/HermesValue-inline.h b/include/hermes/VM/HermesValue-inline.h index a4477f36a70..c2990b4ad30 100644 --- a/include/hermes/VM/HermesValue-inline.h +++ b/include/hermes/VM/HermesValue-inline.h @@ -9,6 +9,7 @@ #define HERMES_VM_HERMESVALUE_INLINE_H #include "hermes/Support/SlowAssert.h" +#include "hermes/VM/Handle.h" #include "hermes/VM/HermesValue.h" #include "hermes/VM/GC.h" @@ -21,6 +22,13 @@ void HermesValue::setInGC(HermesValue hv, GC *gc) { assert(gc->inGC()); } +template +inline PinnedHermesValue &PinnedHermesValue::operator=(PseudoHandle &&hv) { + setNoBarrier(hv.getHermesValue()); + hv.invalidate(); + return *this; +} + template inline void GCHermesValue::set(HermesValue hv, GC *gc) { HERMES_SLOW_ASSERT( diff --git a/include/hermes/VM/HermesValue.h b/include/hermes/VM/HermesValue.h index 8246e561af8..8e74ec0a1e4 100644 --- a/include/hermes/VM/HermesValue.h +++ b/include/hermes/VM/HermesValue.h @@ -99,6 +99,8 @@ namespace hermes { namespace vm { class StringPrimitive; +template +class PseudoHandle; template class PseudoHandle; @@ -508,6 +510,8 @@ class PinnedHermesValue : public HermesValue { setNoBarrier(hv); return *this; } + template + inline PinnedHermesValue &operator=(PseudoHandle &&hv); } HERMES_ATTRIBUTE_WARN_UNUSED_VARIABLES; // All HermesValues stored in heap object should be of this