/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ecmascript/builtins/builtins_reflect.h" #include "ecmascript/ecma_runtime_call_info.h" #include "ecmascript/ecma_string.h" #include "ecmascript/ecma_vm.h" #include "ecmascript/global_env.h" #include "ecmascript/js_array.h" #include "ecmascript/js_function.h" #include "ecmascript/js_object-inl.h" #include "ecmascript/js_primitive_ref.h" #include "ecmascript/tagged_array-inl.h" #include "ecmascript/object_factory.h" #include "ecmascript/tests/test_helper.h" using namespace panda::ecmascript; using namespace panda::ecmascript::builtins; using BuiltinsBase = panda::ecmascript::base::BuiltinsBase; using JSArray = panda::ecmascript::JSArray; namespace panda::test { class BuiltinsReflectTest : public BaseTestWithScope { }; // use for create a JSObject of test static JSHandle TestObjectCreate(JSThread *thread) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); return JSHandle::Cast(env->GetObjectFunction()); } // native function for test Reflect.apply JSTaggedValue TestReflectApply(EcmaRuntimeCallInfo *argv) { auto thread = argv->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += BuiltinsBase::GetCallArg(argv, index).GetTaggedValue().GetInt(); } JSHandle thisValue = BuiltinsBase::GetThis(argv); JSTaggedValue testA = JSObject::GetProperty(thread, thisValue, JSHandle(factory->NewFromASCII("test_reflect_apply_a"))).GetValue().GetTaggedValue(); JSTaggedValue testB = JSObject::GetProperty(thread, thisValue, JSHandle(factory->NewFromASCII("test_reflect_apply_b"))).GetValue().GetTaggedValue(); result = result + testA.GetInt() + testB.GetInt(); return BuiltinsBase::GetTaggedInt(result); } // Reflect.apply (target, thisArgument, argumentsList) HWTEST_F_L0(BuiltinsReflectTest, ReflectApply) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSFunction(env, reinterpret_cast(TestReflectApply)); // thisArgument JSHandle thisArgument = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); JSObject::SetProperty(thread, JSHandle(thisArgument), JSHandle(factory->NewFromASCII("test_reflect_apply_a")), JSHandle(thread, JSTaggedValue(11))); JSObject::SetProperty(thread, JSHandle(thisArgument), JSHandle(factory->NewFromASCII("test_reflect_apply_b")), JSHandle(thread, JSTaggedValue(22))); // argumentsList JSHandle argumentsList(JSArray::ArrayCreate(thread, JSTaggedNumber(2))); PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(33))); JSArray::DefineOwnProperty(thread, argumentsList, JSHandle(thread, JSTaggedValue(0)), desc); PropertyDescriptor desc1(thread, JSHandle(thread, JSTaggedValue(44))); JSArray::DefineOwnProperty(thread, argumentsList, JSHandle(thread, JSTaggedValue(1)), desc1); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(*thisArgument)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(*argumentsList)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectApply(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(110).GetRawData()); JSObject::DeleteProperty(thread, (thisArgument), JSHandle(factory->NewFromASCII("test_reflect_apply_a"))); JSObject::DeleteProperty(thread, (thisArgument), JSHandle(factory->NewFromASCII("test_reflect_apply_b"))); TestHelper::TearDownFrame(thread, prev); } // Reflect.construct (target, argumentsList [ , newTarget]) HWTEST_F_L0(BuiltinsReflectTest, ReflectConstruct) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = JSHandle::Cast(env->GetStringFunction()); // argumentsList JSHandle argumentsList(JSArray::ArrayCreate(thread, JSTaggedNumber(1))); PropertyDescriptor desc(thread, JSHandle::Cast(factory->NewFromASCII("ReflectConstruct"))); JSArray::DefineOwnProperty(thread, argumentsList, JSHandle(thread, JSTaggedValue(0)), desc); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(*argumentsList)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectConstruct(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle taggedResult(thread, result); JSHandle refResult = JSHandle::Cast(taggedResult); JSHandle ruler = factory->NewFromASCII("ReflectConstruct"); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(thread, EcmaString::Cast(refResult->GetValue())), ruler), 0); TestHelper::TearDownFrame(thread, prev); } // Reflect.defineProperty (target, propertyKey, attributes) HWTEST_F_L0(BuiltinsReflectTest, ReflectDefineProperty) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // propertyKey JSHandle key(factory->NewFromASCII("test_reflect_define_property")); // attributes JSHandle attributes = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // attributes value auto globalConst = thread->GlobalConstants(); JSHandle valueKey = globalConst->GetHandledValueString(); JSHandle value(thread, JSTaggedValue(100)); JSObject::SetProperty(thread, JSHandle(attributes), valueKey, value); // attributes writable JSHandle writableKey = globalConst->GetHandledWritableString(); JSHandle writable(thread, JSTaggedValue::True()); JSObject::SetProperty(thread, JSHandle(attributes), writableKey, writable); // attributes enumerable JSHandle enumerableKey = globalConst->GetHandledEnumerableString(); JSHandle enumerable(thread, JSTaggedValue::False()); JSObject::SetProperty(thread, JSHandle(attributes), enumerableKey, enumerable); // attributes configurable JSHandle configurableKey = globalConst->GetHandledConfigurableString(); JSHandle configurable(thread, JSTaggedValue::True()); JSObject::SetProperty(thread, JSHandle(attributes), configurableKey, configurable); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(*attributes)); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectDefineProperty(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); PropertyDescriptor descRuler(thread); JSObject::GetOwnProperty(thread, target, key, descRuler); ASSERT_EQ(descRuler.GetValue()->GetInt(), 100); ASSERT_EQ(descRuler.IsWritable(), true); ASSERT_EQ(descRuler.IsEnumerable(), false); ASSERT_EQ(descRuler.IsConfigurable(), true); TestHelper::TearDownFrame(thread, prev); } // Reflect.deleteProperty (target, propertyKey) HWTEST_F_L0(BuiltinsReflectTest, ReflectDeleteProperty) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // propertyKey JSHandle key(factory->NewFromASCII("test_reflect_delete_property")); JSHandle value(thread, JSTaggedValue(101)); JSObject::SetProperty(thread, JSHandle(target), key, value); PropertyDescriptor desc(thread); ASSERT_EQ(JSObject::GetOwnProperty(thread, target, key, desc), true); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectDeleteProperty(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(JSObject::GetOwnProperty(thread, target, key, desc), false); TestHelper::TearDownFrame(thread, prev); } // Reflect.get (target, propertyKey [ , receiver]) HWTEST_F_L0(BuiltinsReflectTest, ReflectGet) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // propertyKey JSHandle key(factory->NewFromASCII("test_reflect_get")); // set property JSHandle value(thread, JSTaggedValue(101.5)); JSObject::SetProperty(thread, JSHandle(target), key, value); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectGet(ecmaRuntimeCallInfo); JSHandle resultValue(thread, result); ASSERT_EQ(resultValue->GetDouble(), 101.5); TestHelper::TearDownFrame(thread, prev); } // Reflect.getOwnPropertyDescriptor ( target, propertyKey ) HWTEST_F_L0(BuiltinsReflectTest, ReflectGetOwnPropertyDescriptor) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // propertyKey JSHandle key(factory->NewFromASCII("test_reflect_get_property_descriptor")); PropertyDescriptor desc(thread, JSHandle(thread, JSTaggedValue(102)), true, false, true); ASSERT_EQ(JSTaggedValue::DefinePropertyOrThrow(thread, JSHandle(target), key, desc), true); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectGetOwnPropertyDescriptor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultObj(thread, result); // test value auto globalConst = thread->GlobalConstants(); JSHandle valueKey = globalConst->GetHandledValueString(); JSHandle resultValue = JSObject::GetProperty(thread, resultObj, valueKey).GetValue(); ASSERT_EQ(resultValue->GetInt(), 102); // test writable JSHandle writableKey = globalConst->GetHandledWritableString(); JSHandle resultWritable = JSObject::GetProperty(thread, resultObj, writableKey).GetValue(); ASSERT_EQ(resultWritable->ToBoolean(), true); // test enumerable JSHandle enumerableKey = globalConst->GetHandledEnumerableString(); JSHandle resultEnumerable = JSObject::GetProperty(thread, resultObj, enumerableKey).GetValue(); ASSERT_EQ(resultEnumerable->ToBoolean(), false); // test configurable JSHandle configurableKey = globalConst->GetHandledConfigurableString(); JSHandle resultConfigurable = JSObject::GetProperty(thread, resultObj, configurableKey).GetValue(); ASSERT_EQ(resultConfigurable->ToBoolean(), true); TestHelper::TearDownFrame(thread, prev); } // Reflect.getPrototypeOf (target) HWTEST_F_L0(BuiltinsReflectTest, ReflectGetPrototypeOf) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); JSHandle proto = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); ASSERT_EQ(JSObject::SetPrototype(thread, target, JSHandle(proto)), true); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectGetPrototypeOf(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultObj(thread, JSTaggedValue(reinterpret_cast(result.GetRawData()))); ASSERT_EQ(JSTaggedValue::SameValue(resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); TestHelper::TearDownFrame(thread, prev); } // Reflect.has (target, propertyKey) HWTEST_F_L0(BuiltinsReflectTest, ReflectHas) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // propertyKey JSHandle key(factory->NewFromASCII("test_reflect_has")); JSHandle value(thread, JSTaggedValue(103)); ASSERT_EQ(JSObject::SetProperty(thread, JSHandle(target), key, value), true); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectHas(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); TestHelper::TearDownFrame(thread, prev); } // Reflect.isExtensible (target) HWTEST_F_L0(BuiltinsReflectTest, ReflectIsExtensible) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); target->GetJSHClass()->SetExtensible(false); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectIsExtensible(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); TestHelper::TearDownFrame(thread, prev); } // Reflect.ownKeys (target) HWTEST_F_L0(BuiltinsReflectTest, ReflectOwnKeys) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); JSHandle key0(factory->NewFromASCII("test_reflect_own_keys1")); JSHandle value0(thread, JSTaggedValue(104)); ASSERT_EQ(JSObject::SetProperty(thread, JSHandle(target), key0, value0), true); JSHandle key1(factory->NewFromASCII("test_reflect_own_keys2")); JSHandle value1(thread, JSTaggedValue(105)); ASSERT_EQ(JSObject::SetProperty(thread, JSHandle(target), key1, value1), true); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectOwnKeys(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultTaggedValue(thread, reinterpret_cast(result.GetRawData())); JSHandle resultArray = JSHandle::Cast(resultTaggedValue); // test length JSHandle resultLengthKey = thread->GlobalConstants()->GetHandledLengthString(); JSHandle resultLength = JSObject::GetProperty(thread, JSHandle(resultArray), resultLengthKey).GetValue(); ASSERT_EQ(resultLength->GetInt(), 2); // test array[0] JSHandle resultKey0(thread, JSTaggedValue(0)); JSHandle resultValue0 = JSObject::GetProperty(thread, JSHandle(resultArray), resultKey0).GetValue(); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(resultValue0), JSHandle(key0)), 0); // test array[1] JSHandle resultKey1(thread, JSTaggedValue(1)); JSHandle resultValue1 = JSObject::GetProperty(thread, JSHandle(resultArray), resultKey1).GetValue(); ASSERT_EQ(EcmaStringAccessor::Compare(instance, JSHandle(resultValue1), JSHandle(key1)), 0); TestHelper::TearDownFrame(thread, prev); } // Reflect.preventExtensions (target) HWTEST_F_L0(BuiltinsReflectTest, ReflectPreventExtensions) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); target->GetJSHClass()->SetExtensible(true); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectPreventExtensions(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(target->IsExtensible(), false); TestHelper::TearDownFrame(thread, prev); } // Reflect.set (target, propertyKey, V [ , receiver]) HWTEST_F_L0(BuiltinsReflectTest, ReflectSet) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); // target JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); // propertyKey JSHandle key(factory->NewFromASCII("test_reflect_set")); // value JSHandle value(thread, JSTaggedValue(106)); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, value.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectSet(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle ruler = JSObject::GetProperty(thread, JSHandle(target), key).GetValue(); ASSERT_EQ(JSTaggedValue::ToInt32(thread, ruler), 106); TestHelper::TearDownFrame(thread, prev); } // Reflect.setPrototypeOf (target, proto) HWTEST_F_L0(BuiltinsReflectTest, ReflectSetPrototypeOf) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle target = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); JSHandle proto = factory->NewJSObjectByConstructor(TestObjectCreate(thread), JSHandle(TestObjectCreate(thread))); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, proto.GetTaggedValue()); [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); JSTaggedValue result = BuiltinsReflect::ReflectSetPrototypeOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle resultObj(thread, target->GetJSHClass()->GetPrototype()); ASSERT_EQ(JSTaggedValue::SameValue(resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test