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