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_ITERATOR_H 17 #define ECMASCRIPT_JS_ITERATOR_H 18 19 #include "ecmascript/js_tagged_value.h" 20 #include "tagged_array-inl.h" 21 22 namespace panda::ecmascript { 23 enum class IterationKind : uint8_t { 24 KEY = 0, 25 VALUE, 26 KEY_AND_VALUE 27 }; 28 29 class JSIterator final { 30 public: 31 static JSTaggedValue IteratorCloseAndReturn(JSThread *thread, const JSHandle<JSTaggedValue> &iter, 32 const JSHandle<JSTaggedValue> &status); 33 // 7.4.1 34 static JSHandle<JSTaggedValue> GetIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj); 35 36 static JSHandle<JSTaggedValue> GetIterator(JSThread *thread, const JSHandle<JSTaggedValue> &obj, 37 const JSHandle<JSTaggedValue> &method); 38 // 7.4.2 39 static JSHandle<JSObject> IteratorNext(JSThread *thread, const JSHandle<JSTaggedValue> &iter, 40 const JSHandle<JSTaggedValue> &value); 41 42 static JSHandle<JSObject> IteratorNext(JSThread *thread, const JSHandle<JSTaggedValue> &iter); 43 // 7.4.3 44 static bool IteratorComplete(JSThread *thread, const JSHandle<JSTaggedValue> &iterResult); 45 // 7.4.4 46 static JSHandle<JSTaggedValue> IteratorValue(JSThread *thread, const JSHandle<JSTaggedValue> &iterResult); 47 // 7.4.5 48 static JSHandle<JSTaggedValue> IteratorStep(JSThread *thread, const JSHandle<JSTaggedValue> &iter); 49 // 7.4.6 50 static JSHandle<JSTaggedValue> IteratorClose(JSThread *thread, const JSHandle<JSTaggedValue> &iter, 51 const JSHandle<JSTaggedValue> &completion); 52 // 7.4.7 53 static JSHandle<JSObject> CreateIterResultObject(JSThread *thread, const JSHandle<JSTaggedValue> &value, bool done); 54 }; 55 } // namespace panda::ecmascript 56 #endif // ECMASCRIPT_JS_ITERATOR_H 57