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 GetAllEnumKeys(JSThread *thread, const JSHandle<JSForInIterator> &it, 37 const JSHandle<JSTaggedValue> &object); 38 39 static constexpr size_t OBJECT_OFFSET = JSObject::SIZE; 40 ACCESSORS(Object, OBJECT_OFFSET, VISITED_KEYS_OFFSET) 41 ACCESSORS(VisitedObjs, VISITED_KEYS_OFFSET, REMAINING_KEYS_OFFSET) 42 ACCESSORS(RemainingKeys, REMAINING_KEYS_OFFSET, BIT_FIELD_OFFSET) 43 ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) 44 DEFINE_ALIGN_SIZE(LAST_OFFSET); 45 46 // define BitField 47 static constexpr size_t WAS_VISITED_BITS = 3; 48 FIRST_BIT_FIELD(BitField, WasVisited, bool, WAS_VISITED_BITS) 49 NEXT_BIT_FIELD(BitField, HasVisitObjs, bool, 1, WasVisited) 50 51 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, OBJECT_OFFSET, BIT_FIELD_OFFSET) 52 DECL_DUMP() 53 }; 54 } // namespace panda::ecmascript 55 56 #endif // ECMASCRIPT_JS_FORIN_ITERATOR_H 57