• 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 #ifndef ECMASCRIPT_COMPILER_BUILTINS_PROXY_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_PROXY_STUB_BUILDER_H
18 #include "ecmascript/compiler/builtins/builtins_stubs.h"
19 #include "ecmascript/js_proxy.h"
20 
21 namespace panda::ecmascript::kungfu {
22 class BuiltinsProxyStubBuilder : public BuiltinsStubBuilder {
23 public:
BuiltinsProxyStubBuilder(StubBuilder * parent,GateRef globalEnv)24     explicit BuiltinsProxyStubBuilder(StubBuilder *parent, GateRef globalEnv)
25         : BuiltinsStubBuilder(parent, globalEnv) {}
BuiltinsProxyStubBuilder(StubBuilder * parent,GateRef glue,GateRef globalEnv)26     BuiltinsProxyStubBuilder(StubBuilder *parent, GateRef glue, GateRef globalEnv)
27         : BuiltinsStubBuilder(parent, globalEnv), glue_(glue) {}
BuiltinsProxyStubBuilder(BuiltinsStubBuilder * parent,GateRef glue,GateRef thisValue,GateRef numArgs,GateRef globalEnv)28     BuiltinsProxyStubBuilder(BuiltinsStubBuilder* parent, GateRef glue, GateRef thisValue, GateRef numArgs,
29                              GateRef globalEnv)
30         : BuiltinsStubBuilder(parent, globalEnv), glue_(glue), thisValue_(thisValue), numArgs_(numArgs) {}
31     ~BuiltinsProxyStubBuilder() override = default;
32     NO_MOVE_SEMANTIC(BuiltinsProxyStubBuilder);
33     NO_COPY_SEMANTIC(BuiltinsProxyStubBuilder);
GenerateCircuit()34     void GenerateCircuit() override {}
35     void GenProxyConstructor(GateRef nativeCode, GateRef func, GateRef newTarget);
36     GateRef GetProperty(GateRef proxy, GateRef key, GateRef receiver);
37     GateRef SetProperty(GateRef proxy, GateRef key, GateRef value, GateRef receiver, bool mayThrow = true);
38     void CheckGetTrapResult(GateRef target, GateRef key, Variable *result, Label *exit);
39     void CheckSetTrapResult(GateRef target, GateRef key, GateRef value, Variable *result, Label *exit);
40 
SetMethod(GateRef glue,GateRef proxy,GateRef method)41     void SetMethod(GateRef glue, GateRef proxy, GateRef method)
42     {
43         GateRef offset = IntPtr(JSProxy::METHOD_OFFSET);
44         Store(VariableType::JS_ANY(), glue, proxy, offset, method);
45     }
46 
SetTarget(GateRef glue,GateRef proxy,GateRef target)47     void SetTarget(GateRef glue, GateRef proxy, GateRef target)
48     {
49         GateRef offset = IntPtr(JSProxy::TARGET_OFFSET);
50         Store(VariableType::JS_ANY(), glue, proxy, offset, target);
51     }
52 
GetHandler(GateRef glue,GateRef proxy)53     GateRef GetHandler(GateRef glue, GateRef proxy)
54     {
55         GateRef offset = IntPtr(JSProxy::HANDLER_OFFSET);
56         return Load(VariableType::JS_ANY(), glue, proxy, offset);
57     }
58 
SetHandler(GateRef glue,GateRef proxy,GateRef handler)59     void SetHandler(GateRef glue, GateRef proxy, GateRef handler)
60     {
61         GateRef offset = IntPtr(JSProxy::HANDLER_OFFSET);
62         Store(VariableType::JS_ANY(), glue, proxy, offset, handler);
63     }
64 
SetPrivateField(GateRef glue,GateRef proxy,GateRef privateField)65     void SetPrivateField(GateRef glue, GateRef proxy, GateRef privateField)
66     {
67         GateRef offset = IntPtr(JSProxy::PRIVATE_FIELD_OFFSET);
68         Store(VariableType::JS_ANY(), glue, proxy, offset, privateField);
69     }
70 
SetIsRevoked(GateRef glue,GateRef proxy,GateRef value)71     void SetIsRevoked(GateRef glue, GateRef proxy, GateRef value)
72     {
73         GateRef oldValue = ZExtInt1ToInt32(value);
74         GateRef offset = IntPtr(JSProxy::BIT_FIELD_OFFSET);
75         GateRef bitfield = LoadPrimitive(VariableType::INT32(), proxy, offset);
76         GateRef mask = Int32LSL(
77             Int32((1LU << JSProxy::IsRevokedBits::SIZE) - 1),
78             Int32(JSProxy::IsRevokedBits::START_BIT));
79         GateRef newVal = Int32Or(Int32And(bitfield, Int32Not(mask)),
80             Int32LSL(oldValue, Int32(JSProxy::IsRevokedBits::START_BIT)));
81         Store(VariableType::INT32(), glue, proxy, offset, newVal);
82     }
83 
84 private:
85     GateRef glue_ { Circuit::NullGate() };
86     GateRef thisValue_ { Circuit::NullGate() };
87     GateRef numArgs_ { Circuit::NullGate() };
88 };
89 }  // namespace panda::ecmascript::kungfu
90 #endif  // ECMASCRIPT_COMPILER_BUILTINS_PROXY_STUB_BUILDER_H
91