14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_JS_API_JS_API_DEQUE_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_JS_API_JS_API_DEQUE_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include <cstddef> 204514f5e3Sopenharmony_ci#include <cstdint> 214514f5e3Sopenharmony_ci 224514f5e3Sopenharmony_ci#include "ecmascript/ecma_macros.h" 234514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h" 244514f5e3Sopenharmony_ci#include "ecmascript/js_object.h" 254514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h" 264514f5e3Sopenharmony_ci 274514f5e3Sopenharmony_ci#include "libpandabase/macros.h" 284514f5e3Sopenharmony_ci 294514f5e3Sopenharmony_cinamespace panda::ecmascript { 304514f5e3Sopenharmony_ciclass JSThread; 314514f5e3Sopenharmony_ciclass TaggedArray; 324514f5e3Sopenharmony_ciclass TaggedObject; 334514f5e3Sopenharmony_ciclass JSAPIDeque : public JSObject { 344514f5e3Sopenharmony_cipublic: 354514f5e3Sopenharmony_ci static constexpr int DEFAULT_CAPACITY_LENGTH = 8; 364514f5e3Sopenharmony_ci static JSAPIDeque *Cast(TaggedObject *object) 374514f5e3Sopenharmony_ci { 384514f5e3Sopenharmony_ci ASSERT(JSTaggedValue(object).IsJSAPIDeque()); 394514f5e3Sopenharmony_ci return static_cast<JSAPIDeque *>(object); 404514f5e3Sopenharmony_ci } 414514f5e3Sopenharmony_ci 424514f5e3Sopenharmony_ci static void InsertFront(JSThread *thread, const JSHandle<JSAPIDeque> &deque, const JSHandle<JSTaggedValue> &value); 434514f5e3Sopenharmony_ci 444514f5e3Sopenharmony_ci static void InsertEnd(JSThread *thread, const JSHandle<JSAPIDeque> &deque, const JSHandle<JSTaggedValue> &value); 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_ci static JSTaggedValue ForEach(JSThread *thread, const JSHandle<JSAPIDeque> &deque); 474514f5e3Sopenharmony_ci 484514f5e3Sopenharmony_ci static JSTaggedValue GetIteratorObj(JSThread *thread, const JSHandle<JSAPIDeque> &deque); 494514f5e3Sopenharmony_ci 504514f5e3Sopenharmony_ci static JSHandle<TaggedArray> OwnKeys(JSThread *thread, const JSHandle<JSAPIDeque> &deque); 514514f5e3Sopenharmony_ci 524514f5e3Sopenharmony_ci static JSHandle<TaggedArray> OwnEnumKeys(JSThread *thread, const JSHandle<JSAPIDeque> &deque); 534514f5e3Sopenharmony_ci 544514f5e3Sopenharmony_ci static bool GetOwnProperty(JSThread *thread, const JSHandle<JSAPIDeque> &deque, const JSHandle<JSTaggedValue> &key); 554514f5e3Sopenharmony_ci static OperationResult GetProperty(JSThread *thread, const JSHandle<JSAPIDeque> &obj, 564514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key); 574514f5e3Sopenharmony_ci static bool SetProperty(JSThread *thread, const JSHandle<JSAPIDeque> &obj, 584514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &key, 594514f5e3Sopenharmony_ci const JSHandle<JSTaggedValue> &value); 604514f5e3Sopenharmony_ci JSTaggedValue GetFront(); 614514f5e3Sopenharmony_ci 624514f5e3Sopenharmony_ci JSTaggedValue GetTail(); 634514f5e3Sopenharmony_ci 644514f5e3Sopenharmony_ci JSTaggedValue PopFirst(); 654514f5e3Sopenharmony_ci 664514f5e3Sopenharmony_ci JSTaggedValue PopLast(); 674514f5e3Sopenharmony_ci 684514f5e3Sopenharmony_ci JSTaggedValue Get(const uint32_t index); 694514f5e3Sopenharmony_ci 704514f5e3Sopenharmony_ci JSTaggedValue PUBLIC_API Set(JSThread *thread, const uint32_t index, JSTaggedValue value); 714514f5e3Sopenharmony_ci 724514f5e3Sopenharmony_ci uint32_t GetSize() const; 734514f5e3Sopenharmony_ci 744514f5e3Sopenharmony_ci bool Has(JSTaggedValue value) const; 754514f5e3Sopenharmony_ci 764514f5e3Sopenharmony_ci static constexpr size_t FIRST_OFFSET = JSObject::SIZE; 774514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(First, uint32_t, FIRST_OFFSET, LAST_OFFSET) 784514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(Last, uint32_t, LAST_OFFSET, ENDL_OFFSET) 794514f5e3Sopenharmony_ci DEFINE_ALIGN_SIZE(ENDL_OFFSET); 804514f5e3Sopenharmony_ci 814514f5e3Sopenharmony_ci DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ENDL_OFFSET, ENDL_OFFSET) 824514f5e3Sopenharmony_ci DECL_DUMP() 834514f5e3Sopenharmony_ciprivate: 844514f5e3Sopenharmony_ci inline static uint32_t ComputeCapacity(uint32_t oldCapacity) 854514f5e3Sopenharmony_ci { 864514f5e3Sopenharmony_ci uint32_t newCapacity = oldCapacity << 1U; 874514f5e3Sopenharmony_ci return newCapacity > DEFAULT_CAPACITY_LENGTH ? newCapacity : DEFAULT_CAPACITY_LENGTH; 884514f5e3Sopenharmony_ci } 894514f5e3Sopenharmony_ci static JSHandle<TaggedArray> GrowCapacity(JSThread *thread, const JSHandle<JSAPIDeque> &deque, 904514f5e3Sopenharmony_ci uint32_t oldCapacity, uint32_t first, uint32_t last); 914514f5e3Sopenharmony_ci bool IsEmpty(); 924514f5e3Sopenharmony_ci}; 934514f5e3Sopenharmony_ci} // namespace panda::ecmascript 944514f5e3Sopenharmony_ci 954514f5e3Sopenharmony_ci#endif // ECMASCRIPT_JS_API_JS_API_DEQUE_H 96