14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023 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/elements.h"
174514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value-inl.h"
184514f5e3Sopenharmony_ci#include "ecmascript/tagged_array-inl.h"
194514f5e3Sopenharmony_ci
204514f5e3Sopenharmony_cinamespace panda::ecmascript {
214514f5e3Sopenharmony_ciCMap<ElementsKind, std::pair<ConstantIndex, ConstantIndex>> Elements::InitializeHClassMap()
224514f5e3Sopenharmony_ci{
234514f5e3Sopenharmony_ci    CMap<ElementsKind, std::pair<ConstantIndex, ConstantIndex>> result;
244514f5e3Sopenharmony_ci#define INIT_ARRAY_HCLASS_INDEX_MAPS(name)                                                                       \
254514f5e3Sopenharmony_ci    result.emplace(ElementsKind::name, std::make_pair(ConstantIndex::ELEMENT_##name##_HCLASS_INDEX,              \
264514f5e3Sopenharmony_ci                                                      ConstantIndex::ELEMENT_##name##_PROTO_HCLASS_INDEX));
274514f5e3Sopenharmony_ci    ELEMENTS_KIND_INIT_HCLASS_LIST(INIT_ARRAY_HCLASS_INDEX_MAPS)
284514f5e3Sopenharmony_ci#undef INIT_ARRAY_HCLASS_INDEX_MAPS
294514f5e3Sopenharmony_ci    return result;
304514f5e3Sopenharmony_ci}
314514f5e3Sopenharmony_ci
324514f5e3Sopenharmony_cistd::string Elements::GetString(ElementsKind kind)
334514f5e3Sopenharmony_ci{
344514f5e3Sopenharmony_ci    return std::to_string(static_cast<uint32_t>(kind));
354514f5e3Sopenharmony_ci}
364514f5e3Sopenharmony_ci
374514f5e3Sopenharmony_cibool Elements::IsInt(ElementsKind kind)
384514f5e3Sopenharmony_ci{
394514f5e3Sopenharmony_ci    return kind == ElementsKind::INT;
404514f5e3Sopenharmony_ci}
414514f5e3Sopenharmony_ci
424514f5e3Sopenharmony_cibool Elements::IsNumber(ElementsKind kind)
434514f5e3Sopenharmony_ci{
444514f5e3Sopenharmony_ci    return kind == ElementsKind::NUMBER;
454514f5e3Sopenharmony_ci}
464514f5e3Sopenharmony_ci
474514f5e3Sopenharmony_cibool Elements::IsTagged(ElementsKind kind)
484514f5e3Sopenharmony_ci{
494514f5e3Sopenharmony_ci    return kind == ElementsKind::TAGGED;
504514f5e3Sopenharmony_ci}
514514f5e3Sopenharmony_ci
524514f5e3Sopenharmony_cibool Elements::IsObject(ElementsKind kind)
534514f5e3Sopenharmony_ci{
544514f5e3Sopenharmony_ci    return kind == ElementsKind::OBJECT;
554514f5e3Sopenharmony_ci}
564514f5e3Sopenharmony_ci
574514f5e3Sopenharmony_cibool Elements::IsHole(ElementsKind kind)
584514f5e3Sopenharmony_ci{
594514f5e3Sopenharmony_ci    static constexpr uint8_t EVEN_NUMBER = 2;
604514f5e3Sopenharmony_ci    return static_cast<uint8_t>(kind) % EVEN_NUMBER == 1;
614514f5e3Sopenharmony_ci}
624514f5e3Sopenharmony_ci
634514f5e3Sopenharmony_ciConstantIndex Elements::GetGlobalContantIndexByKind(ElementsKind kind)
644514f5e3Sopenharmony_ci{
654514f5e3Sopenharmony_ci    switch (kind) {
664514f5e3Sopenharmony_ci        case ElementsKind::NONE:
674514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_NONE_HCLASS_INDEX;
684514f5e3Sopenharmony_ci        case ElementsKind::INT:
694514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_INT_HCLASS_INDEX;
704514f5e3Sopenharmony_ci        case ElementsKind::NUMBER:
714514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_NUMBER_HCLASS_INDEX;
724514f5e3Sopenharmony_ci        case ElementsKind::STRING:
734514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_STRING_HCLASS_INDEX;
744514f5e3Sopenharmony_ci        case ElementsKind::OBJECT:
754514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_OBJECT_HCLASS_INDEX;
764514f5e3Sopenharmony_ci        case ElementsKind::TAGGED:
774514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_TAGGED_HCLASS_INDEX;
784514f5e3Sopenharmony_ci        case ElementsKind::HOLE:
794514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_HOLE_HCLASS_INDEX;
804514f5e3Sopenharmony_ci        case ElementsKind::HOLE_INT:
814514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_HOLE_INT_HCLASS_INDEX;
824514f5e3Sopenharmony_ci        case ElementsKind::HOLE_NUMBER:
834514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_HOLE_NUMBER_HCLASS_INDEX;
844514f5e3Sopenharmony_ci        case ElementsKind::HOLE_STRING:
854514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_HOLE_STRING_HCLASS_INDEX;
864514f5e3Sopenharmony_ci        case ElementsKind::HOLE_OBJECT:
874514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_HOLE_OBJECT_HCLASS_INDEX;
884514f5e3Sopenharmony_ci        case ElementsKind::HOLE_TAGGED:
894514f5e3Sopenharmony_ci            return ConstantIndex::ELEMENT_HOLE_TAGGED_HCLASS_INDEX;
904514f5e3Sopenharmony_ci        default:
914514f5e3Sopenharmony_ci            LOG_ECMA(FATAL) << "Unknown elementsKind when getting constantIndx: " << static_cast<int32_t>(kind);
924514f5e3Sopenharmony_ci    }
934514f5e3Sopenharmony_ci}
944514f5e3Sopenharmony_ci
954514f5e3Sopenharmony_ciElementsKind Elements::MergeElementsKind(ElementsKind curKind, ElementsKind newKind)
964514f5e3Sopenharmony_ci{
974514f5e3Sopenharmony_ci    auto result = ElementsKind(static_cast<uint8_t>(curKind) | static_cast<uint8_t>(newKind));
984514f5e3Sopenharmony_ci    result = FixElementsKind(result);
994514f5e3Sopenharmony_ci    return result;
1004514f5e3Sopenharmony_ci}
1014514f5e3Sopenharmony_ci
1024514f5e3Sopenharmony_ciElementsKind Elements::FixElementsKind(ElementsKind oldKind)
1034514f5e3Sopenharmony_ci{
1044514f5e3Sopenharmony_ci    auto result = oldKind;
1054514f5e3Sopenharmony_ci    switch (result) {
1064514f5e3Sopenharmony_ci        case ElementsKind::NONE:
1074514f5e3Sopenharmony_ci        case ElementsKind::INT:
1084514f5e3Sopenharmony_ci        case ElementsKind::NUMBER:
1094514f5e3Sopenharmony_ci        case ElementsKind::STRING:
1104514f5e3Sopenharmony_ci        case ElementsKind::OBJECT:
1114514f5e3Sopenharmony_ci        case ElementsKind::HOLE:
1124514f5e3Sopenharmony_ci        case ElementsKind::HOLE_INT:
1134514f5e3Sopenharmony_ci        case ElementsKind::HOLE_NUMBER:
1144514f5e3Sopenharmony_ci        case ElementsKind::HOLE_STRING:
1154514f5e3Sopenharmony_ci        case ElementsKind::HOLE_OBJECT:
1164514f5e3Sopenharmony_ci            break;
1174514f5e3Sopenharmony_ci        default:
1184514f5e3Sopenharmony_ci            if (IsHole(result)) {
1194514f5e3Sopenharmony_ci                result = ElementsKind::HOLE_TAGGED;
1204514f5e3Sopenharmony_ci            } else {
1214514f5e3Sopenharmony_ci                result = ElementsKind::TAGGED;
1224514f5e3Sopenharmony_ci            }
1234514f5e3Sopenharmony_ci            break;
1244514f5e3Sopenharmony_ci    }
1254514f5e3Sopenharmony_ci    return result;
1264514f5e3Sopenharmony_ci}
1274514f5e3Sopenharmony_ci
1284514f5e3Sopenharmony_ciElementsKind Elements::ToElementsKind(JSTaggedValue value, ElementsKind kind)
1294514f5e3Sopenharmony_ci{
1304514f5e3Sopenharmony_ci    ElementsKind valueKind = ElementsKind::NONE;
1314514f5e3Sopenharmony_ci    if (value.IsInt()) {
1324514f5e3Sopenharmony_ci        valueKind = ElementsKind::INT;
1334514f5e3Sopenharmony_ci    } else if (value.IsDouble()) {
1344514f5e3Sopenharmony_ci        valueKind = ElementsKind::NUMBER;
1354514f5e3Sopenharmony_ci    } else if (value.IsString()) {
1364514f5e3Sopenharmony_ci        valueKind = ElementsKind::STRING;
1374514f5e3Sopenharmony_ci    } else if (value.IsHeapObject()) {
1384514f5e3Sopenharmony_ci        valueKind = ElementsKind::OBJECT;
1394514f5e3Sopenharmony_ci    } else if (value.IsHole()) {
1404514f5e3Sopenharmony_ci        valueKind = ElementsKind::HOLE;
1414514f5e3Sopenharmony_ci    } else {
1424514f5e3Sopenharmony_ci        valueKind = ElementsKind::TAGGED;
1434514f5e3Sopenharmony_ci    }
1444514f5e3Sopenharmony_ci    return MergeElementsKind(valueKind, kind);
1454514f5e3Sopenharmony_ci}
1464514f5e3Sopenharmony_ci
1474514f5e3Sopenharmony_civoid Elements::HandleIntKindMigration(const JSThread *thread, const JSHandle<JSObject> &object,
1484514f5e3Sopenharmony_ci                                      const ElementsKind newKind, bool needCOW)
1494514f5e3Sopenharmony_ci{
1504514f5e3Sopenharmony_ci    if (IsStringOrNoneOrHole(newKind)) {
1514514f5e3Sopenharmony_ci        JSTaggedValue newElements = MigrateFromRawValueToHeapValue(thread, object, needCOW, true);
1524514f5e3Sopenharmony_ci        object->SetElements(thread, newElements);
1534514f5e3Sopenharmony_ci    } else if (newKind == ElementsKind::NUMBER || newKind == ElementsKind::HOLE_NUMBER) {
1544514f5e3Sopenharmony_ci        MigrateFromHoleIntToHoleNumber(thread, object);
1554514f5e3Sopenharmony_ci    }
1564514f5e3Sopenharmony_ci}
1574514f5e3Sopenharmony_ci
1584514f5e3Sopenharmony_cibool Elements::IsNumberKind(const ElementsKind kind)
1594514f5e3Sopenharmony_ci{
1604514f5e3Sopenharmony_ci    return static_cast<uint32_t>(kind) >= static_cast<uint32_t>(ElementsKind::NUMBER) &&
1614514f5e3Sopenharmony_ci           static_cast<uint32_t>(kind) <= static_cast<uint32_t>(ElementsKind::HOLE_NUMBER);
1624514f5e3Sopenharmony_ci}
1634514f5e3Sopenharmony_ci
1644514f5e3Sopenharmony_cibool Elements::IsStringOrNoneOrHole(const ElementsKind kind)
1654514f5e3Sopenharmony_ci{
1664514f5e3Sopenharmony_ci    return static_cast<uint32_t>(kind) >= static_cast<uint32_t>(ElementsKind::STRING) ||
1674514f5e3Sopenharmony_ci           kind == ElementsKind::NONE || kind == ElementsKind::HOLE;
1684514f5e3Sopenharmony_ci}
1694514f5e3Sopenharmony_ci
1704514f5e3Sopenharmony_civoid Elements::HandleNumberKindMigration(const JSThread *thread, const JSHandle<JSObject> &object,
1714514f5e3Sopenharmony_ci                                         const ElementsKind newKind, bool needCOW)
1724514f5e3Sopenharmony_ci{
1734514f5e3Sopenharmony_ci    if (IsStringOrNoneOrHole(newKind)) {
1744514f5e3Sopenharmony_ci        JSTaggedValue newElements = MigrateFromRawValueToHeapValue(thread, object, needCOW, false);
1754514f5e3Sopenharmony_ci        object->SetElements(thread, newElements);
1764514f5e3Sopenharmony_ci    } else if (newKind == ElementsKind::INT || newKind == ElementsKind::HOLE_INT) {
1774514f5e3Sopenharmony_ci        MigrateFromHoleNumberToHoleInt(thread, object);
1784514f5e3Sopenharmony_ci    }
1794514f5e3Sopenharmony_ci}
1804514f5e3Sopenharmony_ci
1814514f5e3Sopenharmony_civoid Elements::HandleOtherKindMigration(const JSThread *thread, const JSHandle<JSObject> &object,
1824514f5e3Sopenharmony_ci                                        const ElementsKind newKind, bool needCOW)
1834514f5e3Sopenharmony_ci{
1844514f5e3Sopenharmony_ci    if (newKind == ElementsKind::INT || newKind == ElementsKind::HOLE_INT) {
1854514f5e3Sopenharmony_ci        JSTaggedValue newElements = MigrateFromHeapValueToRawValue(thread, object, needCOW, true);
1864514f5e3Sopenharmony_ci        object->SetElements(thread, newElements);
1874514f5e3Sopenharmony_ci    } else if (IsNumberKind(newKind)) {
1884514f5e3Sopenharmony_ci        JSTaggedValue newElements = MigrateFromHeapValueToRawValue(thread, object, needCOW, false);
1894514f5e3Sopenharmony_ci        object->SetElements(thread, newElements);
1904514f5e3Sopenharmony_ci    }
1914514f5e3Sopenharmony_ci}
1924514f5e3Sopenharmony_ci
1934514f5e3Sopenharmony_civoid Elements::MigrateArrayWithKind(const JSThread *thread, const JSHandle<JSObject> &object,
1944514f5e3Sopenharmony_ci                                    const ElementsKind oldKind, const ElementsKind newKind)
1954514f5e3Sopenharmony_ci{
1964514f5e3Sopenharmony_ci    if (!thread->GetEcmaVM()->IsEnableElementsKind()) {
1974514f5e3Sopenharmony_ci        return;
1984514f5e3Sopenharmony_ci    }
1994514f5e3Sopenharmony_ci
2004514f5e3Sopenharmony_ci    if (oldKind == newKind ||
2014514f5e3Sopenharmony_ci        (oldKind == ElementsKind::INT && newKind == ElementsKind::HOLE_INT) ||
2024514f5e3Sopenharmony_ci        (oldKind == ElementsKind::NUMBER && newKind == ElementsKind::HOLE_NUMBER)) {
2034514f5e3Sopenharmony_ci        return;
2044514f5e3Sopenharmony_ci    }
2054514f5e3Sopenharmony_ci
2064514f5e3Sopenharmony_ci    bool needCOW = object->GetElements().IsCOWArray();
2074514f5e3Sopenharmony_ci
2084514f5e3Sopenharmony_ci    if (oldKind == ElementsKind::INT || oldKind == ElementsKind::HOLE_INT) {
2094514f5e3Sopenharmony_ci        HandleIntKindMigration(thread, object, newKind, needCOW);
2104514f5e3Sopenharmony_ci    } else if ((IsNumberKind(oldKind))) {
2114514f5e3Sopenharmony_ci        HandleNumberKindMigration(thread, object, newKind, needCOW);
2124514f5e3Sopenharmony_ci    } else {
2134514f5e3Sopenharmony_ci        HandleOtherKindMigration(thread, object, newKind, needCOW);
2144514f5e3Sopenharmony_ci    }
2154514f5e3Sopenharmony_ci}
2164514f5e3Sopenharmony_ci
2174514f5e3Sopenharmony_ciJSTaggedValue Elements::MigrateFromRawValueToHeapValue(const JSThread *thread, const JSHandle<JSObject> object,
2184514f5e3Sopenharmony_ci                                                       bool needCOW, bool isIntKind)
2194514f5e3Sopenharmony_ci{
2204514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2214514f5e3Sopenharmony_ci    JSHandle<MutantTaggedArray> elements = JSHandle<MutantTaggedArray>(thread, object->GetElements());
2224514f5e3Sopenharmony_ci    uint32_t length = elements->GetLength();
2234514f5e3Sopenharmony_ci    JSMutableHandle<TaggedArray> newElements(thread, JSTaggedValue::Undefined());
2244514f5e3Sopenharmony_ci    if (needCOW) {
2254514f5e3Sopenharmony_ci        newElements.Update(factory->NewCOWTaggedArray(length));
2264514f5e3Sopenharmony_ci    } else {
2274514f5e3Sopenharmony_ci        newElements.Update(factory->NewTaggedArray(length));
2284514f5e3Sopenharmony_ci    }
2294514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < length; i++) {
2304514f5e3Sopenharmony_ci        JSTaggedType value = elements->Get(i).GetRawData();
2314514f5e3Sopenharmony_ci        if (value == base::SPECIAL_HOLE) {
2324514f5e3Sopenharmony_ci            newElements->Set(thread, i, JSTaggedValue::Hole());
2334514f5e3Sopenharmony_ci        } else if (isIntKind) {
2344514f5e3Sopenharmony_ci            int convertedValue = static_cast<int>(value);
2354514f5e3Sopenharmony_ci            newElements->Set(thread, i, JSTaggedValue(convertedValue));
2364514f5e3Sopenharmony_ci        } else {
2374514f5e3Sopenharmony_ci            double convertedValue = base::bit_cast<double>(value);
2384514f5e3Sopenharmony_ci            newElements->Set(thread, i, JSTaggedValue(convertedValue));
2394514f5e3Sopenharmony_ci        }
2404514f5e3Sopenharmony_ci    }
2414514f5e3Sopenharmony_ci    return newElements.GetTaggedValue();
2424514f5e3Sopenharmony_ci}
2434514f5e3Sopenharmony_ci
2444514f5e3Sopenharmony_ciJSTaggedValue Elements::MigrateFromHeapValueToRawValue(const JSThread *thread, const JSHandle<JSObject> object,
2454514f5e3Sopenharmony_ci                                                       bool needCOW, bool isIntKind)
2464514f5e3Sopenharmony_ci{
2474514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
2484514f5e3Sopenharmony_ci    JSHandle<TaggedArray> elements = JSHandle<TaggedArray>(thread, object->GetElements());
2494514f5e3Sopenharmony_ci    uint32_t length = elements->GetLength();
2504514f5e3Sopenharmony_ci    JSMutableHandle<MutantTaggedArray> newElements(thread, JSTaggedValue::Undefined());
2514514f5e3Sopenharmony_ci    if (needCOW) {
2524514f5e3Sopenharmony_ci        newElements.Update(factory->NewCOWMutantTaggedArray(length));
2534514f5e3Sopenharmony_ci    } else {
2544514f5e3Sopenharmony_ci        newElements.Update(factory->NewMutantTaggedArray(length));
2554514f5e3Sopenharmony_ci    }
2564514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < length; i++) {
2574514f5e3Sopenharmony_ci        JSTaggedValue value = elements->Get(i);
2584514f5e3Sopenharmony_ci        JSTaggedType convertedValue = 0;
2594514f5e3Sopenharmony_ci        // To distinguish Hole (0x5) in taggedvalue with Interger 5
2604514f5e3Sopenharmony_ci        if (value.IsHole()) {
2614514f5e3Sopenharmony_ci            convertedValue = base::SPECIAL_HOLE;
2624514f5e3Sopenharmony_ci        } else if (isIntKind) {
2634514f5e3Sopenharmony_ci            convertedValue = static_cast<JSTaggedType>(value.GetInt());
2644514f5e3Sopenharmony_ci        } else if (value.IsInt()) {
2654514f5e3Sopenharmony_ci            int intValue = value.GetInt();
2664514f5e3Sopenharmony_ci            convertedValue = base::bit_cast<JSTaggedType>(static_cast<double>(intValue));
2674514f5e3Sopenharmony_ci        } else {
2684514f5e3Sopenharmony_ci            convertedValue = base::bit_cast<JSTaggedType>(value.GetDouble());
2694514f5e3Sopenharmony_ci        }
2704514f5e3Sopenharmony_ci        newElements->Set<false>(thread, i, JSTaggedValue(convertedValue));
2714514f5e3Sopenharmony_ci    }
2724514f5e3Sopenharmony_ci    return newElements.GetTaggedValue();
2734514f5e3Sopenharmony_ci}
2744514f5e3Sopenharmony_ci
2754514f5e3Sopenharmony_civoid Elements::MigrateFromHoleIntToHoleNumber(const JSThread *thread, const JSHandle<JSObject> object)
2764514f5e3Sopenharmony_ci{
2774514f5e3Sopenharmony_ci    JSHandle<MutantTaggedArray> elements = JSHandle<MutantTaggedArray>(thread, object->GetElements());
2784514f5e3Sopenharmony_ci    uint32_t length = elements->GetLength();
2794514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < length; i++) {
2804514f5e3Sopenharmony_ci        JSTaggedType value = elements->Get(i).GetRawData();
2814514f5e3Sopenharmony_ci        if (value == base::SPECIAL_HOLE) {
2824514f5e3Sopenharmony_ci            continue;
2834514f5e3Sopenharmony_ci        }
2844514f5e3Sopenharmony_ci        int intValue = static_cast<int>(elements->Get(i).GetRawData());
2854514f5e3Sopenharmony_ci        double convertedValue = static_cast<double>(intValue);
2864514f5e3Sopenharmony_ci        elements->Set<false>(thread, i, JSTaggedValue(base::bit_cast<JSTaggedType>(convertedValue)));
2874514f5e3Sopenharmony_ci    }
2884514f5e3Sopenharmony_ci}
2894514f5e3Sopenharmony_ci
2904514f5e3Sopenharmony_civoid Elements::MigrateFromHoleNumberToHoleInt(const JSThread *thread, const JSHandle<JSObject> object)
2914514f5e3Sopenharmony_ci{
2924514f5e3Sopenharmony_ci    JSHandle<MutantTaggedArray> elements = JSHandle<MutantTaggedArray>(thread, object->GetElements());
2934514f5e3Sopenharmony_ci    uint32_t length = elements->GetLength();
2944514f5e3Sopenharmony_ci    for (uint32_t i = 0; i < length; i++) {
2954514f5e3Sopenharmony_ci        JSTaggedType value = elements->Get(i).GetRawData();
2964514f5e3Sopenharmony_ci        if (value == base::SPECIAL_HOLE) {
2974514f5e3Sopenharmony_ci            continue;
2984514f5e3Sopenharmony_ci        }
2994514f5e3Sopenharmony_ci        double intValue = base::bit_cast<double>(elements->Get(i).GetRawData());
3004514f5e3Sopenharmony_ci        int64_t convertedValue = static_cast<int64_t>(intValue);
3014514f5e3Sopenharmony_ci        elements->Set<false>(thread, i, JSTaggedValue(base::bit_cast<JSTaggedType>(convertedValue)));
3024514f5e3Sopenharmony_ci    }
3034514f5e3Sopenharmony_ci}
3044514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
305