• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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// @ts-nocheck
17declare function print(str: any): string;
18
19print("===Class inheritance test begin ===");
20class SubSendableSet<T> extends SendableSet {
21  desc: string = "I'am SubSendableSet";
22  constructor(entries?: T[] | null) {
23    'use sendable';
24    super(entries);
25  }
26}
27
28let subSharedset = new SubSendableSet<number>();
29subSharedset.add(1);
30print(subSharedset.has(1));
31print(subSharedset.size);
32
33subSharedset = new SubSendableSet<number>([1, 2, 3]);
34print(subSharedset.has(1));
35print(subSharedset.has(2));
36print(subSharedset.has(3));
37print(subSharedset.size);
38
39try {
40  let obj = {};
41  subSharedset = new SubSendableSet<Object>([obj]);
42  print(subSharedset.size);
43} catch (e) {
44  print('SubSendableSet add[unshared]: ' + e + ', errCode: ' + e.code);
45}
46
47subSharedset = new SubSendableSet<string>(['one', 'two', 'three']);
48for (const [key, _] of subSharedset.entries()) {
49  print('SubSendableSet key[for-of]: ' + key);
50}
51
52try {
53  subSharedset = new SubSendableSet<number>([1, 2, 3, 4]);
54  print(subSharedset.size);
55  subSharedset.forEach((key: number, _: number, set: SubSendableSet) => {
56    if (key % 2 == 0) {
57      set.delete(key);
58    }
59  });
60} catch (e) {
61  print('SubSendableSet Delete Scenario[forEach]: ' + e + ', errCode: ' + e.code);
62}
63
64class SubSubSendableSet<T> extends SubSendableSet {
65  constructor(entries?: T[] | null) {
66    'use sendable';
67    super(entries);
68  }
69}
70
71let subSubSendableSet = new SubSubSendableSet<number>([1, 2, 3]);
72print(subSubSendableSet.has(1));
73print(subSubSendableSet.has(2));
74print(subSubSendableSet.has(3));
75print(subSubSendableSet.size);
76
77try {
78  subSubSendableSet['extension'] = 'value';
79} catch(e) {
80  print("add extension(.): " + e);
81}
82try {
83  subSubSendableSet.extension = 'value';
84} catch(e) {
85  print("add extension([]): " + e);
86}
87
88try {
89  let obj = {};
90  subSubSendableSet = new SubSubSendableSet<Object>([obj]);
91  print(subSubSendableSet.size);
92} catch (e) {
93  print('SubSubSendableSet add[unshared]: ' + e + ', errCode: ' + e.code);
94}
95
96try {
97  subSubSendableSet = new SubSubSendableSet<number>([1, 2, 3, 4]);
98  subSubSendableSet.forEach((key: number, _: number, set: SubSubSendableSet) => {
99    if (key % 2 == 0) {
100      set.delete(key);
101    }
102  });
103} catch (e) {
104  print('SubSubSendableSet Delete Scenario[forEach]: ' + e + ', errCode: ' + e.code);
105}
106
107print("===Class inheritance test end ===");
108