14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#include "ecmascript/builtins/builtins_object.h"
174514f5e3Sopenharmony_ci
184514f5e3Sopenharmony_ci#include "ecmascript/builtins/builtins_map.h"
194514f5e3Sopenharmony_ci#include "ecmascript/interpreter/interpreter.h"
204514f5e3Sopenharmony_ci#include "ecmascript/js_primitive_ref.h"
214514f5e3Sopenharmony_ci#include "ecmascript/object_fast_operator-inl.h"
224514f5e3Sopenharmony_ci
234514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
244514f5e3Sopenharmony_ci// 19.1.1.1 Object ( [ value ] )
254514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ObjectConstructor(EcmaRuntimeCallInfo *argv)
264514f5e3Sopenharmony_ci{
274514f5e3Sopenharmony_ci    ASSERT(argv);
284514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
294514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Constructor);
304514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
314514f5e3Sopenharmony_ci    auto ecmaVm = thread->GetEcmaVM();
324514f5e3Sopenharmony_ci    JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
334514f5e3Sopenharmony_ci
344514f5e3Sopenharmony_ci    // 1.If NewTarget is neither undefined nor the active function, then
354514f5e3Sopenharmony_ci    //    a.Return OrdinaryCreateFromConstructor(NewTarget, "%ObjectPrototype%").
364514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
374514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
384514f5e3Sopenharmony_ci    if (!newTarget->IsUndefined() && !(newTarget.GetTaggedValue() == constructor.GetTaggedValue())) {
394514f5e3Sopenharmony_ci        JSHandle<JSObject> obj =
404514f5e3Sopenharmony_ci            ecmaVm->GetFactory()->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
414514f5e3Sopenharmony_ci        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
424514f5e3Sopenharmony_ci        return obj.GetTaggedValue();
434514f5e3Sopenharmony_ci    }
444514f5e3Sopenharmony_ci
454514f5e3Sopenharmony_ci    // 2.If value is null, undefined or not supplied, return ObjectCreate(%ObjectPrototype%).
464514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
474514f5e3Sopenharmony_ci    if (value->IsNull() || value->IsUndefined()) {
484514f5e3Sopenharmony_ci        JSHandle<JSObject> obj = ecmaVm->GetFactory()->OrdinaryNewJSObjectCreate(env->GetObjectFunctionPrototype());
494514f5e3Sopenharmony_ci        return obj.GetTaggedValue();
504514f5e3Sopenharmony_ci    }
514514f5e3Sopenharmony_ci
524514f5e3Sopenharmony_ci    // 3.Return ToObject(value).
534514f5e3Sopenharmony_ci    return JSTaggedValue::ToObject(thread, value).GetTaggedValue();
544514f5e3Sopenharmony_ci}
554514f5e3Sopenharmony_ci
564514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::AssignTaggedValue(JSThread *thread, const JSHandle<JSTaggedValue> &source,
574514f5e3Sopenharmony_ci                                                const JSHandle<JSObject> &toAssign)
584514f5e3Sopenharmony_ci{
594514f5e3Sopenharmony_ci    JSHandle<JSObject> from = JSTaggedValue::ToObject(thread, source);
604514f5e3Sopenharmony_ci    JSHandle<TaggedArray> keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle<JSTaggedValue>::Cast(from));
614514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
624514f5e3Sopenharmony_ci
634514f5e3Sopenharmony_ci    JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
644514f5e3Sopenharmony_ci    uint32_t keysLen = keys->GetLength();
654514f5e3Sopenharmony_ci    for (uint32_t j = 0; j < keysLen; j++) {
664514f5e3Sopenharmony_ci        PropertyDescriptor desc(thread);
674514f5e3Sopenharmony_ci        key.Update(keys->Get(j));
684514f5e3Sopenharmony_ci        bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(from), key, desc);
694514f5e3Sopenharmony_ci        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
704514f5e3Sopenharmony_ci
714514f5e3Sopenharmony_ci        if (success && desc.IsEnumerable()) {
724514f5e3Sopenharmony_ci            JSTaggedValue value = desc.GetValue().GetTaggedValue();
734514f5e3Sopenharmony_ci            if (value.IsUndefined() || JSHandle<JSTaggedValue>::Cast(from)->IsJSProxy()) {
744514f5e3Sopenharmony_ci                value = ObjectFastOperator::FastGetPropertyByValue(thread, from.GetTaggedValue(),
754514f5e3Sopenharmony_ci                                                                   key.GetTaggedValue());
764514f5e3Sopenharmony_ci            }
774514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
784514f5e3Sopenharmony_ci
794514f5e3Sopenharmony_ci            ObjectFastOperator::FastSetPropertyByValue(thread, toAssign.GetTaggedValue(), key.GetTaggedValue(),
804514f5e3Sopenharmony_ci                                                       value);
814514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
824514f5e3Sopenharmony_ci        }
834514f5e3Sopenharmony_ci    }
844514f5e3Sopenharmony_ci    return JSTaggedValue::Undefined();
854514f5e3Sopenharmony_ci}
864514f5e3Sopenharmony_ci
874514f5e3Sopenharmony_ci// 19.1.2.1 Object.assign ( target, ...sources )
884514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv)
894514f5e3Sopenharmony_ci{
904514f5e3Sopenharmony_ci    ASSERT(argv);
914514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
924514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Assign);
934514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
944514f5e3Sopenharmony_ci
954514f5e3Sopenharmony_ci    uint32_t numArgs = argv->GetArgsNumber();
964514f5e3Sopenharmony_ci    // 1.Let to be ToObject(target).
974514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> target = GetCallArg(argv, 0);
984514f5e3Sopenharmony_ci    JSHandle<JSObject> toAssign = JSTaggedValue::ToObject(thread, target);
994514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(to).
1004514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1014514f5e3Sopenharmony_ci
1024514f5e3Sopenharmony_ci    // 3.If only one argument was passed, return to.
1034514f5e3Sopenharmony_ci    // 4.Let sources be the List of argument values starting with the second argument.
1044514f5e3Sopenharmony_ci    // 5.For each element nextSource of sources, in ascending index order
1054514f5e3Sopenharmony_ci    //   a.If nextSource is undefined or null, let keys be an empty List.
1064514f5e3Sopenharmony_ci    //   b.Else,
1074514f5e3Sopenharmony_ci    //     i.Let from be ToObject(nextSource).
1084514f5e3Sopenharmony_ci    //     ii.Let keys be from.[[OwnPropertyKeys]]().
1094514f5e3Sopenharmony_ci    //     iii.ReturnIfAbrupt(keys).
1104514f5e3Sopenharmony_ci    JSMutableHandle<JSTaggedValue> key(thread, JSTaggedValue::Undefined());
1114514f5e3Sopenharmony_ci    for (uint32_t i = 1; i < numArgs; i++) {
1124514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> source = GetCallArg(argv, i);
1134514f5e3Sopenharmony_ci        if (!source->IsNull() && !source->IsUndefined()) {
1144514f5e3Sopenharmony_ci            JSHandle<JSObject> from = JSTaggedValue::ToObject(thread, source);
1154514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1164514f5e3Sopenharmony_ci
1174514f5e3Sopenharmony_ci            JSHandle<TaggedArray> keys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle<JSTaggedValue>::Cast(from));
1184514f5e3Sopenharmony_ci            // ReturnIfAbrupt(keys)
1194514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1204514f5e3Sopenharmony_ci
1214514f5e3Sopenharmony_ci            // c.Repeat for each element nextKey of keys in List order,
1224514f5e3Sopenharmony_ci            //    i.Let desc be from.[[GetOwnProperty]](nextKey).
1234514f5e3Sopenharmony_ci            //    ii.ReturnIfAbrupt(desc).
1244514f5e3Sopenharmony_ci            //    iii.if desc is not undefined and desc.[[Enumerable]] is true, then
1254514f5e3Sopenharmony_ci            //      1.Let propValue be Get(from, nextKey).
1264514f5e3Sopenharmony_ci            //      2.ReturnIfAbrupt(propValue).
1274514f5e3Sopenharmony_ci            //      3.Let status be Set(to, nextKey, propValue, true).
1284514f5e3Sopenharmony_ci            //      4.ReturnIfAbrupt(status).
1294514f5e3Sopenharmony_ci            uint32_t keysLen = keys->GetLength();
1304514f5e3Sopenharmony_ci            for (uint32_t j = 0; j < keysLen; j++) {
1314514f5e3Sopenharmony_ci                PropertyDescriptor desc(thread);
1324514f5e3Sopenharmony_ci                key.Update(keys->Get(j));
1334514f5e3Sopenharmony_ci                bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(from), key, desc);
1344514f5e3Sopenharmony_ci                // ReturnIfAbrupt(desc)
1354514f5e3Sopenharmony_ci                RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1364514f5e3Sopenharmony_ci
1374514f5e3Sopenharmony_ci                if (success && desc.IsEnumerable()) {
1384514f5e3Sopenharmony_ci                    JSTaggedValue value = desc.GetValue().GetTaggedValue();
1394514f5e3Sopenharmony_ci                    if (value.IsUndefined() || JSHandle<JSTaggedValue>::Cast(from)->IsJSProxy()) {
1404514f5e3Sopenharmony_ci                        value = ObjectFastOperator::FastGetPropertyByValue(thread, from.GetTaggedValue(),
1414514f5e3Sopenharmony_ci                                                                           key.GetTaggedValue());
1424514f5e3Sopenharmony_ci                    }
1434514f5e3Sopenharmony_ci                    // ReturnIfAbrupt(prop_value)
1444514f5e3Sopenharmony_ci                    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1454514f5e3Sopenharmony_ci
1464514f5e3Sopenharmony_ci                    ObjectFastOperator::FastSetPropertyByValue(thread, toAssign.GetTaggedValue(), key.GetTaggedValue(),
1474514f5e3Sopenharmony_ci                                                               value);
1484514f5e3Sopenharmony_ci                    //  ReturnIfAbrupt(status)
1494514f5e3Sopenharmony_ci                    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1504514f5e3Sopenharmony_ci                }
1514514f5e3Sopenharmony_ci            }
1524514f5e3Sopenharmony_ci        }
1534514f5e3Sopenharmony_ci    }
1544514f5e3Sopenharmony_ci
1554514f5e3Sopenharmony_ci    // 6.Return to.
1564514f5e3Sopenharmony_ci    return toAssign.GetTaggedValue();
1574514f5e3Sopenharmony_ci}
1584514f5e3Sopenharmony_ci
1594514f5e3Sopenharmony_ci// Runtime Semantics
1604514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ObjectDefineProperties(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
1614514f5e3Sopenharmony_ci                                                     const JSHandle<JSTaggedValue> &prop)
1624514f5e3Sopenharmony_ci{
1634514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, DefineProperties);
1644514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
1654514f5e3Sopenharmony_ci    // 1.If Type(O) is not Object, throw a TypeError exception.
1664514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
1674514f5e3Sopenharmony_ci        // throw a TypeError exception
1684514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "is not an object", JSTaggedValue::Exception());
1694514f5e3Sopenharmony_ci    }
1704514f5e3Sopenharmony_ci
1714514f5e3Sopenharmony_ci    // 2.Let props be ToObject(Properties).
1724514f5e3Sopenharmony_ci    JSHandle<JSObject> props = JSTaggedValue::ToObject(thread, prop);
1734514f5e3Sopenharmony_ci
1744514f5e3Sopenharmony_ci    // 3.ReturnIfAbrupt(props).
1754514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1764514f5e3Sopenharmony_ci
1774514f5e3Sopenharmony_ci    // 4.Let keys be props.[[OwnPropertyKeys]]().
1784514f5e3Sopenharmony_ci    JSHandle<TaggedArray> handleKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle<JSTaggedValue>::Cast(props));
1794514f5e3Sopenharmony_ci
1804514f5e3Sopenharmony_ci    // 5.ReturnIfAbrupt(keys).
1814514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
1824514f5e3Sopenharmony_ci
1834514f5e3Sopenharmony_ci    // 6.Let descriptors be an empty List.
1844514f5e3Sopenharmony_ci    // new an empty array and append
1854514f5e3Sopenharmony_ci    uint32_t length = handleKeys->GetLength();
1864514f5e3Sopenharmony_ci    [[maybe_unused]] JSHandle<TaggedArray> descriptors =
1874514f5e3Sopenharmony_ci        factory->NewTaggedArray(2 * length);  // 2: 2 means two element list
1884514f5e3Sopenharmony_ci
1894514f5e3Sopenharmony_ci    // 7.Repeat for each element nextKey of keys in List order,
1904514f5e3Sopenharmony_ci    //   a.Let propDesc be props.[[GetOwnProperty]](nextKey).
1914514f5e3Sopenharmony_ci    //   b.ReturnIfAbrupt(propDesc).
1924514f5e3Sopenharmony_ci    //   c.If propDesc is not undefined and propDesc.[[Enumerable]] is true, then
1934514f5e3Sopenharmony_ci    //     i.Let descObj be Get( props, nextKey).
1944514f5e3Sopenharmony_ci    //     ii.ReturnIfAbrupt(descObj).
1954514f5e3Sopenharmony_ci    //     iii.Let desc be ToPropertyDescriptor(descObj).
1964514f5e3Sopenharmony_ci    //     iv.ReturnIfAbrupt(desc).
1974514f5e3Sopenharmony_ci    //     v.Append the pair (a two element List) consisting of nextKey and desc to the end of descriptors.
1984514f5e3Sopenharmony_ci
1994514f5e3Sopenharmony_ci    std::vector<PropertyDescriptor> desArr;
2004514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < length; i++) {
2014514f5e3Sopenharmony_ci        PropertyDescriptor propDesc(thread);
2024514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> handleKey(thread, handleKeys->Get(i));
2034514f5e3Sopenharmony_ci
2044514f5e3Sopenharmony_ci        bool success = JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(props), handleKey, propDesc);
2054514f5e3Sopenharmony_ci        // ReturnIfAbrupt(propDesc)
2064514f5e3Sopenharmony_ci        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2074514f5e3Sopenharmony_ci
2084514f5e3Sopenharmony_ci        if (success && propDesc.IsEnumerable()) {
2094514f5e3Sopenharmony_ci            JSHandle<JSTaggedValue> descObj =
2104514f5e3Sopenharmony_ci                JSTaggedValue::GetProperty(thread, JSHandle<JSTaggedValue>::Cast(props), handleKey).GetValue();
2114514f5e3Sopenharmony_ci            // ReturnIfAbrupt(descObj)
2124514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2134514f5e3Sopenharmony_ci
2144514f5e3Sopenharmony_ci            PropertyDescriptor desc(thread);
2154514f5e3Sopenharmony_ci            JSObject::ToPropertyDescriptor(thread, descObj, desc);
2164514f5e3Sopenharmony_ci            // ReturnIfAbrupt(desc)
2174514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2184514f5e3Sopenharmony_ci            desc.SetKey(handleKey);
2194514f5e3Sopenharmony_ci            desArr.emplace_back(desc);
2204514f5e3Sopenharmony_ci        }
2214514f5e3Sopenharmony_ci    }
2224514f5e3Sopenharmony_ci    uint32_t desLength = desArr.size();
2234514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < desLength; i++) {
2244514f5e3Sopenharmony_ci        // 8.For each pair from descriptors in list order,
2254514f5e3Sopenharmony_ci        //   a.Let P be the first element of pair.
2264514f5e3Sopenharmony_ci        //   b.Let desc be the second element of pair.
2274514f5e3Sopenharmony_ci        //   c.Let status be DefinePropertyOrThrow(O,P, desc).
2284514f5e3Sopenharmony_ci        //   d.ReturnIfAbrupt(status).
2294514f5e3Sopenharmony_ci        [[maybe_unused]] bool setSuccess =
2304514f5e3Sopenharmony_ci            JSTaggedValue::DefinePropertyOrThrow(thread, obj, desArr[i].GetKey(), desArr[i]);
2314514f5e3Sopenharmony_ci
2324514f5e3Sopenharmony_ci        // ReturnIfAbrupt(status)
2334514f5e3Sopenharmony_ci        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2344514f5e3Sopenharmony_ci    }
2354514f5e3Sopenharmony_ci    // 9.Return O.
2364514f5e3Sopenharmony_ci    return obj.GetTaggedValue();
2374514f5e3Sopenharmony_ci}
2384514f5e3Sopenharmony_ci
2394514f5e3Sopenharmony_ci// 19.1.2.2 Object.create ( O [ , Properties ] )
2404514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Create(EcmaRuntimeCallInfo *argv)
2414514f5e3Sopenharmony_ci{
2424514f5e3Sopenharmony_ci    ASSERT(argv);
2434514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
2444514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Create);
2454514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
2464514f5e3Sopenharmony_ci    // 1.If Type(O) is neither Object nor Null, throw a TypeError exception.
2474514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
2484514f5e3Sopenharmony_ci    if (!obj->IsECMAObject() && !obj->IsNull()) {
2494514f5e3Sopenharmony_ci        // throw a TypeError exception
2504514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "Create: O is neither Object nor Null", JSTaggedValue::Exception());
2514514f5e3Sopenharmony_ci    }
2524514f5e3Sopenharmony_ci
2534514f5e3Sopenharmony_ci    if (obj->IsJSShared()) {
2544514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, GET_MESSAGE_STRING(CreateObjectWithSendableProto),
2554514f5e3Sopenharmony_ci                                    JSTaggedValue::Exception());
2564514f5e3Sopenharmony_ci    }
2574514f5e3Sopenharmony_ci
2584514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> properties = GetCallArg(argv, 1);
2594514f5e3Sopenharmony_ci
2604514f5e3Sopenharmony_ci    // 2.Let obj be ObjectCreate(O).
2614514f5e3Sopenharmony_ci    JSHandle<JSObject> objCreate = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(obj);
2624514f5e3Sopenharmony_ci
2634514f5e3Sopenharmony_ci    // 3.If the argument Properties is present and not undefined, then
2644514f5e3Sopenharmony_ci    //   a.Return ObjectDefineProperties(obj, Properties).
2654514f5e3Sopenharmony_ci    if (!properties->IsUndefined()) {
2664514f5e3Sopenharmony_ci        return ObjectDefineProperties(thread, JSHandle<JSTaggedValue>::Cast(objCreate), properties);
2674514f5e3Sopenharmony_ci    }
2684514f5e3Sopenharmony_ci
2694514f5e3Sopenharmony_ci    // 4.Return obj.
2704514f5e3Sopenharmony_ci    return objCreate.GetTaggedValue();
2714514f5e3Sopenharmony_ci}
2724514f5e3Sopenharmony_ci
2734514f5e3Sopenharmony_ci// 19.1.2.3 Object.defineProperties ( O, Properties )
2744514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::DefineProperties(EcmaRuntimeCallInfo *argv)
2754514f5e3Sopenharmony_ci{
2764514f5e3Sopenharmony_ci    ASSERT(argv);
2774514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
2784514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, DefineProperties);
2794514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
2804514f5e3Sopenharmony_ci    // 1.Return ObjectDefineProperties(O, Properties).
2814514f5e3Sopenharmony_ci    return ObjectDefineProperties(thread, GetCallArg(argv, 0), GetCallArg(argv, 1));
2824514f5e3Sopenharmony_ci}
2834514f5e3Sopenharmony_ci
2844514f5e3Sopenharmony_ci// 19.1.2.4 Object.defineProperty ( O, P, Attributes )
2854514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::DefineProperty(EcmaRuntimeCallInfo *argv)
2864514f5e3Sopenharmony_ci{
2874514f5e3Sopenharmony_ci    ASSERT(argv);
2884514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
2894514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, DefineProperty);
2904514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
2914514f5e3Sopenharmony_ci
2924514f5e3Sopenharmony_ci    // 1.If Type(O) is not Object, throw a TypeError exception.
2934514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
2944514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
2954514f5e3Sopenharmony_ci        // throw a TypeError
2964514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "DefineProperty: O is not Object", JSTaggedValue::Exception());
2974514f5e3Sopenharmony_ci    }
2984514f5e3Sopenharmony_ci
2994514f5e3Sopenharmony_ci    // 2.Let key be ToPropertyKey(P).
3004514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> prop = GetCallArg(argv, 1);
3014514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> key = JSTaggedValue::ToPropertyKey(thread, prop);
3024514f5e3Sopenharmony_ci
3034514f5e3Sopenharmony_ci    // 3.ReturnIfAbrupt(key).
3044514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3054514f5e3Sopenharmony_ci    // 4.Let desc be ToPropertyDescriptor(Attributes).
3064514f5e3Sopenharmony_ci    PropertyDescriptor desc(thread);
3074514f5e3Sopenharmony_ci    JSObject::ToPropertyDescriptor(thread, GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD), desc);
3084514f5e3Sopenharmony_ci
3094514f5e3Sopenharmony_ci    // 5.ReturnIfAbrupt(desc).
3104514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3114514f5e3Sopenharmony_ci
3124514f5e3Sopenharmony_ci    // 6.Let success be DefinePropertyOrThrow(O,key, desc).
3134514f5e3Sopenharmony_ci    [[maybe_unused]] bool success = JSTaggedValue::DefinePropertyOrThrow(thread, obj, key, desc);
3144514f5e3Sopenharmony_ci
3154514f5e3Sopenharmony_ci    // 7.ReturnIfAbrupt(success).
3164514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3174514f5e3Sopenharmony_ci    // 8.Return O.
3184514f5e3Sopenharmony_ci    return obj.GetTaggedValue();
3194514f5e3Sopenharmony_ci}
3204514f5e3Sopenharmony_ci
3214514f5e3Sopenharmony_ci// 19.1.2.5 Object.freeze ( O )
3224514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Freeze(EcmaRuntimeCallInfo *argv)
3234514f5e3Sopenharmony_ci{
3244514f5e3Sopenharmony_ci    ASSERT(argv);
3254514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
3264514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Freeze);
3274514f5e3Sopenharmony_ci
3284514f5e3Sopenharmony_ci    // 1.If Type(O) is not Object, return O.
3294514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
3304514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
3314514f5e3Sopenharmony_ci        return obj.GetTaggedValue();
3324514f5e3Sopenharmony_ci    }
3334514f5e3Sopenharmony_ci
3344514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
3354514f5e3Sopenharmony_ci    bool status = false;
3364514f5e3Sopenharmony_ci    // 2.Let status be SetIntegrityLevel( O, "frozen").
3374514f5e3Sopenharmony_ci    if (obj->IsJSSharedObject() || obj->IsJSSharedFunction() || obj->IsJSSharedAsyncFunction()) {
3384514f5e3Sopenharmony_ci        status = JSObject::FreezeSharedObject(thread, JSHandle<JSObject>(obj));
3394514f5e3Sopenharmony_ci    } else if (obj->IsJSSharedArray()) {
3404514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, GET_MESSAGE_STRING(UpdateSendableAttributes), JSTaggedValue::Exception());
3414514f5e3Sopenharmony_ci    } else {
3424514f5e3Sopenharmony_ci        status = JSObject::SetIntegrityLevel(thread, JSHandle<JSObject>(obj), IntegrityLevel::FROZEN);
3434514f5e3Sopenharmony_ci    }
3444514f5e3Sopenharmony_ci
3454514f5e3Sopenharmony_ci    // 3.ReturnIfAbrupt(status).
3464514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3474514f5e3Sopenharmony_ci
3484514f5e3Sopenharmony_ci    // 4.If status is false, throw a TypeError exception.
3494514f5e3Sopenharmony_ci    if (!status) {
3504514f5e3Sopenharmony_ci        // throw a TypeError exception
3514514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "Freeze: freeze failed", JSTaggedValue::Exception());
3524514f5e3Sopenharmony_ci    }
3534514f5e3Sopenharmony_ci
3544514f5e3Sopenharmony_ci    // 5.Return O.
3554514f5e3Sopenharmony_ci    return obj.GetTaggedValue();
3564514f5e3Sopenharmony_ci}
3574514f5e3Sopenharmony_ci
3584514f5e3Sopenharmony_ci// 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P )
3594514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetOwnPropertyDescriptor(EcmaRuntimeCallInfo *argv)
3604514f5e3Sopenharmony_ci{
3614514f5e3Sopenharmony_ci    ASSERT(argv);
3624514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
3634514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetOwnPropertyDescriptor);
3644514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
3654514f5e3Sopenharmony_ci
3664514f5e3Sopenharmony_ci    // 1.Let obj be ToObject(O).
3674514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> func = GetCallArg(argv, 0);
3684514f5e3Sopenharmony_ci    JSHandle<JSObject> handle = JSTaggedValue::ToObject(thread, func);
3694514f5e3Sopenharmony_ci
3704514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(obj).
3714514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3724514f5e3Sopenharmony_ci
3734514f5e3Sopenharmony_ci    // 3.Let key be ToPropertyKey(P).
3744514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> prop = GetCallArg(argv, 1);
3754514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> key = JSTaggedValue::ToPropertyKey(thread, prop);
3764514f5e3Sopenharmony_ci
3774514f5e3Sopenharmony_ci    // 4.ReturnIfAbrupt(key).
3784514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3794514f5e3Sopenharmony_ci
3804514f5e3Sopenharmony_ci    // 5.Let desc be obj.[[GetOwnProperty]](key).
3814514f5e3Sopenharmony_ci    PropertyDescriptor desc(thread);
3824514f5e3Sopenharmony_ci    JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(handle), key, desc);
3834514f5e3Sopenharmony_ci
3844514f5e3Sopenharmony_ci    // 6.ReturnIfAbrupt(desc).
3854514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
3864514f5e3Sopenharmony_ci
3874514f5e3Sopenharmony_ci    // 7.Return FromPropertyDescriptor(desc).
3884514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> res = JSObject::FromPropertyDescriptor(thread, desc);
3894514f5e3Sopenharmony_ci    return res.GetTaggedValue();
3904514f5e3Sopenharmony_ci}
3914514f5e3Sopenharmony_ci
3924514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetOwnPropertyDescriptors(EcmaRuntimeCallInfo *argv)
3934514f5e3Sopenharmony_ci{
3944514f5e3Sopenharmony_ci    ASSERT(argv);
3954514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
3964514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetOwnPropertyDescriptors);
3974514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
3984514f5e3Sopenharmony_ci
3994514f5e3Sopenharmony_ci    // 1.Let obj be ToObject(O).
4004514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> func = GetCallArg(argv, 0);
4014514f5e3Sopenharmony_ci    JSHandle<JSObject> handle = JSTaggedValue::ToObject(thread, func);
4024514f5e3Sopenharmony_ci
4034514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(obj).
4044514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
4054514f5e3Sopenharmony_ci
4064514f5e3Sopenharmony_ci    // 3. Let ownKeys be ? obj.[[OwnPropertyKeys]]().
4074514f5e3Sopenharmony_ci    JSHandle<TaggedArray> ownKeys =
4084514f5e3Sopenharmony_ci        JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle<JSTaggedValue>(handle));
4094514f5e3Sopenharmony_ci
4104514f5e3Sopenharmony_ci    // 4.ReturnIfAbrupt(ownKeys).
4114514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
4124514f5e3Sopenharmony_ci
4134514f5e3Sopenharmony_ci    // 5.Let descriptors be OrdinaryObjectCreate(%Object.prototype%).
4144514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
4154514f5e3Sopenharmony_ci    JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
4164514f5e3Sopenharmony_ci    JSHandle<JSFunction> constructor(env->GetObjectFunction());
4174514f5e3Sopenharmony_ci    JSHandle<JSObject> descriptors = factory->NewJSObjectByConstructor(constructor);
4184514f5e3Sopenharmony_ci
4194514f5e3Sopenharmony_ci    // 6.For each element key of ownKeys, do
4204514f5e3Sopenharmony_ci    // a. Let desc be ? obj.[[GetOwnProperty]](key).
4214514f5e3Sopenharmony_ci    // b. Let descriptor be FromPropertyDescriptor(desc).
4224514f5e3Sopenharmony_ci    // c. If descriptor is not undefined, perform ! CreateDataPropertyOrThrow(descriptors, key, descriptor).
4234514f5e3Sopenharmony_ci    uint32_t length = ownKeys->GetLength();
4244514f5e3Sopenharmony_ci    JSMutableHandle<JSTaggedValue> handleKey(thread, JSTaggedValue::Undefined());
4254514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < length; ++i) {
4264514f5e3Sopenharmony_ci        handleKey.Update(ownKeys->Get(i));
4274514f5e3Sopenharmony_ci        PropertyDescriptor desc(thread);
4284514f5e3Sopenharmony_ci        JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(handle), handleKey, desc);
4294514f5e3Sopenharmony_ci        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
4304514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> descriptor = JSObject::FromPropertyDescriptor(thread, desc);
4314514f5e3Sopenharmony_ci        if (!descriptor->IsUndefined()) {
4324514f5e3Sopenharmony_ci            JSObject::CreateDataPropertyOrThrow(thread, descriptors, handleKey, descriptor);
4334514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
4344514f5e3Sopenharmony_ci        }
4354514f5e3Sopenharmony_ci    }
4364514f5e3Sopenharmony_ci
4374514f5e3Sopenharmony_ci    // 7.Return descriptors.
4384514f5e3Sopenharmony_ci    return descriptors.GetTaggedValue();
4394514f5e3Sopenharmony_ci}
4404514f5e3Sopenharmony_ci
4414514f5e3Sopenharmony_ci// Runtime Semantics
4424514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetOwnPropertyKeys(JSThread *thread, const JSHandle<JSTaggedValue> &object,
4434514f5e3Sopenharmony_ci                                                 const KeyType &type)
4444514f5e3Sopenharmony_ci{
4454514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetOwnPropertyKeys);
4464514f5e3Sopenharmony_ci    // 1.Let obj be ToObject(O).
4474514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
4484514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = JSTaggedValue::ToObject(thread, object);
4494514f5e3Sopenharmony_ci
4504514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(obj).
4514514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
4524514f5e3Sopenharmony_ci
4534514f5e3Sopenharmony_ci    // 3.Let keys be obj.[[OwnPropertyKeys]]().
4544514f5e3Sopenharmony_ci    JSHandle<TaggedArray> handleKeys = JSTaggedValue::GetOwnPropertyKeys(thread, JSHandle<JSTaggedValue>::Cast(obj));
4554514f5e3Sopenharmony_ci
4564514f5e3Sopenharmony_ci    // 4.ReturnIfAbrupt(keys).
4574514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
4584514f5e3Sopenharmony_ci
4594514f5e3Sopenharmony_ci    // 5.Let nameList be a new empty List.
4604514f5e3Sopenharmony_ci    // new an empty array and append
4614514f5e3Sopenharmony_ci    uint32_t length = handleKeys->GetLength();
4624514f5e3Sopenharmony_ci    JSHandle<TaggedArray> nameList = factory->NewTaggedArray(length);
4634514f5e3Sopenharmony_ci
4644514f5e3Sopenharmony_ci    // 6.Repeat for each element nextKey of keys in List order,
4654514f5e3Sopenharmony_ci    uint32_t copyLength = 0;
4664514f5e3Sopenharmony_ci    switch (type) {
4674514f5e3Sopenharmony_ci        case KeyType::STRING_TYPE: {
4684514f5e3Sopenharmony_ci            for (uint32_t i = 0; i < length; i++) {
4694514f5e3Sopenharmony_ci                JSTaggedValue key = handleKeys->Get(i);
4704514f5e3Sopenharmony_ci                if (key.IsString()) {
4714514f5e3Sopenharmony_ci                    nameList->Set(thread, copyLength, key);
4724514f5e3Sopenharmony_ci                    copyLength++;
4734514f5e3Sopenharmony_ci                }
4744514f5e3Sopenharmony_ci            }
4754514f5e3Sopenharmony_ci            break;
4764514f5e3Sopenharmony_ci        }
4774514f5e3Sopenharmony_ci        case KeyType::SYMBOL_TYPE: {
4784514f5e3Sopenharmony_ci            for (uint32_t i = 0; i < length; i++) {
4794514f5e3Sopenharmony_ci                JSTaggedValue key = handleKeys->Get(i);
4804514f5e3Sopenharmony_ci                if (key.IsSymbol()) {
4814514f5e3Sopenharmony_ci                    nameList->Set(thread, copyLength, key);
4824514f5e3Sopenharmony_ci                    copyLength++;
4834514f5e3Sopenharmony_ci                }
4844514f5e3Sopenharmony_ci            }
4854514f5e3Sopenharmony_ci            break;
4864514f5e3Sopenharmony_ci        }
4874514f5e3Sopenharmony_ci        default:
4884514f5e3Sopenharmony_ci            break;
4894514f5e3Sopenharmony_ci    }
4904514f5e3Sopenharmony_ci
4914514f5e3Sopenharmony_ci    // 7.Return CreateArrayFromList(nameList).
4924514f5e3Sopenharmony_ci    JSHandle<TaggedArray> resultList = factory->CopyArray(nameList, length, copyLength);
4934514f5e3Sopenharmony_ci    JSHandle<JSArray> resultArray = JSArray::CreateArrayFromList(thread, resultList);
4944514f5e3Sopenharmony_ci    return resultArray.GetTaggedValue();
4954514f5e3Sopenharmony_ci}
4964514f5e3Sopenharmony_ci
4974514f5e3Sopenharmony_ci// 19.1.2.7 Object.getOwnPropertyNames ( O )
4984514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetOwnPropertyNames(EcmaRuntimeCallInfo *argv)
4994514f5e3Sopenharmony_ci{
5004514f5e3Sopenharmony_ci    ASSERT(argv);
5014514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
5024514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetOwnPropertyNames);
5034514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
5044514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
5054514f5e3Sopenharmony_ci    KeyType type = KeyType::STRING_TYPE;
5064514f5e3Sopenharmony_ci
5074514f5e3Sopenharmony_ci    // 1.Return GetOwnPropertyKeys(O, String).
5084514f5e3Sopenharmony_ci    return GetOwnPropertyKeys(thread, obj, type);
5094514f5e3Sopenharmony_ci}
5104514f5e3Sopenharmony_ci
5114514f5e3Sopenharmony_ci// 19.1.2.8 Object.getOwnPropertySymbols ( O )
5124514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetOwnPropertySymbols(EcmaRuntimeCallInfo *argv)
5134514f5e3Sopenharmony_ci{
5144514f5e3Sopenharmony_ci    ASSERT(argv);
5154514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
5164514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetOwnPropertySymbols);
5174514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
5184514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
5194514f5e3Sopenharmony_ci    KeyType type = KeyType::SYMBOL_TYPE;
5204514f5e3Sopenharmony_ci
5214514f5e3Sopenharmony_ci    // 1.Return GetOwnPropertyKeys(O, Symbol).
5224514f5e3Sopenharmony_ci    return GetOwnPropertyKeys(thread, obj, type);
5234514f5e3Sopenharmony_ci}
5244514f5e3Sopenharmony_ci
5254514f5e3Sopenharmony_ci// 19.1.2.9 Object.getPrototypeOf ( O )
5264514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetPrototypeOf(EcmaRuntimeCallInfo *argv)
5274514f5e3Sopenharmony_ci{
5284514f5e3Sopenharmony_ci    ASSERT(argv);
5294514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
5304514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetPrototypeOf);
5314514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
5324514f5e3Sopenharmony_ci
5334514f5e3Sopenharmony_ci    // 1.Let obj be ToObject(O).
5344514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> func = GetCallArg(argv, 0);
5354514f5e3Sopenharmony_ci
5364514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = JSTaggedValue::ToObject(thread, func);
5374514f5e3Sopenharmony_ci
5384514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(obj).
5394514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
5404514f5e3Sopenharmony_ci
5414514f5e3Sopenharmony_ci    // 3.Return obj.[[GetPrototypeOf]]().
5424514f5e3Sopenharmony_ci    return JSTaggedValue::GetPrototype(thread, JSHandle<JSTaggedValue>(obj));
5434514f5e3Sopenharmony_ci}
5444514f5e3Sopenharmony_ci
5454514f5e3Sopenharmony_ci// 19.1.2.10 Object.is ( value1, value2 )
5464514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Is(EcmaRuntimeCallInfo *argv)
5474514f5e3Sopenharmony_ci{
5484514f5e3Sopenharmony_ci    ASSERT(argv);
5494514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Object, Is);
5504514f5e3Sopenharmony_ci
5514514f5e3Sopenharmony_ci    // 1.Return SameValue(value1, value2).
5524514f5e3Sopenharmony_ci    bool result = JSTaggedValue::SameValue(GetCallArg(argv, 0), GetCallArg(argv, 1));
5534514f5e3Sopenharmony_ci    return GetTaggedBoolean(result);
5544514f5e3Sopenharmony_ci}
5554514f5e3Sopenharmony_ci
5564514f5e3Sopenharmony_ci// 19.1.2.11 Object.isExtensible ( O )
5574514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::IsExtensible(EcmaRuntimeCallInfo *argv)
5584514f5e3Sopenharmony_ci{
5594514f5e3Sopenharmony_ci    ASSERT(argv);
5604514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
5614514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, IsExtensible);
5624514f5e3Sopenharmony_ci    // 1.If Type(O) is not Object, return false.
5634514f5e3Sopenharmony_ci    JSTaggedValue obj = GetCallArg(argv, 0).GetTaggedValue();
5644514f5e3Sopenharmony_ci    if (!obj.IsHeapObject()) {
5654514f5e3Sopenharmony_ci        return GetTaggedBoolean(false);
5664514f5e3Sopenharmony_ci    }
5674514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
5684514f5e3Sopenharmony_ci    // 2.Return IsExtensible(O).
5694514f5e3Sopenharmony_ci    return GetTaggedBoolean(obj.IsExtensible(thread));
5704514f5e3Sopenharmony_ci}
5714514f5e3Sopenharmony_ci
5724514f5e3Sopenharmony_ci// 19.1.2.12 Object.isFrozen ( O )
5734514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::IsFrozen(EcmaRuntimeCallInfo *argv)
5744514f5e3Sopenharmony_ci{
5754514f5e3Sopenharmony_ci    ASSERT(argv);
5764514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Object, IsFrozen);
5774514f5e3Sopenharmony_ci    // 1.If Type(O) is not Object, return true.
5784514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
5794514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
5804514f5e3Sopenharmony_ci        return GetTaggedBoolean(true);
5814514f5e3Sopenharmony_ci    }
5824514f5e3Sopenharmony_ci
5834514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
5844514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
5854514f5e3Sopenharmony_ci
5864514f5e3Sopenharmony_ci    // 2.Return TestIntegrityLevel(O, "frozen").
5874514f5e3Sopenharmony_ci    bool status = JSObject::TestIntegrityLevel(thread, JSHandle<JSObject>(obj), IntegrityLevel::FROZEN);
5884514f5e3Sopenharmony_ci    return GetTaggedBoolean(status);
5894514f5e3Sopenharmony_ci}
5904514f5e3Sopenharmony_ci
5914514f5e3Sopenharmony_ci// 19.1.2.13 Object.isSealed ( O )
5924514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::IsSealed(EcmaRuntimeCallInfo *argv)
5934514f5e3Sopenharmony_ci{
5944514f5e3Sopenharmony_ci    ASSERT(argv);
5954514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Object, IsSealed);
5964514f5e3Sopenharmony_ci    // 1.If Type(O) is not Object, return true.
5974514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
5984514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
5994514f5e3Sopenharmony_ci        return GetTaggedBoolean(true);
6004514f5e3Sopenharmony_ci    }
6014514f5e3Sopenharmony_ci
6024514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
6034514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
6044514f5e3Sopenharmony_ci
6054514f5e3Sopenharmony_ci    // 2.Return TestIntegrityLevel(O, "sealed").
6064514f5e3Sopenharmony_ci    bool status = JSObject::TestIntegrityLevel(thread, JSHandle<JSObject>(obj), IntegrityLevel::SEALED);
6074514f5e3Sopenharmony_ci    return GetTaggedBoolean(status);
6084514f5e3Sopenharmony_ci}
6094514f5e3Sopenharmony_ci
6104514f5e3Sopenharmony_ci// 19.1.2.14 Object.keys(O)
6114514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv)
6124514f5e3Sopenharmony_ci{
6134514f5e3Sopenharmony_ci    ASSERT(argv);
6144514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
6154514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Keys);
6164514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
6174514f5e3Sopenharmony_ci
6184514f5e3Sopenharmony_ci    // 1. Let obj be ToObject(O).
6194514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> msg = GetCallArg(argv, 0);
6204514f5e3Sopenharmony_ci
6214514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = JSTaggedValue::ToObject(thread, msg);
6224514f5e3Sopenharmony_ci
6234514f5e3Sopenharmony_ci    // 2. ReturnIfAbrupt(obj).
6244514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
6254514f5e3Sopenharmony_ci
6264514f5e3Sopenharmony_ci    // 3. Let nameList be EnumerableOwnNames(obj).
6274514f5e3Sopenharmony_ci    JSHandle<TaggedArray> nameList = JSObject::EnumerableOwnNames(thread, obj);
6284514f5e3Sopenharmony_ci
6294514f5e3Sopenharmony_ci    // 4. ReturnIfAbrupt(nameList).
6304514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
6314514f5e3Sopenharmony_ci
6324514f5e3Sopenharmony_ci    // 5. Return CreateArrayFromList(nameList).
6334514f5e3Sopenharmony_ci    JSHandle<JSArray> result = JSArray::CreateArrayFromList(thread, nameList);
6344514f5e3Sopenharmony_ci    return result.GetTaggedValue();
6354514f5e3Sopenharmony_ci}
6364514f5e3Sopenharmony_ci
6374514f5e3Sopenharmony_ci// 20.1.2.22 Object.values(O)
6384514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Values(EcmaRuntimeCallInfo *argv)
6394514f5e3Sopenharmony_ci{
6404514f5e3Sopenharmony_ci    ASSERT(argv);
6414514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
6424514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Values);
6434514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
6444514f5e3Sopenharmony_ci
6454514f5e3Sopenharmony_ci    // 1. Let obj be ToObject(O).
6464514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> msg = GetCallArg(argv, 0);
6474514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = JSTaggedValue::ToObject(thread, msg);
6484514f5e3Sopenharmony_ci
6494514f5e3Sopenharmony_ci    // 2. ReturnIfAbrupt(obj).
6504514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
6514514f5e3Sopenharmony_ci
6524514f5e3Sopenharmony_ci    // 3. Let nameList be ? EnumerableOwnPropertyNames(obj, value).
6534514f5e3Sopenharmony_ci    JSHandle<TaggedArray> nameList = JSObject::EnumerableOwnPropertyNames(thread, obj, PropertyKind::VALUE);
6544514f5e3Sopenharmony_ci
6554514f5e3Sopenharmony_ci    // 4. ReturnIfAbrupt(nameList).
6564514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
6574514f5e3Sopenharmony_ci
6584514f5e3Sopenharmony_ci    // 5. Return CreateArrayFromList(nameList).
6594514f5e3Sopenharmony_ci    JSHandle<JSArray> result = JSArray::CreateArrayFromList(thread, nameList);
6604514f5e3Sopenharmony_ci    return result.GetTaggedValue();
6614514f5e3Sopenharmony_ci}
6624514f5e3Sopenharmony_ci
6634514f5e3Sopenharmony_ci// 19.1.2.15 Object.preventExtensions(O)
6644514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::PreventExtensions(EcmaRuntimeCallInfo *argv)
6654514f5e3Sopenharmony_ci{
6664514f5e3Sopenharmony_ci    ASSERT(argv);
6674514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
6684514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, PreventExtensions);
6694514f5e3Sopenharmony_ci    // 1. If Type(O) is not Object, return O.
6704514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
6714514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
6724514f5e3Sopenharmony_ci        return obj.GetTaggedValue();
6734514f5e3Sopenharmony_ci    }
6744514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
6754514f5e3Sopenharmony_ci    // 2. Let status be O.[[PreventExtensions]]().
6764514f5e3Sopenharmony_ci    bool status = JSTaggedValue::PreventExtensions(thread, obj);
6774514f5e3Sopenharmony_ci
6784514f5e3Sopenharmony_ci    // 3. ReturnIfAbrupt(status).
6794514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
6804514f5e3Sopenharmony_ci
6814514f5e3Sopenharmony_ci    // 4. If status is false, throw a TypeError exception.
6824514f5e3Sopenharmony_ci    if (!status) {
6834514f5e3Sopenharmony_ci        // throw a TypeError exception.
6844514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "PreventExtensions: preventExtensions failed",
6854514f5e3Sopenharmony_ci                                    JSTaggedValue::Exception());
6864514f5e3Sopenharmony_ci    }
6874514f5e3Sopenharmony_ci
6884514f5e3Sopenharmony_ci    // 5. Return O.
6894514f5e3Sopenharmony_ci    return obj.GetTaggedValue();
6904514f5e3Sopenharmony_ci}
6914514f5e3Sopenharmony_ci// 19.1.2.16 Object.prototype
6924514f5e3Sopenharmony_ci
6934514f5e3Sopenharmony_ci// 19.1.2.17 Object.seal(O)
6944514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Seal(EcmaRuntimeCallInfo *argv)
6954514f5e3Sopenharmony_ci{
6964514f5e3Sopenharmony_ci    ASSERT(argv);
6974514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
6984514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, Seal);
6994514f5e3Sopenharmony_ci
7004514f5e3Sopenharmony_ci    // 1. If Type(O) is not Object, return O.
7014514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> msg = GetCallArg(argv, 0);
7024514f5e3Sopenharmony_ci    if (!msg->IsECMAObject()) {
7034514f5e3Sopenharmony_ci        return msg.GetTaggedValue();
7044514f5e3Sopenharmony_ci    }
7054514f5e3Sopenharmony_ci
7064514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
7074514f5e3Sopenharmony_ci
7084514f5e3Sopenharmony_ci    // 2. Let status be SetIntegrityLevel(O, "sealed").
7094514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, msg);
7104514f5e3Sopenharmony_ci    bool status = JSObject::SetIntegrityLevel(thread, object, IntegrityLevel::SEALED);
7114514f5e3Sopenharmony_ci
7124514f5e3Sopenharmony_ci    // 3. ReturnIfAbrupt(status).
7134514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
7144514f5e3Sopenharmony_ci
7154514f5e3Sopenharmony_ci    // 4. If status is false, throw a TypeError exception.
7164514f5e3Sopenharmony_ci    if (!status) {
7174514f5e3Sopenharmony_ci        // throw a TypeError exception.
7184514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "Seal: seal failed", JSTaggedValue::Exception());
7194514f5e3Sopenharmony_ci    }
7204514f5e3Sopenharmony_ci
7214514f5e3Sopenharmony_ci    // 5. Return O.
7224514f5e3Sopenharmony_ci    return object.GetTaggedValue();
7234514f5e3Sopenharmony_ci}
7244514f5e3Sopenharmony_ci
7254514f5e3Sopenharmony_ci// 19.1.2.18 Object.setPrototypeOf(O, proto)
7264514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::SetPrototypeOf(EcmaRuntimeCallInfo *argv)
7274514f5e3Sopenharmony_ci{
7284514f5e3Sopenharmony_ci    ASSERT(argv);
7294514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
7304514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, SetPrototypeOf);
7314514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
7324514f5e3Sopenharmony_ci    // 1. Let O be RequireObjectCoercible(O).
7334514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> object = JSTaggedValue::RequireObjectCoercible(thread, GetCallArg(argv, 0));
7344514f5e3Sopenharmony_ci
7354514f5e3Sopenharmony_ci    // 2. ReturnIfAbrupt(O).
7364514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
7374514f5e3Sopenharmony_ci
7384514f5e3Sopenharmony_ci    // 3. If Type(proto) is neither Object nor Null, throw a TypeError exception.
7394514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> proto = GetCallArg(argv, 1);
7404514f5e3Sopenharmony_ci    if (!proto->IsNull() && !proto->IsECMAObject()) {
7414514f5e3Sopenharmony_ci        // throw a TypeError exception.
7424514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "SetPrototypeOf: proto is neither Object nor Null",
7434514f5e3Sopenharmony_ci                                    JSTaggedValue::Exception());
7444514f5e3Sopenharmony_ci    }
7454514f5e3Sopenharmony_ci
7464514f5e3Sopenharmony_ci    // 4. If Type(O) is not Object, return O.
7474514f5e3Sopenharmony_ci    if (!object->IsECMAObject()) {
7484514f5e3Sopenharmony_ci        return object.GetTaggedValue();
7494514f5e3Sopenharmony_ci    }
7504514f5e3Sopenharmony_ci
7514514f5e3Sopenharmony_ci    // 5. Let status be O.[[SetPrototypeOf]](proto).
7524514f5e3Sopenharmony_ci    bool status = JSTaggedValue::SetPrototype(thread, object, proto);
7534514f5e3Sopenharmony_ci
7544514f5e3Sopenharmony_ci    // 6. ReturnIfAbrupt(status).
7554514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
7564514f5e3Sopenharmony_ci
7574514f5e3Sopenharmony_ci    // 7. If status is false, throw a TypeError exception.
7584514f5e3Sopenharmony_ci    if (!status) {
7594514f5e3Sopenharmony_ci        // throw a TypeError exception.
7604514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "SetPrototypeOf: prototype set failed", JSTaggedValue::Exception());
7614514f5e3Sopenharmony_ci    }
7624514f5e3Sopenharmony_ci
7634514f5e3Sopenharmony_ci    // 8. Return O.
7644514f5e3Sopenharmony_ci    return object.GetTaggedValue();
7654514f5e3Sopenharmony_ci}
7664514f5e3Sopenharmony_ci
7674514f5e3Sopenharmony_ci// 19.1.3.1 Object.prototype.constructor
7684514f5e3Sopenharmony_ci
7694514f5e3Sopenharmony_ci// 19.1.3.2 Object.prototype.hasOwnProperty(V)
7704514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::HasOwnProperty(EcmaRuntimeCallInfo *argv)
7714514f5e3Sopenharmony_ci{
7724514f5e3Sopenharmony_ci    ASSERT(argv);
7734514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
7744514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, HasOwnProperty);
7754514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
7764514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> thisValue = GetThis(argv);
7774514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> prop = GetCallArg(argv, 0);
7784514f5e3Sopenharmony_ci    return HasOwnPropertyInternal(thread, thisValue, prop);
7794514f5e3Sopenharmony_ci}
7804514f5e3Sopenharmony_ci
7814514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::HasOwnPropertyInternal(JSThread *thread, JSHandle<JSTaggedValue> thisValue,
7824514f5e3Sopenharmony_ci                                                     JSHandle<JSTaggedValue> prop)
7834514f5e3Sopenharmony_ci{
7844514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
7854514f5e3Sopenharmony_ci    std::pair<JSTaggedValue, bool> result = ObjectFastOperator::HasOwnProperty(thread, thisValue.GetTaggedValue(),
7864514f5e3Sopenharmony_ci        prop.GetTaggedValue());
7874514f5e3Sopenharmony_ci    if (!result.first.IsHole()) {
7884514f5e3Sopenharmony_ci        return GetTaggedBoolean(true);
7894514f5e3Sopenharmony_ci    } else if (result.second) {
7904514f5e3Sopenharmony_ci        return GetTaggedBoolean(false);
7914514f5e3Sopenharmony_ci    }
7924514f5e3Sopenharmony_ci
7934514f5e3Sopenharmony_ci    // 1. Let P be ToPropertyKey(V).
7944514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> property = JSTaggedValue::ToPropertyKey(thread, prop);
7954514f5e3Sopenharmony_ci
7964514f5e3Sopenharmony_ci    // 2. ReturnIfAbrupt(P).
7974514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
7984514f5e3Sopenharmony_ci
7994514f5e3Sopenharmony_ci    // 3. Let O be ToObject(this value).
8004514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, thisValue);
8014514f5e3Sopenharmony_ci
8024514f5e3Sopenharmony_ci    // 4. ReturnIfAbrupt(O).
8034514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8044514f5e3Sopenharmony_ci
8054514f5e3Sopenharmony_ci    // 5. Return HasOwnProperty(O, P).
8064514f5e3Sopenharmony_ci    bool res = JSTaggedValue::HasOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(object), property);
8074514f5e3Sopenharmony_ci    return GetTaggedBoolean(res);
8084514f5e3Sopenharmony_ci}
8094514f5e3Sopenharmony_ci
8104514f5e3Sopenharmony_ci// 19.1.3.3 Object.prototype.isPrototypeOf(V)
8114514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::IsPrototypeOf(EcmaRuntimeCallInfo *argv)
8124514f5e3Sopenharmony_ci{
8134514f5e3Sopenharmony_ci    ASSERT(argv);
8144514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
8154514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, IsPrototypeOf);
8164514f5e3Sopenharmony_ci    // 1. If Type(V) is not Object, return false.
8174514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> msg = GetCallArg(argv, 0);
8184514f5e3Sopenharmony_ci    if (!msg->IsECMAObject()) {
8194514f5e3Sopenharmony_ci        return GetTaggedBoolean(false);
8204514f5e3Sopenharmony_ci    }
8214514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
8224514f5e3Sopenharmony_ci    // 2. Let O be ToObject(this value).
8234514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, GetThis(argv));
8244514f5e3Sopenharmony_ci    // 3. ReturnIfAbrupt(O).
8254514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8264514f5e3Sopenharmony_ci
8274514f5e3Sopenharmony_ci    // 4. Repeat
8284514f5e3Sopenharmony_ci    //    a. Let V be V.[[GetPrototypeOf]]().
8294514f5e3Sopenharmony_ci    //    b. If V is null, return false
8304514f5e3Sopenharmony_ci    //    c. If SameValue(O, V) is true, return true.
8314514f5e3Sopenharmony_ci    JSMutableHandle<JSTaggedValue> msgValueHandle(thread, msg.GetTaggedValue());
8324514f5e3Sopenharmony_ci    while (!msgValueHandle->IsNull()) {
8334514f5e3Sopenharmony_ci        msgValueHandle.Update(JSTaggedValue::GetPrototype(thread, msgValueHandle));
8344514f5e3Sopenharmony_ci        RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8354514f5e3Sopenharmony_ci
8364514f5e3Sopenharmony_ci        if (JSTaggedValue::SameValue(object.GetTaggedValue(), msgValueHandle.GetTaggedValue())) {
8374514f5e3Sopenharmony_ci            return GetTaggedBoolean(true);
8384514f5e3Sopenharmony_ci        }
8394514f5e3Sopenharmony_ci    }
8404514f5e3Sopenharmony_ci    return GetTaggedBoolean(false);
8414514f5e3Sopenharmony_ci}
8424514f5e3Sopenharmony_ci
8434514f5e3Sopenharmony_ci// 19.1.3.4 Object.prototype.propertyIsEnumerable(V)
8444514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::PropertyIsEnumerable(EcmaRuntimeCallInfo *argv)
8454514f5e3Sopenharmony_ci{
8464514f5e3Sopenharmony_ci    ASSERT(argv);
8474514f5e3Sopenharmony_ci    // 1. Let P be ToPropertyKey(V).
8484514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
8494514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, PropertyIsEnumerable);
8504514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
8514514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> msg = GetCallArg(argv, 0);
8524514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> property = JSTaggedValue::ToPropertyKey(thread, msg);
8534514f5e3Sopenharmony_ci
8544514f5e3Sopenharmony_ci    // 2. ReturnIfAbrupt(P).
8554514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8564514f5e3Sopenharmony_ci
8574514f5e3Sopenharmony_ci    // 3. Let O be ToObject(this value).
8584514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, GetThis(argv));
8594514f5e3Sopenharmony_ci    // 4. ReturnIfAbrupt(O).
8604514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8614514f5e3Sopenharmony_ci
8624514f5e3Sopenharmony_ci    // 5. Let desc be O.[[GetOwnProperty]](P).
8634514f5e3Sopenharmony_ci    PropertyDescriptor desc(thread);
8644514f5e3Sopenharmony_ci    JSTaggedValue::GetOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(object), property, desc);
8654514f5e3Sopenharmony_ci
8664514f5e3Sopenharmony_ci    // 6. ReturnIfAbrupt(desc).
8674514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8684514f5e3Sopenharmony_ci
8694514f5e3Sopenharmony_ci    // 7. If desc is undefined, return false.
8704514f5e3Sopenharmony_ci    if (desc.IsEmpty()) {
8714514f5e3Sopenharmony_ci        return GetTaggedBoolean(false);
8724514f5e3Sopenharmony_ci    }
8734514f5e3Sopenharmony_ci
8744514f5e3Sopenharmony_ci    // 8. Return the value of desc.[[Enumerable]].
8754514f5e3Sopenharmony_ci    return GetTaggedBoolean(desc.IsEnumerable());
8764514f5e3Sopenharmony_ci}
8774514f5e3Sopenharmony_ci
8784514f5e3Sopenharmony_ci// 19.1.3.5 Object.prototype.toLocaleString([reserved1[, reserved2]])
8794514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ToLocaleString(EcmaRuntimeCallInfo *argv)
8804514f5e3Sopenharmony_ci{
8814514f5e3Sopenharmony_ci    ASSERT(argv);
8824514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
8834514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, ToLocaleString);
8844514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
8854514f5e3Sopenharmony_ci    // 1. Let O be the this value.
8864514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> object = GetThis(argv);
8874514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8884514f5e3Sopenharmony_ci
8894514f5e3Sopenharmony_ci    // 2. Return Invoke(O, "toString").
8904514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> calleeKey = thread->GlobalConstants()->GetHandledToStringString();
8914514f5e3Sopenharmony_ci    const uint32_t argsLength = argv->GetArgsNumber();
8924514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
8934514f5e3Sopenharmony_ci    EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, object, undefined, argsLength);
8944514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
8954514f5e3Sopenharmony_ci    info->SetCallArg(argsLength, 0, argv, 0);
8964514f5e3Sopenharmony_ci    return JSFunction::Invoke(info, calleeKey);
8974514f5e3Sopenharmony_ci}
8984514f5e3Sopenharmony_ci
8994514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::GetBuiltinObjectToString(JSThread *thread, const JSHandle<JSObject> &object)
9004514f5e3Sopenharmony_ci{
9014514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, GetBuiltinObjectToString);
9024514f5e3Sopenharmony_ci    // 4. Let isArray be IsArray(O).
9034514f5e3Sopenharmony_ci    bool isArray = object.GetTaggedValue().IsArray(thread);
9044514f5e3Sopenharmony_ci    // 5. ReturnIfAbrupt(isArray).
9054514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
9064514f5e3Sopenharmony_ci
9074514f5e3Sopenharmony_ci    if (isArray) {
9084514f5e3Sopenharmony_ci        // 6. If isArray is true, return "[object Array]".
9094514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetArrayToString();
9104514f5e3Sopenharmony_ci    } else if (object->IsJSPrimitiveRef()) {
9114514f5e3Sopenharmony_ci        // 7. Else, if O is an exotic String object, return "[object String]".
9124514f5e3Sopenharmony_ci        JSPrimitiveRef *primitiveRef = JSPrimitiveRef::Cast(*object);
9134514f5e3Sopenharmony_ci        if (primitiveRef->IsString()) {
9144514f5e3Sopenharmony_ci            return thread->GlobalConstants()->GetStringToString();
9154514f5e3Sopenharmony_ci        } else if (primitiveRef->IsBoolean()) {
9164514f5e3Sopenharmony_ci            // 11. Else, if O has a [[BooleanData]] internal slot, return "[object Boolean]".
9174514f5e3Sopenharmony_ci            return thread->GlobalConstants()->GetBooleanToString();
9184514f5e3Sopenharmony_ci        } else if (primitiveRef->IsNumber()) {
9194514f5e3Sopenharmony_ci            // 12. Else, if O has a [[NumberData]] internal slot, return "[object Number]".
9204514f5e3Sopenharmony_ci            return thread->GlobalConstants()->GetNumberToString();
9214514f5e3Sopenharmony_ci        }
9224514f5e3Sopenharmony_ci    } else if (object->IsArguments()) {
9234514f5e3Sopenharmony_ci        // if O has a [[ArgumentsData]] internal slot, return "[object Arguments]".
9244514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetArgumentsToString();
9254514f5e3Sopenharmony_ci    } else if (object->IsCallable()) {
9264514f5e3Sopenharmony_ci        // if O has a [[CallableData]] internal slot, return "[object Function]".
9274514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetFunctionToString();
9284514f5e3Sopenharmony_ci    } else if (object->IsJSError()) {
9294514f5e3Sopenharmony_ci        // if O has a [[ErrorData]] internal slot, return "[object Error]".
9304514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetErrorToString();
9314514f5e3Sopenharmony_ci    } else if (object->IsDate()) {
9324514f5e3Sopenharmony_ci        // if O has a [[DateData]] internal slot, return "[object Date]".
9334514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetDateToString();
9344514f5e3Sopenharmony_ci    } else if (object->IsJSRegExp()) {
9354514f5e3Sopenharmony_ci        // if O has a [[RegExpData]] internal slot, return "[object JSRegExp]".
9364514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetRegExpToString();
9374514f5e3Sopenharmony_ci    }
9384514f5e3Sopenharmony_ci    // 15. Else, return "[Object Object]".
9394514f5e3Sopenharmony_ci    return thread->GlobalConstants()->GetObjectToString();
9404514f5e3Sopenharmony_ci}
9414514f5e3Sopenharmony_ci
9424514f5e3Sopenharmony_ci// 19.1.3.6 Object.prototype.toString()
9434514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ToString(EcmaRuntimeCallInfo *argv)
9444514f5e3Sopenharmony_ci{
9454514f5e3Sopenharmony_ci    ASSERT(argv);
9464514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
9474514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, ToString);
9484514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
9494514f5e3Sopenharmony_ci    // 1. If the this value is undefined, return "[object Undefined]".
9504514f5e3Sopenharmony_ci
9514514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> msg = GetThis(argv);
9524514f5e3Sopenharmony_ci    if (msg->IsUndefined()) {
9534514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetUndefinedToString();
9544514f5e3Sopenharmony_ci    }
9554514f5e3Sopenharmony_ci    // 2. If the this value is null, return "[object Null]".
9564514f5e3Sopenharmony_ci    if (msg->IsNull()) {
9574514f5e3Sopenharmony_ci        return thread->GlobalConstants()->GetNullToString();
9584514f5e3Sopenharmony_ci    }
9594514f5e3Sopenharmony_ci
9604514f5e3Sopenharmony_ci    // 3. Let O be ToObject(this value).
9614514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, GetThis(argv));
9624514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
9634514f5e3Sopenharmony_ci
9644514f5e3Sopenharmony_ci    // 16. Let tag be Get (O, @@toStringTag).
9654514f5e3Sopenharmony_ci    auto ecmaVm = thread->GetEcmaVM();
9664514f5e3Sopenharmony_ci    JSHandle<GlobalEnv> env = ecmaVm->GetGlobalEnv();
9674514f5e3Sopenharmony_ci    auto factory = ecmaVm->GetFactory();
9684514f5e3Sopenharmony_ci
9694514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> tag = JSTaggedValue::GetProperty(thread, msg, env->GetToStringTagSymbol()).GetValue();
9704514f5e3Sopenharmony_ci
9714514f5e3Sopenharmony_ci    // 17. ReturnIfAbrupt(tag).
9724514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
9734514f5e3Sopenharmony_ci
9744514f5e3Sopenharmony_ci    // 18. If Type(tag) is not String, return builtin object to string.
9754514f5e3Sopenharmony_ci    if (!tag->IsString()) {
9764514f5e3Sopenharmony_ci        return GetBuiltinObjectToString(thread, object);
9774514f5e3Sopenharmony_ci    }
9784514f5e3Sopenharmony_ci
9794514f5e3Sopenharmony_ci    // 19. Return the String that is the result of concatenating "[object ", tag, and "]".
9804514f5e3Sopenharmony_ci    JSHandle<EcmaString> leftString(factory->NewFromASCII("[object "));
9814514f5e3Sopenharmony_ci    JSHandle<EcmaString> rightString(factory->NewFromASCII("]"));
9824514f5e3Sopenharmony_ci
9834514f5e3Sopenharmony_ci    JSHandle<EcmaString> newLeftStringHandle =
9844514f5e3Sopenharmony_ci        factory->ConcatFromString(leftString, JSTaggedValue::ToString(thread, tag));
9854514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
9864514f5e3Sopenharmony_ci    auto result = factory->ConcatFromString(newLeftStringHandle, rightString);
9874514f5e3Sopenharmony_ci    return result.GetTaggedValue();
9884514f5e3Sopenharmony_ci}
9894514f5e3Sopenharmony_ci
9904514f5e3Sopenharmony_ci// 19.1.3.7 Object.prototype.valueOf()
9914514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ValueOf(EcmaRuntimeCallInfo *argv)
9924514f5e3Sopenharmony_ci{
9934514f5e3Sopenharmony_ci    ASSERT(argv);
9944514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
9954514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, ValueOf);
9964514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
9974514f5e3Sopenharmony_ci
9984514f5e3Sopenharmony_ci    // 1. Return ToObject(this value).
9994514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, GetThis(argv));
10004514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
10014514f5e3Sopenharmony_ci    return object.GetTaggedValue();
10024514f5e3Sopenharmony_ci}
10034514f5e3Sopenharmony_ci// B.2.2.1 Object.prototype.__proto__
10044514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ProtoGetter(EcmaRuntimeCallInfo *argv)
10054514f5e3Sopenharmony_ci{
10064514f5e3Sopenharmony_ci    ASSERT(argv);
10074514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
10084514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, ProtoGetter);
10094514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
10104514f5e3Sopenharmony_ci
10114514f5e3Sopenharmony_ci    // 1.Let obj be ToObject(this value).
10124514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = JSTaggedValue::ToObject(thread, GetThis(argv));
10134514f5e3Sopenharmony_ci
10144514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(obj).
10154514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
10164514f5e3Sopenharmony_ci
10174514f5e3Sopenharmony_ci    // 3.Return obj.[[GetPrototypeOf]]().
10184514f5e3Sopenharmony_ci    return JSTaggedValue::GetPrototype(thread, JSHandle<JSTaggedValue>(obj));
10194514f5e3Sopenharmony_ci}
10204514f5e3Sopenharmony_ci
10214514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::ProtoSetter(EcmaRuntimeCallInfo *argv)
10224514f5e3Sopenharmony_ci{
10234514f5e3Sopenharmony_ci    ASSERT(argv);
10244514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
10254514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, ProtoSetter);
10264514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
10274514f5e3Sopenharmony_ci    // 1. Let O be RequireObjectCoercible(this value).
10284514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = JSTaggedValue::RequireObjectCoercible(thread, GetThis(argv));
10294514f5e3Sopenharmony_ci
10304514f5e3Sopenharmony_ci    // 2. ReturnIfAbrupt(O).
10314514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
10324514f5e3Sopenharmony_ci
10334514f5e3Sopenharmony_ci    // 3. If Type(proto) is neither Object nor Null, return undefined..
10344514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> proto = GetCallArg(argv, 0);
10354514f5e3Sopenharmony_ci    if (!proto->IsNull() && !proto->IsECMAObject()) {
10364514f5e3Sopenharmony_ci        return JSTaggedValue::Undefined();
10374514f5e3Sopenharmony_ci    }
10384514f5e3Sopenharmony_ci
10394514f5e3Sopenharmony_ci    // 4. If Type(O) is not Object, return undefined.
10404514f5e3Sopenharmony_ci    if (!obj->IsECMAObject()) {
10414514f5e3Sopenharmony_ci        return JSTaggedValue::Undefined();
10424514f5e3Sopenharmony_ci    }
10434514f5e3Sopenharmony_ci
10444514f5e3Sopenharmony_ci    // 5. Let status be O.[[SetPrototypeOf]](proto).
10454514f5e3Sopenharmony_ci    bool status = JSTaggedValue::SetPrototype(thread, obj, proto, true);
10464514f5e3Sopenharmony_ci
10474514f5e3Sopenharmony_ci    // 6. ReturnIfAbrupt(status).
10484514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
10494514f5e3Sopenharmony_ci
10504514f5e3Sopenharmony_ci    // 7. If status is false, throw a TypeError exception.
10514514f5e3Sopenharmony_ci    if (!status) {
10524514f5e3Sopenharmony_ci        // throw a TypeError exception.
10534514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "ProtoSetter: proto set failed", JSTaggedValue::Exception());
10544514f5e3Sopenharmony_ci    }
10554514f5e3Sopenharmony_ci
10564514f5e3Sopenharmony_ci    // 8. Return O.
10574514f5e3Sopenharmony_ci    return JSTaggedValue::Undefined();
10584514f5e3Sopenharmony_ci}
10594514f5e3Sopenharmony_ci
10604514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::CreateRealm(EcmaRuntimeCallInfo *argv)
10614514f5e3Sopenharmony_ci{
10624514f5e3Sopenharmony_ci    ASSERT(argv);
10634514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
10644514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, CreateRealm);
10654514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
10664514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
10674514f5e3Sopenharmony_ci    JSHandle<JSRealm> realm = factory->NewJSRealm();
10684514f5e3Sopenharmony_ci    return realm.GetTaggedValue();
10694514f5e3Sopenharmony_ci}
10704514f5e3Sopenharmony_ci
10714514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::Entries(EcmaRuntimeCallInfo *argv)
10724514f5e3Sopenharmony_ci{
10734514f5e3Sopenharmony_ci    ASSERT(argv);
10744514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
10754514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, ToString);
10764514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
10774514f5e3Sopenharmony_ci
10784514f5e3Sopenharmony_ci    // 1. Let obj be ? ToObject(O).
10794514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
10804514f5e3Sopenharmony_ci    if (obj->IsJSUint8Array() || obj->IsJSUint16Array()) {
10814514f5e3Sopenharmony_ci        THROW_RANGE_ERROR_AND_RETURN(thread, "Object entries is not supported IsJSUint8Array or IsJSUint16Array",
10824514f5e3Sopenharmony_ci                                     JSTaggedValue::Exception());
10834514f5e3Sopenharmony_ci    }
10844514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, obj);
10854514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
10864514f5e3Sopenharmony_ci    // 2. Let nameList be ? EnumerableOwnPropertyNames(obj, key+value).
10874514f5e3Sopenharmony_ci    JSHandle<TaggedArray> nameList = JSObject::EnumerableOwnPropertyNames(thread, object, PropertyKind::KEY_VALUE);
10884514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
10894514f5e3Sopenharmony_ci    // 3. Return CreateArrayFromList(nameList).
10904514f5e3Sopenharmony_ci    return JSArray::CreateArrayFromList(thread, nameList).GetTaggedValue();
10914514f5e3Sopenharmony_ci}
10924514f5e3Sopenharmony_ci
10934514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::FromEntries(EcmaRuntimeCallInfo *argv)
10944514f5e3Sopenharmony_ci{
10954514f5e3Sopenharmony_ci    ASSERT(argv);
10964514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
10974514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, FromEntries);
10984514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
10994514f5e3Sopenharmony_ci
11004514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> iterable = GetCallArg(argv, 0);
11014514f5e3Sopenharmony_ci    // 1. Perform ? RequireObjectCoercible(iterable).
11024514f5e3Sopenharmony_ci    if (iterable->IsUndefined() || iterable->IsNull()) {
11034514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "iterable is undefined or null", JSTaggedValue::Exception());
11044514f5e3Sopenharmony_ci    }
11054514f5e3Sopenharmony_ci
11064514f5e3Sopenharmony_ci    // 2. Let obj be ! OrdinaryObjectCreate(%Object.prototype%).
11074514f5e3Sopenharmony_ci    // 3. Assert: obj is an extensible ordinary object with no own properties.
11084514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
11094514f5e3Sopenharmony_ci    JSHandle<GlobalEnv> env = thread->GetEcmaVM()->GetGlobalEnv();
11104514f5e3Sopenharmony_ci    JSHandle<JSFunction> constructor(env->GetObjectFunction());
11114514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(constructor);
11124514f5e3Sopenharmony_ci
11134514f5e3Sopenharmony_ci    // 4. Let stepsDefine be the algorithm steps defined in CreateDataPropertyOnObject Functions.
11144514f5e3Sopenharmony_ci    // 5. Let lengthDefine be the number of non-optional parameters of the function definition in
11154514f5e3Sopenharmony_ci    //    CreateDataPropertyOnObject Functions.
11164514f5e3Sopenharmony_ci    // 6. Let adder be ! CreateBuiltinFunction(stepsDefine, lengthDefine, "", « »).
11174514f5e3Sopenharmony_ci    JSHandle<Method> method(thread,
11184514f5e3Sopenharmony_ci        thread->GetEcmaVM()->GetMethodByIndex(MethodIndex::BUILTINS_OBJECT_CREATE_DATA_PROPERTY_ON_OBJECT_FUNCTIONS));
11194514f5e3Sopenharmony_ci    JSHandle<JSFunction> addrFunc = factory->NewJSFunction(env, method);
11204514f5e3Sopenharmony_ci
11214514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> adder(thread, addrFunc.GetTaggedValue());
11224514f5e3Sopenharmony_ci
11234514f5e3Sopenharmony_ci    // 7. Return ? AddEntriesFromIterable(obj, iterable, adder).
11244514f5e3Sopenharmony_ci    return BuiltinsMap::AddEntriesFromIterable(thread, obj, iterable, adder, factory);
11254514f5e3Sopenharmony_ci}
11264514f5e3Sopenharmony_ci
11274514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::CreateDataPropertyOnObjectFunctions(EcmaRuntimeCallInfo *argv)
11284514f5e3Sopenharmony_ci{
11294514f5e3Sopenharmony_ci    ASSERT(argv);
11304514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
11314514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, CreateDataPropertyOnObjectFunctions);
11324514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
11334514f5e3Sopenharmony_ci
11344514f5e3Sopenharmony_ci    // 1. Let O be the this value.
11354514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> thisHandle = GetThis(argv);
11364514f5e3Sopenharmony_ci    JSHandle<JSObject> thisObjHandle = JSHandle<JSObject>::Cast(thisHandle);
11374514f5e3Sopenharmony_ci
11384514f5e3Sopenharmony_ci    // 2. Assert: Type(O) is Object.
11394514f5e3Sopenharmony_ci    // 3. Assert: O is an extensible ordinary object.
11404514f5e3Sopenharmony_ci    ASSERT(thisHandle->IsHeapObject());
11414514f5e3Sopenharmony_ci
11424514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> key = GetCallArg(argv, 0);
11434514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> value = GetCallArg(argv, 1);
11444514f5e3Sopenharmony_ci
11454514f5e3Sopenharmony_ci    // 4. Let propertyKey be ? ToPropertyKey(key).
11464514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> propertyKey = JSTaggedValue::ToPropertyKey(thread, key);
11474514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
11484514f5e3Sopenharmony_ci
11494514f5e3Sopenharmony_ci    // 5. Perform ! CreateDataPropertyOrThrow(O, propertyKey, value).
11504514f5e3Sopenharmony_ci    JSObject::CreateDataPropertyOrThrow(thread, thisObjHandle, propertyKey, value);
11514514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
11524514f5e3Sopenharmony_ci
11534514f5e3Sopenharmony_ci    // 6. Return undefined.
11544514f5e3Sopenharmony_ci    return JSTaggedValue::Undefined();
11554514f5e3Sopenharmony_ci}
11564514f5e3Sopenharmony_ci
11574514f5e3Sopenharmony_ciJSTaggedValue BuiltinsObject::HasOwn(EcmaRuntimeCallInfo *argv)
11584514f5e3Sopenharmony_ci{
11594514f5e3Sopenharmony_ci    ASSERT(argv);
11604514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
11614514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Object, HasOwn);
11624514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
11634514f5e3Sopenharmony_ci
11644514f5e3Sopenharmony_ci    // 1. Let obj be ? ToObject(O).
11654514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> obj = GetCallArg(argv, 0);
11664514f5e3Sopenharmony_ci    JSHandle<JSObject> object = JSTaggedValue::ToObject(thread, obj);
11674514f5e3Sopenharmony_ci
11684514f5e3Sopenharmony_ci    // 2.ReturnIfAbrupt(obj).
11694514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
11704514f5e3Sopenharmony_ci
11714514f5e3Sopenharmony_ci    // 3.Let key be ToPropertyKey(P).
11724514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> prop = GetCallArg(argv, 1);
11734514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> key = JSTaggedValue::ToPropertyKey(thread, prop);
11744514f5e3Sopenharmony_ci
11754514f5e3Sopenharmony_ci    // 4. ReturnIfAbrupt(4).
11764514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
11774514f5e3Sopenharmony_ci
11784514f5e3Sopenharmony_ci    // 5. Return HasOwnProperty(O, P).
11794514f5e3Sopenharmony_ci    bool res = JSTaggedValue::HasOwnProperty(thread, JSHandle<JSTaggedValue>::Cast(object), key);
11804514f5e3Sopenharmony_ci    return GetTaggedBoolean(res);
11814514f5e3Sopenharmony_ci}
11824514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
1183