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