• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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_JS_FORIN_ITERATOR_H
17 #define ECMASCRIPT_JS_FORIN_ITERATOR_H
18 
19 #include <utility>
20 
21 #include "ecmascript/js_object.h"
22 #include "ecmascript/js_tagged_value-inl.h"
23 #include "ecmascript/tagged_array-inl.h"
24 
25 namespace panda::ecmascript {
26 class JSForInIterator : public JSObject {
27 public:
28     CAST_CHECK(JSForInIterator, IsForinIterator);
29 
30     static std::pair<JSTaggedValue, bool> NextInternal(JSThread *thread, const JSHandle<JSForInIterator> &it);
31 
32     static JSTaggedValue Next(EcmaRuntimeCallInfo *msg);
33 
34     static bool CheckObjProto(const JSThread *thread, const JSHandle<JSForInIterator> &it);
35 
36     static void FastGetAllEnumKeys(const JSThread *thread, const JSHandle<JSForInIterator> &it,
37                                    const JSHandle<JSTaggedValue> &object);
38 
39     static void SlowGetAllEnumKeys(JSThread *thread, const JSHandle<JSForInIterator> &it,
40                                    const JSHandle<JSTaggedValue> &object);
41 
42     static constexpr size_t OBJECT_OFFSET = JSObject::SIZE;
43     ACCESSORS(Object, OBJECT_OFFSET, VISITED_KEYS_OFFSET)
44     ACCESSORS(VisitedKeys, VISITED_KEYS_OFFSET, REMAINING_KEYS_OFFSET)
45     ACCESSORS(RemainingKeys, REMAINING_KEYS_OFFSET, BIT_FIELD_OFFSET)
46     ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET)
47     DEFINE_ALIGN_SIZE(LAST_OFFSET);
48 
49     // define BitField
50     static constexpr size_t WAS_VISITED_BITS = 3;
51     FIRST_BIT_FIELD(BitField, WasVisited, bool, WAS_VISITED_BITS)
52 
53     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, OBJECT_OFFSET, BIT_FIELD_OFFSET)
54     DECL_DUMP()
55 };
56 }  // namespace panda::ecmascript
57 
58 #endif  // ECMASCRIPT_JS_FORIN_ITERATOR_H
59