void setNativePointer(alias_ref<HybridData::javaobject> hybridData, std::unique_ptr<BaseHybridClass> new_value) { static auto pointerField = hybridData->getClass()->getField<jlong>("mNativePointer"); auto* old_value = reinterpret_cast<BaseHybridClass*>(hybridData->getFieldValue(pointerField)); if (new_value) { // Modify should only ever be called once with a non-null // new_value. If this happens again it's a programmer error, so // blow up. FBASSERTMSGF(old_value == 0, "Attempt to set C++ native pointer twice"); } else if (old_value == 0) { return; } // delete on a null pointer is defined to be a noop. delete old_value; // This releases ownership from the unique_ptr, and passes the pointer, and // ownership of it, to HybridData which is managed by the java GC. The // finalizer on hybridData calls resetNative which will delete the object, if // reseetNative has not already been called. hybridData->setFieldValue(pointerField, reinterpret_cast<jlong>(new_value.release())); }
static void _jniTransferLayoutDirection(CSSNodeRef node, alias_ref<jobject> javaNode) { static auto layoutDirectionField = javaNode->getClass()->getField<jint>("mLayoutDirection"); javaNode->setFieldValue(layoutDirectionField, static_cast<jint>(CSSNodeLayoutGetDirection(node))); }