1/* 2 * Copyright (c) 2023 - 2024-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 16class C { 17 bar(): string { 18 return "Class C"; 19 } 20} 21 22function foo(c: Object|null|undefined): string { 23 if (c instanceof string) { 24 assertEQ(c.length, 11) 25 c = "Case 1"; 26 } else if (c instanceof C) { 27 assertEQ(c.bar(), "Class C") 28 c = "Case 2"; 29 } else if (c instanceof Int) { 30 assertEQ(c * 7, 49) 31 c = "Case 3"; 32 } else if (c instanceof null) { 33 assertEQ(c, null) 34 c = "Case 4"; 35 } else { 36 c = "Case 5"; 37 } 38 39 assertEQ(c.length, 6) 40 return c; 41} 42 43 44function main(): void { 45 assertEQ(foo("Test string"), "Case 1") 46 assertEQ(foo(new Int(7)), "Case 3") 47 assertEQ(foo(new C()), "Case 2") 48 assertEQ(foo(null), "Case 4") 49 assertEQ(foo(undefined), "Case 5") 50 assertEQ(foo(new Number(3.0)), "Case 5") 51} 52