1/*
2 * Copyright (c) 2022 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 interface ArkTools {
17    isAOTCompiled(args: any): boolean;
18}
19
20declare function print(str:any):string;
21class A{};
22class B{};
23var a = new A();
24var b = new B();
25print(a instanceof A);
26print(b instanceof A);
27print(a instanceof B);
28print(b instanceof B);
29
30class C {}
31
32Object.defineProperty(C, Symbol.hasInstance, {
33  value(instance) {
34    return false;
35  },
36});
37
38class D extends A {}
39
40function test1 () {
41    let a = new A();
42    print(a instanceof A); // true
43}
44test1();
45
46function test2 () {
47    let a = new D();
48    print(a instanceof D); // true
49}
50test2();
51
52function test3 () {
53    let a = new C();
54    print(a instanceof C); // false
55}
56test3();
57
58function test4() {
59    let a = new Array();
60    print(a instanceof Array); // true
61}
62test4();
63
64function test5() {
65    let a = new Array();
66    print(a instanceof A); // false
67}
68test5();
69
70function foo() {};
71function bar() {};
72const proxy = new Proxy(foo, {});
73
74let f = new foo();
75
76print(f instanceof foo); // true
77print(f instanceof proxy); // true
78print(f instanceof bar); // false
79
80print(ArkTools.isAOTCompiled(test1));
81print(ArkTools.isAOTCompiled(test2));
82print(ArkTools.isAOTCompiled(test3));
83print(ArkTools.isAOTCompiled(test4));
84print(ArkTools.isAOTCompiled(test5));
85
86function test6() {
87    const target = new A();
88    const proxy = new Proxy( target, {});
89    print(proxy instanceof A);
90}
91test6();
92print(ArkTools.isAOTCompiled(test6));
93