1 /*
2 * Copyright (c) 2024 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 #include "ecmascript/compiler/builtins/builtins_proxy_stub_builder.h"
17
18 #include "ecmascript/compiler/new_object_stub_builder.h"
19
20 namespace panda::ecmascript::kungfu {
GenProxyConstructor(GateRef nativeCode,GateRef func,GateRef newTarget)21 void BuiltinsProxyStubBuilder::GenProxyConstructor(GateRef nativeCode, GateRef func, GateRef newTarget)
22 {
23 auto env = GetEnvironment();
24 DEFVARIABLE(res, VariableType::JS_ANY(), Undefined());
25 Label thisCollectionObj(env);
26 Label slowPath(env);
27 Label slowPath1(env);
28 Label exit(env);
29
30 Label handleIsEcma(env);
31 Label targetIsEcma(env);
32 Label newTargetNotUndefined(env);
33 BRANCH(TaggedIsUndefined(newTarget), &slowPath, &newTargetNotUndefined);
34 Bind(&newTargetNotUndefined);
35
36 GateRef target = GetArgFromArgv(IntPtr(0), numArgs_, true);
37 GateRef handler = GetArgFromArgv(IntPtr(1), numArgs_, true);
38
39 BRANCH(IsEcmaObject(target), &targetIsEcma, &slowPath);
40 Bind(&targetIsEcma);
41 BRANCH(IsEcmaObject(handler), &handleIsEcma, &slowPath);
42 Bind(&handleIsEcma);
43 {
44 NewObjectStubBuilder newBuilder(this);
45 newBuilder.SetParameters(glue_, IntPtr(0));
46 res = newBuilder.NewJSProxy(glue_, target, handler);
47 Jump(&exit);
48 }
49 Bind(&slowPath);
50 {
51 GateRef argv = GetArgv();
52 res = CallBuiltinRuntime(glue_, { glue_, nativeCode, func, thisValue_, numArgs_, argv }, true);
53 Jump(&exit);
54 }
55 Bind(&exit);
56 Return(*res);
57 }
58 } // namespace panda::ecmascript::kungfu
59