GlobalRef& GlobalRef::operator=(GlobalRef& other) { if (&other != this) { // Increment the new reference before decrementing the old. auto oldJVM = m_javaVM; auto oldObject = m_object; m_javaVM = other.m_javaVM; m_object = getEnvFromJavaVM(m_javaVM)->NewGlobalRef(other.m_object); getEnvFromJavaVM(oldJVM)->DeleteGlobalRef(oldObject); } return *this; }
DuktapeContext::DuktapeContext(JavaVM* javaVM) : m_context(duk_create_heap(nullptr, nullptr, nullptr, nullptr, fatalErrorHandler)) , m_objectType(m_javaValues.getObjectType(getEnvFromJavaVM(javaVM))) { if (!m_context) { throw std::bad_alloc(); } // Stash the JVM object in the context, so we can find our way back from a Duktape C callback. duk_push_global_stash(m_context); duk_push_pointer(m_context, javaVM); duk_put_prop_string(m_context, -2, JAVA_VM_PROP_NAME); duk_pop(m_context); }
JNIEnv* GlobalRef::getJniEnv() const { return getEnvFromJavaVM(m_javaVM); }
GlobalRef::~GlobalRef() { getEnvFromJavaVM(m_javaVM)->DeleteGlobalRef(m_object); }
GlobalRef::GlobalRef(const GlobalRef& other) : m_javaVM(other.m_javaVM) , m_object(getEnvFromJavaVM(m_javaVM)->NewGlobalRef(other.m_object)) { }