14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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/* 174514f5e3Sopenharmony_ci * @tc.name:weakmapsymbolkey 184514f5e3Sopenharmony_ci * @tc.desc:test WeakMap allow the use of most Symbols as keys 194514f5e3Sopenharmony_ci * @tc.type: FUNC 204514f5e3Sopenharmony_ci * @tc.require: issueI7J2VN 214514f5e3Sopenharmony_ci */ 224514f5e3Sopenharmony_ciprint("weakmapsymbolkey test start"); 234514f5e3Sopenharmony_cilet wm = new WeakMap(); 244514f5e3Sopenharmony_cilet o = {}; 254514f5e3Sopenharmony_ciwm.set(o, 0); 264514f5e3Sopenharmony_cilet s1 = Symbol("symbol1"); 274514f5e3Sopenharmony_ciwm.set(s1, 1); 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cilet s2 = Symbol.for("symbol2"); 304514f5e3Sopenharmony_citry { 314514f5e3Sopenharmony_ci wm.set(s2, 2); 324514f5e3Sopenharmony_ci} catch (err) { 334514f5e3Sopenharmony_ci print(err.name); 344514f5e3Sopenharmony_ci} 354514f5e3Sopenharmony_ci 364514f5e3Sopenharmony_ciprint("wm.has(s1) " + wm.has(s1)); 374514f5e3Sopenharmony_ciprint("wm.get(s1) " + wm.get(s1)); 384514f5e3Sopenharmony_ciprint("wm.delete(s1) " + wm.delete(s1)); 394514f5e3Sopenharmony_ciprint("wm.has(s1) " + wm.has(s1)); 404514f5e3Sopenharmony_ci 414514f5e3Sopenharmony_ciprint("wm.has(s2) " + wm.has(s2)); 424514f5e3Sopenharmony_ciprint("wm.get(s2) " + wm.get(s2)); 434514f5e3Sopenharmony_ciprint("wm.delete(s2) " + wm.delete(s2)); 444514f5e3Sopenharmony_ci 454514f5e3Sopenharmony_ciconst symbolFuncsSet = [ 464514f5e3Sopenharmony_ci Symbol.asyncIterator, 474514f5e3Sopenharmony_ci Symbol.hasInstance, 484514f5e3Sopenharmony_ci Symbol.isConcatSpreadable, 494514f5e3Sopenharmony_ci Symbol.iterator, 504514f5e3Sopenharmony_ci Symbol.match, 514514f5e3Sopenharmony_ci Symbol.matchAll, 524514f5e3Sopenharmony_ci Symbol.replace, 534514f5e3Sopenharmony_ci Symbol.search, 544514f5e3Sopenharmony_ci Symbol.species, 554514f5e3Sopenharmony_ci Symbol.split, 564514f5e3Sopenharmony_ci Symbol.toPrimitive, 574514f5e3Sopenharmony_ci Symbol.toStringTag, 584514f5e3Sopenharmony_ci Symbol.unscopables 594514f5e3Sopenharmony_ci]; 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_cisymbolFuncsSet.forEach(function (ctor, i) { 624514f5e3Sopenharmony_ci wm.set(ctor, i); 634514f5e3Sopenharmony_ci}); 644514f5e3Sopenharmony_ci 654514f5e3Sopenharmony_ciprint("wm.get(Symbol.match) == 4 " + (wm.get(Symbol.match) == 4)); 664514f5e3Sopenharmony_ciprint("weakmapsymbolkey test end");