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 #ifndef ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_PLAINARRAY_STUB_BUILDER_H 17 #define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_PLAINARRAY_STUB_BUILDER_H 18 #include "ecmascript/compiler/stub_builder-inl.h" 19 #include "ecmascript/js_api/js_api_plain_array.h" 20 21 namespace panda::ecmascript::kungfu { 22 class ContainersPlainArrayStubBuilder : public StubBuilder { 23 public: ContainersPlainArrayStubBuilder(StubBuilder * parent)24 explicit ContainersPlainArrayStubBuilder(StubBuilder *parent) 25 : StubBuilder(parent) {} 26 ~ContainersPlainArrayStubBuilder() override = default; 27 NO_MOVE_SEMANTIC(ContainersPlainArrayStubBuilder); 28 NO_COPY_SEMANTIC(ContainersPlainArrayStubBuilder); GenerateCircuit()29 void GenerateCircuit() override {} GetSize(GateRef obj)30 GateRef GetSize(GateRef obj) 31 { 32 return Load(VariableType::INT32(), obj, IntPtr(JSAPIPlainArray::LENGTH_OFFSET)); 33 } 34 Get(GateRef obj,GateRef index)35 GateRef Get(GateRef obj, GateRef index) 36 { 37 GateRef elementsOffset = IntPtr(JSAPIPlainArray::VALUES_OFFSET); 38 GateRef elements = Load(VariableType::JS_POINTER(), obj, elementsOffset); 39 return GetValueFromTaggedArray(elements, index); 40 } 41 GetKey(GateRef obj,GateRef index)42 GateRef GetKey(GateRef obj, GateRef index) 43 { 44 GateRef elementsOffset = IntPtr(JSAPIPlainArray::KEYS_OFFSET); 45 GateRef elements = Load(VariableType::JS_POINTER(), obj, elementsOffset); 46 return GetValueFromTaggedArray(elements, index); 47 } Set(GateRef glue,GateRef obj,GateRef index,GateRef value)48 void Set(GateRef glue, GateRef obj, GateRef index, GateRef value) 49 { 50 GateRef elementsOffset = IntPtr(JSObject::ELEMENTS_OFFSET); 51 GateRef elements = Load(VariableType::JS_POINTER(), obj, elementsOffset); 52 SetValueToTaggedArray(VariableType::JS_ANY(), glue, elements, index, value); 53 } 54 }; 55 } // namespace panda::ecmascript::kungfu 56 #endif // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_PLAINARRAY_STUB_BUILDER_H