1/* 2 * Copyright (c) 2023 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/* 17 * @tc.name:sendablecontext 18 * @tc.desc:test sendablecontext 19 * @tc.type: FUNC 20 * @tc.require: issue#I8SFAK 21 */ 22 23// @ts-nocheck 24declare function print(str: any): string; 25 26class SendableClassA { 27 static staticField: string = "staticField"; 28 constructor() { 29 "use sendable"; 30 } 31 32 testZeroLevelContext() { 33 print(SendableClassA.staticField); 34 } 35 36 testOneLevelContext() { 37 let x: number = 0; 38 (()=>{ 39 print(SendableClassA.staticField); 40 print("closureVariable x = " + x); 41 })(); 42 } 43 44 testTwoLevelContext() { 45 let y: number = 0; 46 class InnerClass { 47 static innerStaticField: string = "innerStaticField"; 48 innerFunc() { 49 let x: number = 0; 50 (()=>{ 51 print(SendableClassA.staticField); 52 print("closureVariable y = " + y); 53 print("closureVariable x = " + x); 54 print("innerStaticField = " + InnerClass.innerStaticField); 55 })(); 56 } 57 } 58 let innerObj = new InnerClass; 59 innerObj.innerFunc(); 60 } 61} 62 63let sObj = new SendableClassA; 64sObj.testZeroLevelContext(); 65sObj.testOneLevelContext(); 66sObj.testTwoLevelContext(); 67 68class SendableClassB extends SendableClassA { 69 x:number = 5; 70 constructor() { 71 "use sendable"; 72 super(); 73 } 74 75 testZeroLevelContext() { 76 print(SendableClassB.staticField); 77 } 78} 79 80let sObjb = new SendableClassB; 81sObjb.testZeroLevelContext() 82