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 JSTaggedValue NextInternal(JSThread *thread, const JSHandle<JSForInIterator> &it); 31 static JSTaggedValue NextInternalSlowpath(JSThread *thread, const JSHandle<JSForInIterator> &it); 32 33 static JSTaggedValue Next(EcmaRuntimeCallInfo *msg); 34 35 static constexpr size_t OBJECT_OFFSET = JSObject::SIZE; 36 ACCESSORS(Object, OBJECT_OFFSET, CACHED_HCLASS_OFFSET) 37 ACCESSORS(CachedHclass, CACHED_HCLASS_OFFSET, KEYS_OFFSET) 38 ACCESSORS(Keys, KEYS_OFFSET, INDEX_OFFSET) 39 ACCESSORS_PRIMITIVE_FIELD(Index, uint32_t, INDEX_OFFSET, LENGTH_OFFSET) 40 ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, LAST_OFFSET) 41 DEFINE_ALIGN_SIZE(LAST_OFFSET); 42 43 DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, OBJECT_OFFSET, INDEX_OFFSET) 44 DECL_DUMP() 45 46 private: 47 static bool IsEnumCacheValid(JSTaggedValue receiver, JSTaggedValue cachedHclass, EnumCacheKind kind); 48 static bool NeedCheckProperty(JSTaggedValue receiver); 49 static bool HasProperty(JSThread *thread, JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key); 50 }; 51 } // namespace panda::ecmascript 52 53 #endif // ECMASCRIPT_JS_FORIN_ITERATOR_H 54