14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2021-2024 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 "builtins_set.h"
174514f5e3Sopenharmony_ci#include "ecmascript/interpreter/interpreter.h"
184514f5e3Sopenharmony_ci#include "ecmascript/js_function.h"
194514f5e3Sopenharmony_ci#include "ecmascript/js_set.h"
204514f5e3Sopenharmony_ci#include "ecmascript/js_set_iterator.h"
214514f5e3Sopenharmony_ci#include "ecmascript/linked_hash_table.h"
224514f5e3Sopenharmony_cinamespace panda::ecmascript::builtins {
234514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv)
244514f5e3Sopenharmony_ci{
254514f5e3Sopenharmony_ci    ASSERT(argv);
264514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Constructor);
274514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
284514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
294514f5e3Sopenharmony_ci    ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
304514f5e3Sopenharmony_ci    // 1.If NewTarget is undefined, throw a TypeError exception
314514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> newTarget = GetNewTarget(argv);
324514f5e3Sopenharmony_ci    if (newTarget->IsUndefined()) {
334514f5e3Sopenharmony_ci        // throw type error
344514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception());
354514f5e3Sopenharmony_ci    }
364514f5e3Sopenharmony_ci    // 2.Let set be OrdinaryCreateFromConstructor(NewTarget, "%SetPrototype%", «‍[[SetData]]» ).
374514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> constructor = GetConstructor(argv);
384514f5e3Sopenharmony_ci    JSHandle<JSObject> obj = factory->NewJSObjectByConstructor(JSHandle<JSFunction>(constructor), newTarget);
394514f5e3Sopenharmony_ci    // 3.returnIfAbrupt()
404514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
414514f5e3Sopenharmony_ci    JSHandle<JSSet> set = JSHandle<JSSet>::Cast(obj);
424514f5e3Sopenharmony_ci    // 3.ReturnIfAbrupt(set).
434514f5e3Sopenharmony_ci    // 4.Set set’s [[SetData]] internal slot to a new empty List.
444514f5e3Sopenharmony_ci    JSHandle<LinkedHashSet> linkedSet = LinkedHashSet::Create(thread);
454514f5e3Sopenharmony_ci    set->SetLinkedSet(thread, linkedSet);
464514f5e3Sopenharmony_ci
474514f5e3Sopenharmony_ci    // add data into set from iterable
484514f5e3Sopenharmony_ci    // 5.If iterable is not present, let iterable be undefined.
494514f5e3Sopenharmony_ci    // 6.If iterable is either undefined or null, let iter be undefined.
504514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> iterable(GetCallArg(argv, 0));
514514f5e3Sopenharmony_ci    // 8.If iter is undefined, return set
524514f5e3Sopenharmony_ci    if (iterable->IsUndefined() || iterable->IsNull()) {
534514f5e3Sopenharmony_ci        return set.GetTaggedValue();
544514f5e3Sopenharmony_ci    }
554514f5e3Sopenharmony_ci    // Let adder be Get(set, "add").
564514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> adderKey(thread->GlobalConstants()->GetHandledAddString());
574514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> setHandle(set);
584514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> adder = JSObject::GetProperty(thread, setHandle, adderKey).GetValue();
594514f5e3Sopenharmony_ci    // ReturnIfAbrupt(adder).
604514f5e3Sopenharmony_ci    RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, adder.GetTaggedValue());
614514f5e3Sopenharmony_ci    // If IsCallable(adder) is false, throw a TypeError exception
624514f5e3Sopenharmony_ci    if (!adder->IsCallable()) {
634514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "adder is not callable", adder.GetTaggedValue());
644514f5e3Sopenharmony_ci    }
654514f5e3Sopenharmony_ci    // Let iter be GetIterator(iterable).
664514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> iter(JSIterator::GetIterator(thread, iterable));
674514f5e3Sopenharmony_ci    // ReturnIfAbrupt(iter).
684514f5e3Sopenharmony_ci    RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter.GetTaggedValue());
694514f5e3Sopenharmony_ci    // values in iterator_result may be a JSArray, values[0] = key values[1]=value, used valueIndex to get value from
704514f5e3Sopenharmony_ci    // jsarray
714514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> valueIndex(thread, JSTaggedValue(1));
724514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> next = JSIterator::IteratorStep(thread, iter);
734514f5e3Sopenharmony_ci    RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue());
744514f5e3Sopenharmony_ci    while (!next->IsFalse()) {
754514f5e3Sopenharmony_ci        // Let nextValue be IteratorValue(next).
764514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> nextValue(JSIterator::IteratorValue(thread, next));
774514f5e3Sopenharmony_ci        // ReturnIfAbrupt(nextValue).
784514f5e3Sopenharmony_ci        RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue());
794514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
804514f5e3Sopenharmony_ci        EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, adder, setHandle, undefined, 1);
814514f5e3Sopenharmony_ci        RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue());
824514f5e3Sopenharmony_ci        info->SetCallArg(nextValue.GetTaggedValue());
834514f5e3Sopenharmony_ci        if (nextValue->IsArray(thread)) {
844514f5e3Sopenharmony_ci            auto prop = JSTaggedValue::GetProperty(thread, nextValue, valueIndex).GetValue();
854514f5e3Sopenharmony_ci            info->SetCallArg(prop.GetTaggedValue());
864514f5e3Sopenharmony_ci        }
874514f5e3Sopenharmony_ci        JSFunction::Call(info);
884514f5e3Sopenharmony_ci        // Let status be Call(adder, set, «nextValue.[[value]]»).
894514f5e3Sopenharmony_ci        if (thread->HasPendingException()) {
904514f5e3Sopenharmony_ci            return JSIterator::IteratorCloseAndReturn(thread, iter);
914514f5e3Sopenharmony_ci        }
924514f5e3Sopenharmony_ci        // Let next be IteratorStep(iter).
934514f5e3Sopenharmony_ci        next = JSIterator::IteratorStep(thread, iter);
944514f5e3Sopenharmony_ci        // ReturnIfAbrupt(next).
954514f5e3Sopenharmony_ci        RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue());
964514f5e3Sopenharmony_ci    }
974514f5e3Sopenharmony_ci    return set.GetTaggedValue();
984514f5e3Sopenharmony_ci}
994514f5e3Sopenharmony_ci
1004514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Add(EcmaRuntimeCallInfo *argv)
1014514f5e3Sopenharmony_ci{
1024514f5e3Sopenharmony_ci    ASSERT(argv);
1034514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Add);
1044514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
1054514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
1064514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
1074514f5e3Sopenharmony_ci
1084514f5e3Sopenharmony_ci    // 2.If Type(S) is not Object, throw a TypeError exception.
1094514f5e3Sopenharmony_ci    // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception.
1104514f5e3Sopenharmony_ci    if (!self->IsJSSet()) {
1114514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception());
1124514f5e3Sopenharmony_ci    }
1134514f5e3Sopenharmony_ci
1144514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> value(GetCallArg(argv, 0));
1154514f5e3Sopenharmony_ci    JSHandle<JSSet> set(self);
1164514f5e3Sopenharmony_ci    JSSet::Add(thread, set, value);
1174514f5e3Sopenharmony_ci    return set.GetTaggedValue();
1184514f5e3Sopenharmony_ci}
1194514f5e3Sopenharmony_ci
1204514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Clear(EcmaRuntimeCallInfo *argv)
1214514f5e3Sopenharmony_ci{
1224514f5e3Sopenharmony_ci    ASSERT(argv);
1234514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Clear);
1244514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
1254514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
1264514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
1274514f5e3Sopenharmony_ci
1284514f5e3Sopenharmony_ci    // 2.If Type(S) is not Object, throw a TypeError exception.
1294514f5e3Sopenharmony_ci    // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception.
1304514f5e3Sopenharmony_ci    if (!self->IsJSSet()) {
1314514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception());
1324514f5e3Sopenharmony_ci    }
1334514f5e3Sopenharmony_ci    JSHandle<JSSet> set(self);
1344514f5e3Sopenharmony_ci    JSSet::Clear(thread, set);
1354514f5e3Sopenharmony_ci    return JSTaggedValue::Undefined();
1364514f5e3Sopenharmony_ci}
1374514f5e3Sopenharmony_ci
1384514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Delete(EcmaRuntimeCallInfo *argv)
1394514f5e3Sopenharmony_ci{
1404514f5e3Sopenharmony_ci    ASSERT(argv);
1414514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Delete);
1424514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
1434514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
1444514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
1454514f5e3Sopenharmony_ci    // 2.If Type(S) is not Object, throw a TypeError exception.
1464514f5e3Sopenharmony_ci    // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception.
1474514f5e3Sopenharmony_ci    if (!self->IsJSSet()) {
1484514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception());
1494514f5e3Sopenharmony_ci    }
1504514f5e3Sopenharmony_ci
1514514f5e3Sopenharmony_ci    JSHandle<JSSet> set(self);
1524514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
1534514f5e3Sopenharmony_ci    bool flag = JSSet::Delete(thread, set, value);
1544514f5e3Sopenharmony_ci    return GetTaggedBoolean(flag);
1554514f5e3Sopenharmony_ci}
1564514f5e3Sopenharmony_ci
1574514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Has(EcmaRuntimeCallInfo *argv)
1584514f5e3Sopenharmony_ci{
1594514f5e3Sopenharmony_ci    ASSERT(argv);
1604514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Has);
1614514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
1624514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
1634514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
1644514f5e3Sopenharmony_ci    // 2.If Type(S) is not Object, throw a TypeError exception.
1654514f5e3Sopenharmony_ci    // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception.
1664514f5e3Sopenharmony_ci    if (!self->IsJSSet()) {
1674514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception());
1684514f5e3Sopenharmony_ci    }
1694514f5e3Sopenharmony_ci    JSSet* jsSet = JSSet::Cast(self.GetTaggedValue().GetTaggedObject());
1704514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> value = GetCallArg(argv, 0);
1714514f5e3Sopenharmony_ci    bool flag = jsSet->Has(thread, value.GetTaggedValue());
1724514f5e3Sopenharmony_ci    return GetTaggedBoolean(flag);
1734514f5e3Sopenharmony_ci}
1744514f5e3Sopenharmony_ci
1754514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::ForEach(EcmaRuntimeCallInfo *argv)
1764514f5e3Sopenharmony_ci{
1774514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
1784514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(thread, Set, ForEach);
1794514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
1804514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
1814514f5e3Sopenharmony_ci    // 2.If Type(S) is not Object, throw a TypeError exception.
1824514f5e3Sopenharmony_ci    // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception.
1834514f5e3Sopenharmony_ci    if (!self->IsJSSet()) {
1844514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception());
1854514f5e3Sopenharmony_ci    }
1864514f5e3Sopenharmony_ci    JSHandle<JSSet> set(self);
1874514f5e3Sopenharmony_ci
1884514f5e3Sopenharmony_ci    // 4.If IsCallable(callbackfn) is false, throw a TypeError exception.
1894514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> func(GetCallArg(argv, 0));
1904514f5e3Sopenharmony_ci    if (!func->IsCallable()) {
1914514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "callbackfn is not callable", JSTaggedValue::Exception());
1924514f5e3Sopenharmony_ci    }
1934514f5e3Sopenharmony_ci
1944514f5e3Sopenharmony_ci    // 5.If thisArg was supplied, let T be thisArg; else let T be undefined.
1954514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> thisArg = GetCallArg(argv, 1);
1964514f5e3Sopenharmony_ci
1974514f5e3Sopenharmony_ci    // 6.Let entries be the List that is the value of S’s [[SetData]] internal slot.
1984514f5e3Sopenharmony_ci    JSMutableHandle<LinkedHashSet> hashSet(thread, set->GetLinkedSet());
1994514f5e3Sopenharmony_ci    const uint32_t argsLength = 3;
2004514f5e3Sopenharmony_ci    int index = 0;
2014514f5e3Sopenharmony_ci    int totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements();
2024514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
2034514f5e3Sopenharmony_ci    // 7.Repeat for each e that is an element of entries, in original insertion order
2044514f5e3Sopenharmony_ci    while (index < totalElements) {
2054514f5e3Sopenharmony_ci        JSHandle<JSTaggedValue> key(thread, hashSet->GetKey(index++));
2064514f5e3Sopenharmony_ci        // a. If e is not empty, then
2074514f5e3Sopenharmony_ci        if (!key->IsHole()) {
2084514f5e3Sopenharmony_ci            EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(
2094514f5e3Sopenharmony_ci                thread, func, thisArg, undefined, argsLength);
2104514f5e3Sopenharmony_ci            RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2114514f5e3Sopenharmony_ci            info->SetCallArg(key.GetTaggedValue(), key.GetTaggedValue(), set.GetTaggedValue());
2124514f5e3Sopenharmony_ci            // i. Let funcResult be Call(callbackfn, T, «e, e, S»).
2134514f5e3Sopenharmony_ci            JSTaggedValue ret = JSFunction::Call(info);  // 3: three args
2144514f5e3Sopenharmony_ci            // ii. ReturnIfAbrupt(funcResult).
2154514f5e3Sopenharmony_ci            RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret);
2164514f5e3Sopenharmony_ci            // Maybe add or delete
2174514f5e3Sopenharmony_ci            JSTaggedValue nextTable = hashSet->GetNextTable();
2184514f5e3Sopenharmony_ci            while (!nextTable.IsHole()) {
2194514f5e3Sopenharmony_ci                index -= hashSet->GetDeletedElementsAt(index);
2204514f5e3Sopenharmony_ci                hashSet.Update(nextTable);
2214514f5e3Sopenharmony_ci                nextTable = hashSet->GetNextTable();
2224514f5e3Sopenharmony_ci            }
2234514f5e3Sopenharmony_ci            totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements();
2244514f5e3Sopenharmony_ci        }
2254514f5e3Sopenharmony_ci    }
2264514f5e3Sopenharmony_ci    return JSTaggedValue::Undefined();
2274514f5e3Sopenharmony_ci}
2284514f5e3Sopenharmony_ci
2294514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Species(EcmaRuntimeCallInfo *argv)
2304514f5e3Sopenharmony_ci{
2314514f5e3Sopenharmony_ci    return GetThis(argv).GetTaggedValue();
2324514f5e3Sopenharmony_ci}
2334514f5e3Sopenharmony_ci
2344514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::GetSize(EcmaRuntimeCallInfo *argv)
2354514f5e3Sopenharmony_ci{
2364514f5e3Sopenharmony_ci    ASSERT(argv);
2374514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, GetSize);
2384514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
2394514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
2404514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self(GetThis(argv));
2414514f5e3Sopenharmony_ci    // 2.If Type(S) is not Object, throw a TypeError exception.
2424514f5e3Sopenharmony_ci    // 3.If S does not have a [[SetData]] internal slot, throw a TypeError exception.
2434514f5e3Sopenharmony_ci    if (!self->IsJSSet()) {
2444514f5e3Sopenharmony_ci        THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSSet", JSTaggedValue::Exception());
2454514f5e3Sopenharmony_ci    }
2464514f5e3Sopenharmony_ci    JSSet* jsSet = JSSet::Cast(self.GetTaggedValue().GetTaggedObject());
2474514f5e3Sopenharmony_ci    uint32_t count = jsSet->GetSize();
2484514f5e3Sopenharmony_ci    return JSTaggedValue(count);
2494514f5e3Sopenharmony_ci}
2504514f5e3Sopenharmony_ci
2514514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Entries(EcmaRuntimeCallInfo *argv)
2524514f5e3Sopenharmony_ci{
2534514f5e3Sopenharmony_ci    ASSERT(argv);
2544514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Entries);
2554514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
2564514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
2574514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
2584514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::KEY_AND_VALUE);
2594514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2604514f5e3Sopenharmony_ci    return iter.GetTaggedValue();
2614514f5e3Sopenharmony_ci}
2624514f5e3Sopenharmony_ci
2634514f5e3Sopenharmony_ciJSTaggedValue BuiltinsSet::Values(EcmaRuntimeCallInfo *argv)
2644514f5e3Sopenharmony_ci{
2654514f5e3Sopenharmony_ci    ASSERT(argv);
2664514f5e3Sopenharmony_ci    BUILTINS_API_TRACE(argv->GetThread(), Set, Values);
2674514f5e3Sopenharmony_ci    JSThread *thread = argv->GetThread();
2684514f5e3Sopenharmony_ci    [[maybe_unused]] EcmaHandleScope handleScope(thread);
2694514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> self = GetThis(argv);
2704514f5e3Sopenharmony_ci    JSHandle<JSTaggedValue> iter = JSSetIterator::CreateSetIterator(thread, self, IterationKind::VALUE);
2714514f5e3Sopenharmony_ci    RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
2724514f5e3Sopenharmony_ci    return iter.GetTaggedValue();
2734514f5e3Sopenharmony_ci}
2744514f5e3Sopenharmony_ci}  // namespace panda::ecmascript::builtins
275