• 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 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 
37     ACCESSORS(Object, OBJECT_OFFSET, CACHED_HCLASS_OFFSET)
38     ACCESSORS(CachedHClass, CACHED_HCLASS_OFFSET, KEYS_OFFSET)
39     ACCESSORS(Keys, KEYS_OFFSET, CACHE_KIND_OFFSET)
40     ACCESSORS_PRIMITIVE_FIELD(CacheKind, uint32_t, CACHE_KIND_OFFSET, INDEX_OFFSET)
41     ACCESSORS_PRIMITIVE_FIELD(Index, uint32_t, INDEX_OFFSET, LENGTH_OFFSET)
42     ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, LAST_OFFSET)
43     DEFINE_ALIGN_SIZE(LAST_OFFSET);
44 
45     DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, OBJECT_OFFSET, CACHE_KIND_OFFSET)
46     DECL_DUMP()
47 
48 private:
49     static bool IsEnumCacheValid(const JSThread *thread, JSTaggedValue receiver, JSTaggedValue cachedHClass,
50                                  EnumCacheKind kind);
51     static bool NeedCheckProperty(const JSThread *thread, JSTaggedValue receiver);
52     static bool HasProperty(JSThread *thread, JSHandle<JSTaggedValue> receiver, JSHandle<JSTaggedValue> key);
53 };
54 }  // namespace panda::ecmascript
55 
56 #endif  // ECMASCRIPT_JS_FORIN_ITERATOR_H
57