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_HASHMAP_STUB_BUILDER_H 17 #define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_HASHMAP_STUB_BUILDER_H 18 #include "ecmascript/compiler/stub_builder-inl.h" 19 #include "ecmascript/js_api/js_api_hashmap.h" 20 21 namespace panda::ecmascript::kungfu { 22 class ContainersHashMapStubBuilder : public StubBuilder { 23 public: ContainersHashMapStubBuilder(StubBuilder * parent)24 explicit ContainersHashMapStubBuilder(StubBuilder *parent) 25 : StubBuilder(parent) {} 26 ~ContainersHashMapStubBuilder() override = default; 27 NO_MOVE_SEMANTIC(ContainersHashMapStubBuilder); 28 NO_COPY_SEMANTIC(ContainersHashMapStubBuilder); GenerateCircuit()29 void GenerateCircuit() override {} 30 GetTableLength(GateRef obj)31 GateRef GetTableLength(GateRef obj) 32 { 33 GateRef tableOffset = IntPtr(JSAPIHashMap::HASHMAP_TABLE_INDEX); 34 GateRef table = Load(VariableType::JS_POINTER(), obj, tableOffset); 35 return GetLengthOfTaggedArray(table); 36 } 37 GetNode(GateRef obj,GateRef index)38 GateRef GetNode(GateRef obj, GateRef index) 39 { 40 GateRef tableOffset = IntPtr(JSAPIHashMap::HASHMAP_TABLE_INDEX); 41 GateRef table = Load(VariableType::JS_POINTER(), obj, tableOffset); 42 return GetValueFromTaggedArray(table, index); 43 } 44 }; 45 } // namespace panda::ecmascript::kungfu 46 #endif // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_HASHMAP_STUB_BUILDER_H