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 V8TemplateMapTraits::Dispose(v8::Isolate* isolate, v8::Global<v8::Object> value, void* key) { v8::Local<v8::Object> obj = value.Get(isolate); if (obj.IsEmpty()) return; CFXJS_Engine* pEngine = CFXJS_Engine::CurrentEngineFromIsolate(isolate); int id = pEngine->GetObjDefnID(obj); if (id == -1) return; CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(isolate, id); if (!pObjDef) return; if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(pEngine, obj); CFXJS_Engine::FreeObjectPrivate(obj); }
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 CFXJS_Engine::ReleaseEngine() { v8::Isolate::Scope isolate_scope(m_isolate); v8::HandleScope handle_scope(m_isolate); v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_isolate, m_V8PersistentContext); v8::Context::Scope context_scope(context); FXJS_PerIsolateData* pData = FXJS_PerIsolateData::Get(m_isolate); if (!pData) return; m_ConstArrays.clear(); int maxID = CFXJS_ObjDefinition::MaxID(m_isolate); for (int i = 0; i < maxID; ++i) { CFXJS_ObjDefinition* pObjDef = CFXJS_ObjDefinition::ForID(m_isolate, i); v8::Local<v8::Object> pObj; if (pObjDef->m_ObjType == FXJSOBJTYPE_GLOBAL) { pObj = context->Global()->GetPrototype()->ToObject(context).ToLocalChecked(); } else if (m_StaticObjects[i] && !m_StaticObjects[i]->IsEmpty()) { pObj = v8::Local<v8::Object>::New(m_isolate, *m_StaticObjects[i]); delete m_StaticObjects[i]; m_StaticObjects[i] = nullptr; } if (!pObj.IsEmpty()) { if (pObjDef->m_pDestructor) pObjDef->m_pDestructor(this, pObj); FreeObjectPrivate(pObj); } } m_V8PersistentContext.Reset(); if (m_isolate == g_isolate && --g_isolate_ref_count > 0) return; delete pData; m_isolate->SetData(g_embedderDataSlot, nullptr); }