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