• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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:weakmapsymbolkey
18 * @tc.desc:test WeakMap allow the use of most Symbols as keys
19 * @tc.type: FUNC
20 * @tc.require: issueI7J2VN
21 */
22print("weakmapsymbolkey test start");
23let wm = new WeakMap();
24let o = {};
25wm.set(o, 0);
26let s1 = Symbol("symbol1");
27wm.set(s1, 1);
28
29let s2 = Symbol.for("symbol2");
30try {
31    wm.set(s2, 2);
32} catch (err) {
33    print(err.name);
34}
35
36print("wm.has(s1) " + wm.has(s1));
37print("wm.get(s1) " + wm.get(s1));
38print("wm.delete(s1) " + wm.delete(s1));
39print("wm.has(s1) " + wm.has(s1));
40
41print("wm.has(s2) " + wm.has(s2));
42print("wm.get(s2) " + wm.get(s2));
43print("wm.delete(s2) " + wm.delete(s2));
44
45[
46    Symbol.asyncIterator,
47    Symbol.hasInstance,
48    Symbol.isConcatSpreadable,
49    Symbol.iterator,
50    Symbol.match,
51    Symbol.matchAll,
52    Symbol.replace,
53    Symbol.search,
54    Symbol.species,
55    Symbol.split,
56    Symbol.toPrimitive,
57    Symbol.toStringTag,
58    Symbol.unscopables
59].forEach(function (ctor, i) {
60    wm.set(ctor, i);
61});
62
63print("wm.get(Symbol.match) == 4 " + (wm.get(Symbol.match) == 4));
64print("weakmapsymbolkey test end");