| 358 | } |
| 359 | |
| 360 | void ObjectManager::JSObjectFinalizer(Isolate* isolate, |
| 361 | ObjectWeakCallbackState* callbackState) { |
| 362 | HandleScope handleScope(m_isolate); |
| 363 | Persistent<Object>* po = callbackState->target; |
| 364 | auto jsInstanceInfo = GetJSInstanceInfoFromRuntimeObject(po->Get(m_isolate)); |
| 365 | |
| 366 | if (jsInstanceInfo == nullptr) { |
| 367 | po->Reset(); |
| 368 | delete po; |
| 369 | delete callbackState; |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | auto javaObjectID = jsInstanceInfo->JavaObjectID; |
| 374 | JEnv env; |
| 375 | jboolean isJavaInstanceAlive = env.CallBooleanMethod( |
| 376 | m_javaRuntimeObject, MAKE_INSTANCE_WEAK_AND_CHECK_IF_ALIVE_METHOD_ID, |
| 377 | javaObjectID); |
| 378 | if (isJavaInstanceAlive) { |
| 379 | // If the Java instance is alive, keep the JavaScript instance alive. |
| 380 | po->SetWeak(callbackState, JSObjectFinalizerStatic, |
| 381 | WeakCallbackType::kFinalizer); |
| 382 | } else { |
| 383 | // If the Java instance is dead, this JavaScript instance can be let die. |
| 384 | delete jsInstanceInfo; |
| 385 | auto jsInfoIdx = static_cast<int>(MetadataNodeKeys::JsInfo); |
| 386 | po->Get(m_isolate)->SetInternalField(jsInfoIdx, Undefined(m_isolate)); |
| 387 | po->Reset(); |
| 388 | m_idToObject.erase(javaObjectID); |
| 389 | delete po; |
| 390 | delete callbackState; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* |
| 395 | * When JS GC happens change state of the java counterpart to mirror state of JS |
no test coverage detected