Beispiel #1
0
local_ref<HybridData::javaobject> getHybridData(alias_ref<jobject> jthis,
                                                JField<HybridData::javaobject> field) {
  auto hybridData = jthis->getFieldValue(field);
  if (!hybridData) {
    throwNewJavaException("java/lang/NullPointerException", "java.lang.NullPointerException");
  }
  return hybridData;
}
Beispiel #2
0
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()));
}
Beispiel #3
0
jlong jni_CSSNodeNew(alias_ref<jobject> thiz) {
  const CSSNodeRef node = CSSNodeNew();
  CSSNodeSetContext(node, Environment::current()->NewWeakGlobalRef(thiz.get()));
  CSSNodeSetPrintFunc(node, _jniPrint);
  return reinterpret_cast<jlong>(node);
}
Beispiel #4
0
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)));
}