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 16// @ts-nocheck 17declare function print(str:any):string; 18declare var ArkTools:any; 19function sum(a:number, b:number):number { 20 return a + b; 21} 22 23const handler = { 24 apply: function(target:any, thisArg:any, argumentsList:any[]) { 25 print(`Calculate sum: ${argumentsList}`); 26 // expected output: "Calculate sum: 1,2" 27 return target(argumentsList[0], argumentsList[1]) * 10; 28 } 29}; 30 31print(sum(1, 2)); 32// call proxy-forward-AOT 33const proxy0 = new Proxy(sum, handler); 34print(proxy0(1, 2)); 35 36// call proxy-forward-asm 37ArkTools.removeAOTFlag(handler.apply); 38const proxy1 = new Proxy(sum, handler); 39print(proxy1(1, 2)); 40 41// call proxy-no-forward-AOT 42const proxy2 = new Proxy(sum, {}); 43print(proxy2(1, 2)); 44 45// call proxy-no-forward-AOT 46const proxy3 = new Proxy(sum, {}); 47print(proxy3(1, 2, 3)); 48 49// call proxy-no-forward-bound-AOT 50const proxy4 = new Proxy(sum.bind({}, 3), {}); 51print(proxy4(1, 2)); 52 53// call proxy-no-forward-native-AOT 54const proxy5 = new Proxy(print, {}); 55print(proxy5(1, 2)); 56 57// call proxy-no-forward-asm 58ArkTools.removeAOTFlag(sum); 59const proxy6 = new Proxy(sum, {}); 60print(proxy6(1, 2));