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:weakrefforsymbol 18 * @tc.desc:test WeakRef allow the use of most Symbols as targets 19 * @tc.type: FUNC 20 * @tc.require: issueI7J2VN 21 */ 22 23let target1 = Symbol("symbol1"); 24let wr1 = new WeakRef(target1); 25 26let target2 = Symbol.for("symbol2"); 27try { 28 let wr2 = new WeakRef(target2); 29} catch (err) { 30 assert_equal(err instanceof TypeError, true); 31} 32 33const symbolFuncsRef = [ 34 Symbol.asyncIterator, 35 Symbol.hasInstance, 36 Symbol.isConcatSpreadable, 37 Symbol.iterator, 38 Symbol.match, 39 Symbol.matchAll, 40 Symbol.replace, 41 Symbol.search, 42 Symbol.species, 43 Symbol.split, 44 Symbol.toPrimitive, 45 Symbol.toStringTag, 46 Symbol.unscopables 47]; 48 49const symbolFuncsRefAssertLsit = [ 50 true, 51 true, 52 true, 53 true, 54 true, 55 true, 56 true, 57 true, 58 true, 59 true, 60 true, 61 true, 62 true 63]; 64let symbolFuncsRefResLsit = []; 65 66symbolFuncsRef.forEach(function (ctor, i) { 67 let wr = new WeakRef(ctor); 68 symbolFuncsRefResLsit.push(wr.deref() == ctor); 69}); 70 71assert_equal(symbolFuncsRefResLsit, symbolFuncsRefAssertLsit); 72 73test_end();