• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WEAK_VECTOR_INL_H
17 #define ECMASCRIPT_WEAK_VECTOR_INL_H
18 
19 #include "weak_vector.h"
20 #include "tagged_array-inl.h"
21 
22 namespace panda::ecmascript {
GetEnd()23 uint32_t WeakVector::GetEnd() const
24 {
25     return TaggedArray::Get(END_INDEX).GetArrayLength();
26 }
27 
Full()28 bool WeakVector::Full() const
29 {
30     return GetEnd() == GetCapacity();
31 }
32 
Empty()33 bool WeakVector::Empty() const
34 {
35     return GetEnd() == 0;
36 }
37 
GetCapacity()38 uint32_t WeakVector::GetCapacity() const
39 {
40     return TaggedArray::GetLength() - ELEMENTS_START_INDEX;
41 }
42 
Get(uint32_t index)43 JSTaggedValue WeakVector::Get(uint32_t index) const
44 {
45     ASSERT(index < GetCapacity());
46     return TaggedArray::Get(VectorToArrayIndex(index));
47 }
48 
Set(const JSThread * thread,uint32_t index,JSTaggedValue value)49 void WeakVector::Set(const JSThread *thread, uint32_t index, JSTaggedValue value)
50 {
51     ASSERT(index < GetCapacity());
52     TaggedArray::Set(thread, VectorToArrayIndex(index), value);
53 }
54 
SetEnd(const JSThread * thread,uint32_t end)55 void WeakVector::SetEnd(const JSThread *thread, uint32_t end)
56 {
57     ASSERT(end <= GetCapacity());
58     TaggedArray::Set(thread, END_INDEX, JSTaggedValue(end));
59 }
60 }  // namespace panda::ecmascript
61 #endif  // ECMASCRIPT_WEAK_VECTOR_INL_H