1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/* 17 * @tc.name: forof_set 18 * @tc.desc: test set forof 19 * @tc.type: FUNC 20 */ 21let comBinedSet = new Set([ 22 "ark_stringValue", 23 1, 24 true, 25 {}, 26 null, 27 undefined, 28 NaN, 29 Infinity, 30 -Infinity, 31 RegExp("ark_regexValue"), 32 new Map(), 33 new Set(), 34 Array.from([1, 2, 3]), 35 "ark_unicodeValue " 36]); 37 38for (const key of comBinedSet.keys()) { 39 print(key); 40} 41 42for (const value of comBinedSet.values()) { 43 print(value); 44} 45 46for (const entry of comBinedSet.entries()) { 47 print(entry); 48} 49 50let keyIterator = comBinedSet.keys(); 51let valueIterator = comBinedSet.values(); 52let entriesIterator = comBinedSet.entries(); 53 54print(keyIterator.next().value); 55print(keyIterator.next().done); 56 57print(valueIterator.next().value); 58print(valueIterator.next().done); 59 60while (!entriesIterator.next().done) { 61} 62print(entriesIterator.next().value); 63 64let iterResult; 65// start point is [true] 66while (!(iterResult = keyIterator.next()).done) { 67 print(iterResult.value); 68 if (Object.is(iterResult.value, NaN)) { 69 // update comBinedSet 70 comBinedSet.delete(true); 71 comBinedSet.delete("ark_unicodeValue "); 72 comBinedSet.add("new_key"); 73 } 74 if (iterResult.value == Infinity) { 75 // check combinedSet 76 if (!comBinedSet.has(true)) { 77 print("[true] is deleted"); 78 } 79 } 80} 81 82class MySet extends Set { 83 constructor() { 84 super(); 85 } 86} 87 88const newSet = new MySet([ 89 1, 90 2, 91 3, 92]); 93 94for (let value of newSet.values()) { 95 print(value); 96 if (value == 2) { 97 break; 98 } 99} 100