diff --git a/ecmascript/tests/accessor_data_test.cpp b/ecmascript/tests/accessor_data_test.cpp index 99558c10178199ab9e24e8f739de8f8f1b896cd0..744968a102eef671b36c6dc7bed13299cef8b87a 100644 --- a/ecmascript/tests/accessor_data_test.cpp +++ b/ecmascript/tests/accessor_data_test.cpp @@ -159,65 +159,8 @@ HWTEST_F_L0(AccessorDataTest, HasSetter) } /** - * @tc.name: CallInternalGet - * @tc.desc: Call internal get function to get object prototype. - * @tc.type: FUNC - * @tc.require: - */ -HWTEST_F_L0(AccessorDataTest, CallInternalGet) -{ - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); - - // Construct objects and specify specific prototypes. - JSFunction *func1 = globalEnv->GetObjectFunction().GetObject(); - JSFunction *func2 = globalEnv->GetObjectFunction().GetObject(); - JSHandle funcTagVal1(thread, func1); - JSHandle funcTagVal2(thread, func2); - JSHandle jsObjectHandle1 = - factory->NewJSObjectByConstructor(JSHandle(funcTagVal1), funcTagVal1); - JSHandle jsObjectHandle2 = - factory->NewJSObjectByConstructor(JSHandle(funcTagVal2), funcTagVal2); - char array1[] = "x"; - char array2[] = "y"; - JSHandle key1(factory->NewFromCanBeCompressString(array1)); - JSHandle key2(factory->NewFromCanBeCompressString(array2)); - JSHandle value(thread, JSTaggedValue(100)); - JSObject::SetProperty(thread, JSHandle(jsObjectHandle1), key1, value); - JSObject::SetProperty(thread, JSHandle(jsObjectHandle2), key2, value); - - JSHandle nullPrototypeHandle(thread, JSTaggedValue::Null()); - JSHandle undefPrototypeHandle(thread, JSTaggedValue::Undefined()); - JSHandle accDynclass1 = - factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullPrototypeHandle); - JSHandle accDynclass2 = - factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, undefPrototypeHandle); - ObjectHeader *accObject1 = factory->NewDynObject(accDynclass1); - ObjectHeader *accObject2 = factory->NewDynObject(accDynclass2); - AccessorData *acc1 = AccessorData::Cast(accObject1); - AccessorData *acc2 = AccessorData::Cast(accObject2); - JSHandle prototypeGetterFuncNativePtrHandle = - factory->NewJSNativePointer(reinterpret_cast(JSFunction::PrototypeGetter), nullptr, nullptr, true); - acc1->SetGetter(thread, prototypeGetterFuncNativePtrHandle); - acc2->SetGetter(thread, prototypeGetterFuncNativePtrHandle); - ObjectOperator op1(thread, jsObjectHandle1, key1, OperatorType::OWN); - ObjectOperator op2(thread, jsObjectHandle2, key2, OperatorType::OWN); - PropertyAttributes attr = PropertyAttributes::DefaultAccessor(false, false, true); - op1.AddProperty(jsObjectHandle1, nullPrototypeHandle, attr); - op2.AddProperty(jsObjectHandle2, undefPrototypeHandle, attr); - JSHandle holder1 = op1.GetHolder(); - JSHandle holder2 = op2.GetHolder(); - - // Call CallInternalGet function to get prototypes. - JSTaggedValue valNullPrototype = acc1->CallInternalGet(thread, JSHandle::Cast(holder1)); - JSTaggedValue valUndefPrototype = acc2->CallInternalGet(thread, JSHandle::Cast(holder2)); - EXPECT_EQ(valNullPrototype.GetInt(), JSTaggedValue::Null().GetInt()); - EXPECT_EQ(valUndefPrototype.GetInt(), JSTaggedValue::Undefined().GetInt()); -} - -/** - * @tc.name: CallInternalSet - * @tc.desc: Call internal set function to set object prototype. + * @tc.name: CallInternalSet/CallInternalGet + * @tc.desc: Call internal set & get function to set object prototype. * @tc.type: FUNC * @tc.require: */ @@ -228,42 +171,32 @@ HWTEST_F_L0(AccessorDataTest, CallInternalSet) // Construct objects and specify specific prototypes. JSFunction *func1 = globalEnv->GetObjectFunction().GetObject(); - JSHandle funcTagVal1(thread, func1); - JSHandle jsObjectHandle1 = - factory->NewJSObjectByConstructor(JSHandle(funcTagVal1), funcTagVal1); - char array1[] = "x"; - JSHandle key1(factory->NewFromCanBeCompressString(array1)); - JSHandle value(thread, JSTaggedValue(100)); - JSObject::SetProperty(thread, JSHandle(jsObjectHandle1), key1, value); + JSHandle funcTagVal1 = + factory->CloneJSFuction(JSHandle(thread, func1), FunctionKind::BASE_CONSTRUCTOR); // Call the CallInternalGet method to inspect prototype. JSHandle nullPrototypeHandle(thread, JSTaggedValue::Null()); JSHandle accDynclass1 = factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullPrototypeHandle); - ObjectHeader *accObject1 = factory->NewDynObject(accDynclass1); - AccessorData *acc1 = AccessorData::Cast(accObject1); + JSHandle accObject1(thread, factory->NewDynObject(accDynclass1)); JSHandle prototypeGetterFuncNativePtrHandle = factory->NewJSNativePointer(reinterpret_cast(JSFunction::PrototypeGetter), nullptr, nullptr, true); - acc1->SetGetter(thread, prototypeGetterFuncNativePtrHandle); - ObjectOperator op1(thread, jsObjectHandle1, key1, OperatorType::OWN); - PropertyAttributes attr = PropertyAttributes::DefaultAccessor(false, false, true); - op1.AddProperty(jsObjectHandle1, nullPrototypeHandle, attr); - JSHandle holder1 = op1.GetHolder(); + accObject1->SetGetter(thread, prototypeGetterFuncNativePtrHandle); - JSTaggedValue valNullPrototype = acc1->CallInternalGet(thread, JSHandle::Cast(holder1)); - EXPECT_EQ(valNullPrototype.GetInt(), JSTaggedValue::Null().GetInt()); + JSTaggedValue valNullPrototype = accObject1->CallInternalGet(thread, JSHandle::Cast(funcTagVal1)); + EXPECT_NE(valNullPrototype.GetRawData(), JSTaggedValue::Undefined().GetRawData()); // Call the CallInternalSet method to set new prototype. JSHandle undefPrototypeHandle(thread, JSTaggedValue::Undefined()); JSHandle prototypeSetterFuncNativePtrHandle = factory->NewJSNativePointer(reinterpret_cast(JSFunction::PrototypeSetter), nullptr, nullptr, true); - acc1->SetSetter(thread, prototypeSetterFuncNativePtrHandle); - bool res1 = acc1->CallInternalSet(thread, JSHandle::Cast(holder1), undefPrototypeHandle); + accObject1->SetSetter(thread, prototypeSetterFuncNativePtrHandle); + bool res1 = accObject1->CallInternalSet(thread, JSHandle::Cast(funcTagVal1), undefPrototypeHandle); EXPECT_TRUE(res1); // Call the CallInternalGet method to check the changed prototype. - valNullPrototype = acc1->CallInternalGet(thread, JSHandle::Cast(holder1)); - EXPECT_EQ(valNullPrototype.GetInt(), JSTaggedValue::Undefined().GetInt()); + valNullPrototype = accObject1->CallInternalGet(thread, JSHandle::Cast(funcTagVal1)); + EXPECT_EQ(valNullPrototype.GetRawData(), JSTaggedValue::Undefined().GetRawData()); } /** diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index 3ba32c6c85418a1f4d0a4c6f50f17fc5e0d74487..91ab734ea399e12f2b19f6d8e3401ddd17857dc0 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -433,7 +433,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_DISPLAYNAMES: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSDisplayNames::SIZE, 6) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSDisplayNames::SIZE, 3) NEW_OBJECT_AND_DUMP(JSDisplayNames, JS_DISPLAYNAMES) break; }