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