• 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
16declare function print(str:any):string;
17declare var ArkTools:any;
18
19class A {
20    name:string;
21    value:number;
22    constructor(name:string, value:number) {
23        this.name = name;
24        this.value = value;
25    }
26}
27class B extends A {
28    constructor(name:string, value:number) {
29        super(name, value);
30    }
31}
32
33
34var obj = new B("AOT", 123);
35print(obj.name);
36print(obj.value);
37
38// Inconsistent number of parameters
39class C extends A {
40    constructor(name:string, value:number) {
41        super(name, value, value);
42    }
43}
44
45var obj2 = new C("AOT", 123);
46print(ArkTools.isAOTCompiled(C))
47
48class D extends B {
49    constructor(name:string, value:number) {
50        super(name, value);
51    }
52}
53
54var obj = new D("AOT", 456);
55print(obj.name);
56print(obj.value);
57
58function foo () {
59    ArkTools.clearTypedOpProfiler();
60    B.__proto__ = {}
61    try {
62        new B("AOT", 123);
63    } catch (e) {
64        ArkTools.printTypedOpProfiler("INLINE_SUPER_CTOR_CHECK")
65        print("not constructor");
66    }
67}
68foo();
69
70class E {
71    name:string;
72    value:number;
73    constructor(name:string, value:number) {
74        this.name = name;
75        this.value = value;
76        this.sin = Math.sin(value)
77        return 1
78    }
79}
80class F extends E {
81    constructor(name:string, value:number) {
82        super(name, value);
83    }
84}
85
86function bar() {
87    let obj1 = new F("AOT", 123);
88    Object.defineProperty(Math, 1, {});
89    let obj2= new F("AOT", 123);
90    print(obj2.name)
91    print(obj2.value)
92}
93
94bar();