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_SENDABLEENV_H
17#define ECMASCRIPT_SENDABLEENV_H
18
19#include "ecmascript/js_object.h"
20#include "ecmascript/tagged_array-inl.h"
21
22namespace panda::ecmascript {
23class SendableEnv : public TaggedArray {
24public:
25    static constexpr uint32_t SENDABLE_PARENT_ENV_INDEX = 0;
26    static constexpr uint32_t SENDABLE_SCOPE_INFO_INDEX = 1;
27    static constexpr uint32_t SENDABLE_RESERVED_ENV_LENGTH = 2;
28
29    static SendableEnv *Cast(TaggedObject *object)
30    {
31        ASSERT(JSTaggedValue(object).IsTaggedArray());
32        return static_cast<SendableEnv *>(object);
33    }
34
35    static size_t ComputeSize(uint32_t numSlots)
36    {
37        return TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), numSlots + SENDABLE_RESERVED_ENV_LENGTH);
38    }
39
40    void SetParentEnv(JSThread *thread, JSTaggedValue value)
41    {
42        Set(thread, SENDABLE_PARENT_ENV_INDEX, value);
43    }
44
45    JSTaggedValue GetParentEnv() const
46    {
47        return Get(SENDABLE_PARENT_ENV_INDEX);
48    }
49
50    JSTaggedValue GetProperties(uint32_t index) const
51    {
52        return Get(index + SENDABLE_RESERVED_ENV_LENGTH);
53    }
54
55    void SetProperties(JSThread *thread, uint32_t index, JSTaggedValue value)
56    {
57        Set(thread, index + SENDABLE_RESERVED_ENV_LENGTH, value);
58    }
59
60    JSTaggedValue GetScopeInfo() const
61    {
62        return Get(SENDABLE_SCOPE_INFO_INDEX);
63    }
64
65    void SetScopeInfo(JSThread *thread, JSTaggedValue value)
66    {
67        Set(thread, SENDABLE_SCOPE_INFO_INDEX, value);
68    }
69
70    DECL_DUMP()
71};
72}  // namespace panda::ecmascript
73#endif  // ECMASCRIPT_SENDABLEENV_H
74