• 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_LEXICALENV_H
17 #define ECMASCRIPT_LEXICALENV_H
18 
19 #include "ecmascript/js_object.h"
20 
21 namespace panda::ecmascript {
22 struct ScopeInfo {
23     uint32_t slot;
24     CString name;
25 };
26 
27 struct ScopeDebugInfo {
28     std::vector<ScopeInfo> scopeInfo;
29 };
30 
31 class LexicalEnv : public TaggedArray {
32 public:
33     static constexpr uint32_t PARENT_ENV_INDEX = 0;
34     static constexpr uint32_t SCOPE_INFO_INDEX = 1;
35     static constexpr uint32_t RESERVED_ENV_LENGTH = 2;
36 
Cast(ObjectHeader * object)37     static LexicalEnv *Cast(ObjectHeader *object)
38     {
39         ASSERT(JSTaggedValue(object).IsTaggedArray());
40         return static_cast<LexicalEnv *>(object);
41     }
42 
ComputeSize(uint32_t numSlots)43     static size_t ComputeSize(uint32_t numSlots)
44     {
45         return TaggedArray::ComputeSize(JSTaggedValue::TaggedTypeSize(), numSlots + RESERVED_ENV_LENGTH);
46     }
47 
SetParentEnv(JSThread * thread,JSTaggedValue value)48     void SetParentEnv(JSThread *thread, JSTaggedValue value)
49     {
50         Set(thread, PARENT_ENV_INDEX, value);
51     }
52 
GetParentEnv()53     JSTaggedValue GetParentEnv() const
54     {
55         return Get(PARENT_ENV_INDEX);
56     }
57 
GetProperties(uint32_t index)58     JSTaggedValue GetProperties(uint32_t index) const
59     {
60         return Get(index + RESERVED_ENV_LENGTH);
61     }
62 
SetProperties(JSThread * thread,uint32_t index,JSTaggedValue value)63     void SetProperties(JSThread *thread, uint32_t index, JSTaggedValue value)
64     {
65         Set(thread, index + RESERVED_ENV_LENGTH, value);
66     }
67 
GetScopeInfo()68     JSTaggedValue GetScopeInfo() const
69     {
70         return Get(SCOPE_INFO_INDEX);
71     }
72 
SetScopeInfo(JSThread * thread,JSTaggedValue value)73     void SetScopeInfo(JSThread *thread, JSTaggedValue value)
74     {
75         Set(thread, SCOPE_INFO_INDEX, value);
76     }
77 
78     DECL_DUMP()
79 };
80 }  // namespace panda::ecmascript
81 #endif  // ECMASCRIPT_LEXICALENV_H
82