• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_JS_API_JS_API_HASHMAP_ITERATOR_H
17 #define ECMASCRIPT_JS_API_JS_API_HASHMAP_ITERATOR_H
18 
19 #include "ecmascript/js_iterator.h"
20 #include "ecmascript/js_object.h"
21 #include "ecmascript/tagged_hash_array.h"
22 
23 namespace panda::ecmascript {
24 class JSAPIHashMapIterator : public JSObject {
25 public:
Cast(TaggedObject * obj)26     static JSAPIHashMapIterator *Cast(TaggedObject *obj)
27     {
28         ASSERT(JSTaggedValue(obj).IsJSAPIHashMapIterator());
29         return static_cast<JSAPIHashMapIterator *>(obj);
30     }
31     static JSTaggedValue Next(EcmaRuntimeCallInfo *argv);
32     static JSHandle<JSTaggedValue> CreateHashMapIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj,
33                                                          IterationKind kind);
34     static JSHandle<JSTaggedValue> GetCurrentNode(JSThread *thread, JSHandle<JSAPIHashMapIterator> &iter,
35                                                   JSMutableHandle<TaggedQueue> &queue,
36                                                   JSHandle<TaggedHashArray> &tableArr);
37     static JSHandle<JSTaggedValue> FastGetCurrentNode(JSThread *thread,
38                                                       JSHandle<JSAPIHashMapIterator> &iter,
39                                                       JSMutableHandle<TaggedQueue> &queue,
40                                                       JSHandle<TaggedHashArray> &tableArr);
41 
42     static constexpr size_t ITERATED_HASHMAP_OFFSET = JSObject::SIZE;
43     ACCESSORS(IteratedHashMap, ITERATED_HASHMAP_OFFSET, TAGGED_QUEUE_OFFSET);
44     ACCESSORS(TaggedQueue, TAGGED_QUEUE_OFFSET, CURRENT_NODE_RESULT);
45     ACCESSORS(CurrentNodeResult, CURRENT_NODE_RESULT, NEXT_INDEX_OFFSET);
46     ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET)
47     ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
48     DEFINE_ALIGN_SIZE(LAST_OFFSET);
49 
50     // define BitField
51     static constexpr size_t ITERATION_KIND_BITS = 2;
52     FIRST_BIT_FIELD(BitField, IterationKind, IterationKind, ITERATION_KIND_BITS)
53 
54     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_HASHMAP_OFFSET, NEXT_INDEX_OFFSET)
55 
56     DECL_DUMP()
57 };
58 }  // namespace panda::ecmascript
59 #endif  // ECMASCRIPT_JS_API_JS_API_HASHMAP_ITERATOR_H