• 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 */
22
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    assert_equal(err instanceof TypeError, true);
34}
35
36assert_equal(wm.has(s1),true);
37assert_equal(wm.get(s1),1);
38assert_equal(wm.delete(s1),true);
39assert_equal(wm.has(s1),false);
40
41assert_equal(wm.has(s2),false);
42assert_equal(wm.get(s2),undefined);
43assert_equal(wm.delete(s2),false);
44
45const symbolFuncsSet = [
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];
60
61symbolFuncsSet.forEach(function (ctor, i) {
62    wm.set(ctor, i);
63});
64
65assert_equal(wm.get(Symbol.match) == 4,true);
66
67test_end();