diff --git a/runtime/compiler/ecmascript_runtime_interface.cpp b/runtime/compiler/ecmascript_runtime_interface.cpp index a732d2c38285bbd3f3c19904986e8899e115dee1..7eaeab526c38406a0361a16ccec7993b18ceca07 100644 --- a/runtime/compiler/ecmascript_runtime_interface.cpp +++ b/runtime/compiler/ecmascript_runtime_interface.cpp @@ -88,11 +88,12 @@ uintptr_t EcmaRuntimeInterface::GetGlobalVarAddress(MethodPtr method, size_t id) return 0; } - JSTaggedValue res(dict->GetBox(entry)); + JSTaggedValue res(dict->GetSafeBox(entry)); // we can't set an attribute in compiler thread. - if (res.IsUndefined() || !res.IsPropertyBox()) { + if (res.IsUndefined() || res.IsHole() || !res.IsPropertyBox()) { return 0; } + ASSERT(res.IsPropertyBox()); return reinterpret_cast(res.GetHeapObject()); } diff --git a/runtime/global_dictionary-inl.h b/runtime/global_dictionary-inl.h index ce7f9b88afe7d4ec91c642e7a0792ac02d1644b7..099fed185755a3f84ed6942cf2a2b7f94fd10e5e 100644 --- a/runtime/global_dictionary-inl.h +++ b/runtime/global_dictionary-inl.h @@ -49,6 +49,16 @@ PropertyBox *GlobalDictionary::GetBox(int entry) const return PropertyBox::Cast(Get(index).GetTaggedObject()); } +PropertyBox *GlobalDictionary::GetSafeBox(int entry) const +{ + int index = GetEntryIndex(entry) + ENTRY_VALUE_INDEX; + auto val = Get(index); + if (!val.IsHeapObject()) { + return nullptr; + } + return PropertyBox::Cast(Get(index).GetTaggedObject()); +} + JSTaggedValue GlobalDictionary::GetValue(int entry) const { return GetBox(entry)->GetValue(); diff --git a/runtime/global_dictionary.h b/runtime/global_dictionary.h index bcdb4a4dc27c4507f5fec89b0f2fa7f2e03fa5ca..94615863f8282d44f310c8df328d60fca516d5d3 100644 --- a/runtime/global_dictionary.h +++ b/runtime/global_dictionary.h @@ -54,6 +54,8 @@ public: inline PropertyBox *GetBox(int entry) const; + inline PropertyBox *GetSafeBox(int entry) const; + inline JSTaggedValue GetValue(int entry) const; inline PropertyAttributes GetAttributes(int entry) const;