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)24 explicit BuiltinsProxyStubBuilder(StubBuilder *parent) 25 : BuiltinsStubBuilder(parent) {} BuiltinsProxyStubBuilder(BuiltinsStubBuilder *parent, GateRef glue, GateRef thisValue, GateRef numArgs)26 BuiltinsProxyStubBuilder(BuiltinsStubBuilder *parent, GateRef glue, GateRef thisValue, GateRef numArgs) 27 : BuiltinsStubBuilder(parent), glue_(glue), thisValue_(thisValue), numArgs_(numArgs) {} 28 ~BuiltinsProxyStubBuilder() override = default; 29 NO_MOVE_SEMANTIC(BuiltinsProxyStubBuilder); 30 NO_COPY_SEMANTIC(BuiltinsProxyStubBuilder); 31 void GenerateCircuit() override {} 32 void GenProxyConstructor(GateRef nativeCode, GateRef func, GateRef newTarget); 33 SetMethod(GateRef glue, GateRef proxy, GateRef method)34 void SetMethod(GateRef glue, GateRef proxy, GateRef method) 35 { 36 GateRef offset = IntPtr(JSProxy::METHOD_OFFSET); 37 Store(VariableType::JS_ANY(), glue, proxy, offset, method); 38 } 39 SetTarget(GateRef glue, GateRef proxy, GateRef target)40 void SetTarget(GateRef glue, GateRef proxy, GateRef target) 41 { 42 GateRef offset = IntPtr(JSProxy::TARGET_OFFSET); 43 Store(VariableType::JS_ANY(), glue, proxy, offset, target); 44 } 45 SetHandler(GateRef glue, GateRef proxy, GateRef handler)46 void SetHandler(GateRef glue, GateRef proxy, GateRef handler) 47 { 48 GateRef offset = IntPtr(JSProxy::HANDLER_OFFSET); 49 Store(VariableType::JS_ANY(), glue, proxy, offset, handler); 50 } 51 SetPrivateField(GateRef glue, GateRef proxy, GateRef privateField)52 void SetPrivateField(GateRef glue, GateRef proxy, GateRef privateField) 53 { 54 GateRef offset = IntPtr(JSProxy::PRIVATE_FIELD_OFFSET); 55 Store(VariableType::JS_ANY(), glue, proxy, offset, privateField); 56 } 57 SetIsRevoked(GateRef glue, GateRef proxy, GateRef value)58 void SetIsRevoked(GateRef glue, GateRef proxy, GateRef value) 59 { 60 GateRef oldValue = ZExtInt1ToInt32(value); 61 GateRef offset = IntPtr(JSProxy::BIT_FIELD_OFFSET); 62 GateRef bitfield = Load(VariableType::INT32(), proxy, offset); 63 GateRef mask = Int32LSL( 64 Int32((1LU << JSProxy::IsRevokedBits::SIZE) - 1), 65 Int32(JSProxy::IsRevokedBits::START_BIT)); 66 GateRef newVal = Int32Or(Int32And(bitfield, Int32Not(mask)), 67 Int32LSL(oldValue, Int32(JSProxy::IsRevokedBits::START_BIT))); 68 Store(VariableType::INT32(), glue, proxy, offset, newVal); 69 } 70 71 private: 72 GateRef glue_ { Circuit::NullGate() }; 73 GateRef thisValue_ { Circuit::NullGate() }; 74 GateRef numArgs_ { Circuit::NullGate() }; 75 }; 76 } // namespace panda::ecmascript::kungfu 77 #endif // ECMASCRIPT_COMPILER_BUILTINS_PROXY_STUB_BUILDER_H 78