static void gum_file_on_weak_notify (const WeakCallbackInfo<GumFile> & info) { HandleScope handle_scope (info.GetIsolate ()); auto self = info.GetParameter (); g_hash_table_remove (self->module->files, self); }
void weakCallback( const WeakCallbackInfo<int> &data) { // NOLINT(runtime/references) int *parameter = static_cast<int*>(data.GetInternalField(0)); v8::Local<v8::Value> val = New(*parameter); MakeCallback(GetCurrentContext()->Global(), New(cb), 1, &val); delete parameter; }
void JNIV8Object::weakPersistentCallback(const WeakCallbackInfo<void>& data) { // never use the raw pointer directly; this way we are retaining the object until this method finishes! auto jniV8Object = reinterpret_cast<JNIV8Object*>(data.GetParameter()); // "resurrect" the JS object, because we might need it later in some native or java function // IF we do, we have to make a strong reference to the java object again and also register this callback for // the provided JS object reference! jniV8Object->_jsObject.ClearWeak(); jniV8Object->_jsObject.MarkActive(); // we are only holding the object because java/native is still alive, v8 can not gc it anymore // => adjust external memory counter jniV8Object->_bgjsEngine->getIsolate()->AdjustAmountOfExternalAllocatedMemory(-jniV8Object->_externalMemory); // finally: the js object is no longer being used => release the strong reference to the java object // NOTE: object might be deleted by another thread after calling this jniV8Object->releaseJObject(); }