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