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_HASHSET_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_HASHSET_STUB_BUILDER_H
18 #include "ecmascript/compiler/builtins/builtins_stubs.h"
19 #include "ecmascript/js_api/js_api_hashset.h"
20 #include "ecmascript/tagged_node.h"
21
22 namespace panda::ecmascript::kungfu {
23 class ContainersHashSetStubBuilder : public BuiltinsStubBuilder {
24 public:
ContainersHashSetStubBuilder(StubBuilder * parent)25 explicit ContainersHashSetStubBuilder(StubBuilder *parent)
26 : BuiltinsStubBuilder(parent) {}
27 ~ContainersHashSetStubBuilder() override = default;
28 NO_MOVE_SEMANTIC(ContainersHashSetStubBuilder);
29 NO_COPY_SEMANTIC(ContainersHashSetStubBuilder);
GenerateCircuit()30 void GenerateCircuit() override {}
31
32 #define DECLARE_CONTAINERS_HASHSET_STUB_BUILDER(method, ...) \
33 void method(GateRef glue, GateRef thisValue, GateRef numArgs, Variable *result, Label *exit, Label *slowPath);
BUILTINS_WITH_CONTAINERS_HASHSET_STUB_BUILDER(DECLARE_CONTAINERS_HASHSET_STUB_BUILDER)34 BUILTINS_WITH_CONTAINERS_HASHSET_STUB_BUILDER(DECLARE_CONTAINERS_HASHSET_STUB_BUILDER)
35 #undef DECLARE_CONTAINERS_HASHSET_STUB_BUILDER
36
37 GateRef GetTableLength(GateRef obj)
38 {
39 GateRef tableOffset = IntPtr(JSAPIHashSet::HASHSET_TABLE_INDEX);
40 GateRef table = Load(VariableType::JS_POINTER(), obj, tableOffset);
41 return GetLengthOfTaggedArray(table);
42 }
43
GetNode(GateRef obj,GateRef index)44 GateRef GetNode(GateRef obj, GateRef index)
45 {
46 GateRef tableOffset = IntPtr(JSAPIHashSet::HASHSET_TABLE_INDEX);
47 GateRef table = Load(VariableType::JS_POINTER(), obj, tableOffset);
48 return GetValueFromTaggedArray(table, index);
49 }
50 };
51 } // namespace panda::ecmascript::kungfu
52 #endif // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_HASHSET_STUB_BUILDER_H
53