From 09ed64e38a70d1b6213e720f61dd4f976a453970 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Tue, 19 Oct 2021 12:28:43 +0800 Subject: [PATCH] fix gc bug of EcmaModule Signed-off-by: wengchangcheng --- ecmascript/ecma_module.cpp | 22 ++++++++++++---------- ecmascript/ecma_module.h | 6 ++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/ecmascript/ecma_module.cpp b/ecmascript/ecma_module.cpp index 3dc94b52ef..8a1a7c1e41 100644 --- a/ecmascript/ecma_module.cpp +++ b/ecmascript/ecma_module.cpp @@ -36,17 +36,18 @@ JSHandle EcmaModule::GetItem(const JSThread *thread, JSHandle(thread, JSTaggedValue::Undefined()); } -void EcmaModule::AddItem(const JSThread *thread, JSHandle itemName, JSHandle itemValue) +void EcmaModule::AddItem(const JSThread *thread, JSHandle module, JSHandle itemName, + JSHandle itemValue) { - JSHandle data(thread, GetNameDictionary()); + JSHandle data(thread, module->GetNameDictionary()); if (data->IsUndefined()) { JSHandle dict(thread, NameDictionary::Create(thread, DICTIONART_CAP)); auto result = dict->Put(thread, dict, itemName, itemValue, PropertyAttributes::Default()); - SetNameDictionary(thread, JSTaggedValue(result)); + module->SetNameDictionary(thread, JSTaggedValue(result)); } else { JSHandle dataDict = JSHandle::Cast(data); auto result = dataDict->Put(thread, dataDict, itemName, itemValue, PropertyAttributes::Default()); - SetNameDictionary(thread, JSTaggedValue(result)); + module->SetNameDictionary(thread, JSTaggedValue(result)); } } @@ -59,7 +60,8 @@ void EcmaModule::RemoveItem(const JSThread *thread, JSHandle item } } -void EcmaModule::CopyModuleInternal(const JSThread *thread, JSHandle srcModule) +void EcmaModule::CopyModuleInternal(const JSThread *thread, JSHandle dstModule, + JSHandle srcModule) { JSHandle moduleItems(thread, NameDictionary::Cast(srcModule->GetNameDictionary().GetTaggedObject())); @@ -76,7 +78,7 @@ void EcmaModule::CopyModuleInternal(const JSThread *thread, JSHandle if (entry != -1) { itemName.Update(allKeys->Get(i)); itemValue.Update(moduleItems->GetValue(entry)); - AddItem(thread, itemName, itemValue); + EcmaModule::AddItem(thread, dstModule, itemName, itemValue); } } } @@ -168,11 +170,11 @@ void ModuleManager::AddModuleItem(const JSThread *thread, JSHandle module = GetModule(thread, JSHandle::Cast(moduleName)); if (module->IsUndefined()) { JSHandle emptyModule = factory->NewEmptyEcmaModule(); - emptyModule->AddItem(thread, itemName, value); + EcmaModule::AddItem(thread, emptyModule, itemName, value); AddModule(JSHandle::Cast(moduleName), JSHandle::Cast(emptyModule)); } else { - EcmaModule::Cast(module->GetTaggedObject())->AddItem(thread, itemName, value); + EcmaModule::AddItem(thread, JSHandle(module), itemName, value); } } @@ -195,11 +197,11 @@ void ModuleManager::CopyModule(const JSThread *thread, JSHandle s if (dstModule->IsUndefined()) { JSHandle emptyModule = factory->NewEmptyEcmaModule(); - emptyModule->CopyModuleInternal(thread, srcModule); + EcmaModule::CopyModuleInternal(thread, emptyModule, srcModule); AddModule(JSHandle::Cast(moduleName), JSHandle::Cast(emptyModule)); } else { - JSHandle::Cast(dstModule)->CopyModuleInternal(thread, srcModule); + EcmaModule::CopyModuleInternal(thread, JSHandle(dstModule), srcModule); } } diff --git a/ecmascript/ecma_module.h b/ecmascript/ecma_module.h index 707724d782..b6a053ab1f 100644 --- a/ecmascript/ecma_module.h +++ b/ecmascript/ecma_module.h @@ -33,7 +33,8 @@ public: JSHandle GetItem(const JSThread *thread, JSHandle itemName); - void AddItem(const JSThread *thread, JSHandle itemName, JSHandle itemValue); + static void AddItem(const JSThread *thread, JSHandle module, JSHandle itemName, + JSHandle itemValue); void RemoveItem(const JSThread *thread, JSHandle itemName); @@ -45,7 +46,8 @@ public: DECL_VISIT_OBJECT_FOR_JS_OBJECT(ECMAObject, NAME_DICTIONARY_OFFSET, SIZE) protected: - void CopyModuleInternal(const JSThread *thread, JSHandle srcModule); + static void CopyModuleInternal(const JSThread *thread, JSHandle dstModule, + JSHandle srcModule); friend class ModuleManager; }; -- Gitee