diff --git a/ecmascript/js_object.h b/ecmascript/js_object.h index 127658b16b22c08e96218626b778c752bbb04b9f..7371b866a006d73f3fea2b793a11f2f038bf8dbb 100644 --- a/ecmascript/js_object.h +++ b/ecmascript/js_object.h @@ -339,6 +339,10 @@ public: void SetHash(int32_t hash); int32_t GetHash() const; + void InitializeHash() + { + Barriers::SetDynPrimitive(this, ECMAObject::HASH_OFFSET, JSTaggedValue(0).GetRawData()); + } void* GetNativePointerField(int32_t index) const; void SetNativePointerField(int32_t index, void *data); @@ -354,6 +358,7 @@ public: void VisitObjects([[maybe_unused]] const EcmaObjectRangeVisitor &visitor) const { // no field in this object + Visitor(visitor); } }; diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index 7282588009227f3e99881e2fcce43a598c034e9d..0e4ed0a3000e3f2b8c446f60f5d208e1ccacdf1c 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -290,6 +290,7 @@ JSHandle ObjectFactory::NewJSObject(const JSHandle &jshclass NewObjectHook(); JSHandle obj(thread_, JSObject::Cast(NewDynObject(jshclass, JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS))); JSHandle emptyArray = EmptyArray(); + obj->InitializeHash(); obj->SetElements(thread_, emptyArray, SKIP_BARRIER); obj->SetProperties(thread_, emptyArray, SKIP_BARRIER); return obj;