From 0df116c2136a012801fcea57931f778f273394f0 Mon Sep 17 00:00:00 2001 From: wengchangcheng Date: Tue, 19 Oct 2021 21:28:25 +0800 Subject: [PATCH] fix EcmaModule RemoveItem bug when dictionary update Signed-off-by: wengchangcheng --- ecmascript/ecma_module.cpp | 11 ++++++++--- ecmascript/ecma_module.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ecmascript/ecma_module.cpp b/ecmascript/ecma_module.cpp index 8a1a7c1e41..260d8397da 100644 --- a/ecmascript/ecma_module.cpp +++ b/ecmascript/ecma_module.cpp @@ -51,12 +51,17 @@ void EcmaModule::AddItem(const JSThread *thread, JSHandle module, JS } } -void EcmaModule::RemoveItem(const JSThread *thread, JSHandle itemName) +void EcmaModule::RemoveItem(const JSThread *thread, JSHandle module, JSHandle itemName) { - JSHandle moduleItems(thread, NameDictionary::Cast(GetNameDictionary().GetTaggedObject())); + JSHandle data(thread, module->GetNameDictionary()); + if (data->IsUndefined()) { + return; + } + JSHandle moduleItems(data); int entry = moduleItems->FindEntry(itemName.GetTaggedValue()); if (entry != -1) { - NameDictionary::Remove(thread, moduleItems, entry); // discard return + NameDictionary *newDict = NameDictionary::Remove(thread, moduleItems, entry); // discard return + module->SetNameDictionary(thread, JSTaggedValue(newDict)); } } diff --git a/ecmascript/ecma_module.h b/ecmascript/ecma_module.h index b6a053ab1f..ee744ac8d5 100644 --- a/ecmascript/ecma_module.h +++ b/ecmascript/ecma_module.h @@ -36,7 +36,7 @@ public: static void AddItem(const JSThread *thread, JSHandle module, JSHandle itemName, JSHandle itemValue); - void RemoveItem(const JSThread *thread, JSHandle itemName); + static void RemoveItem(const JSThread *thread, JSHandle module, JSHandle itemName); void DebugPrint(const JSThread *thread, const CString &caller); -- Gitee