void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, v8::Global<v8::Context>& v8PersistentContext) { v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); v8::Local<v8::Context> context = v8::Local<v8::Context>::New(pIsolate, v8PersistentContext); v8::Context::Scope context_scope(context); FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); if (!pData) return; int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); for (int i = 0; i < maxID; ++i) { CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); if (!pObjDef->m_StaticObj.IsEmpty()) { v8::Local<v8::Object> pObj = v8::Local<v8::Object>::New(pIsolate, pObjDef->m_StaticObj); if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(pObj); FXJS_FreePrivate(pObj); } delete pObjDef; } pIsolate->SetData(g_embedderDataSlot, nullptr); delete pData; }
void FXJS_ReleaseRuntime(v8::Isolate* pIsolate, v8::Global<v8::Context>* pV8PersistentContext, std::vector<v8::Global<v8::Object>*>* pStaticObjects) { v8::Isolate::Scope isolate_scope(pIsolate); v8::HandleScope handle_scope(pIsolate); v8::Local<v8::Context> context = v8::Local<v8::Context>::New(pIsolate, *pV8PersistentContext); v8::Context::Scope context_scope(context); FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(pIsolate); if (!pData) return; int maxID = CFXJS_ObjDefinition::MaxID(pIsolate); for (int i = 0; i < maxID; ++i) { CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(pIsolate, i); v8::Local<v8::Object> pObj; if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { pObj = context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); } else if (pStaticObjects->at(i) && !pStaticObjects->at(i)->IsEmpty()) { pObj = v8::Local<v8::Object>::New(pIsolate, *pStaticObjects->at(i)); delete pStaticObjects->at(i); pStaticObjects->at(i) = nullptr; } if (!pObj.IsEmpty()) { if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(pObj); FXJS_FreePrivate(pObj); } } if (pIsolate == g_isolate && --g_isolate_ref_count > 0) return; for (int i = 0; i < maxID; ++i) delete CFXJS_ObjDefinition::ForID(pIsolate, i); pIsolate->SetData(g_embedderDataSlot, nullptr); delete pData; }
void FXJS_FreePrivate(v8::Local<v8::Object> pObj) { if (pObj.IsEmpty() || !pObj->InternalFieldCount()) return; FXJS_FreePrivate(pObj->GetAlignedPointerFromInternalField(0)); pObj->SetAlignedPointerInInternalField(0, NULL); }
void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { CJS_Object* pJSObj = data.GetParameter(); pJSObj->ExitInstance(); delete pJSObj; FXJS_FreePrivate(data.GetInternalField(0)); }