• 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_GLOBAL_ENV_CONSTANTS_INL_H
17 #define ECMASCRIPT_GLOBAL_ENV_CONSTANTS_INL_H
18 
19 #include "ecmascript/global_env_constants.h"
20 
21 #include "ecmascript/ecma_macros.h"
22 #include "ecmascript/js_handle.h"
23 
24 namespace panda::ecmascript {
BeginSlot()25 inline const JSTaggedValue *GlobalEnvConstants::BeginSlot() const
26 {
27     return &constants_[static_cast<int>(ConstantIndex::CONSTATNT_BEGIN)];
28 }
29 
EndSlot()30 inline const JSTaggedValue *GlobalEnvConstants::EndSlot() const
31 {
32     return &constants_[static_cast<int>(ConstantIndex::CONSTATNT_END)];
33 }
34 
SetConstant(ConstantIndex index,JSTaggedValue value)35 inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSTaggedValue value)
36 {
37     DASSERT_PRINT(index >= ConstantIndex::CONSTATNT_BEGIN && index < ConstantIndex::CONSTATNT_END,
38                   "Root Index out of bound");
39     constants_[static_cast<int>(index)] = value;
40 }
41 
42 template<typename T>
SetConstant(ConstantIndex index,JSHandle<T> value)43 inline void GlobalEnvConstants::SetConstant(ConstantIndex index, JSHandle<T> value)
44 {
45     DASSERT_PRINT(index >= ConstantIndex::CONSTATNT_BEGIN && index < ConstantIndex::CONSTATNT_END,
46                   "Root Index out of bound");
47     constants_[static_cast<int>(index)] = value.GetTaggedValue();
48 }
49 
GetGlobalConstantAddr(ConstantIndex index)50 inline uintptr_t GlobalEnvConstants::GetGlobalConstantAddr(ConstantIndex index) const
51 {
52     return ToUintPtr(this) + sizeof(JSTaggedValue) * static_cast<uint32_t>(index);
53 }
54 
55 // clang-format off
56 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
57 #define DECL_GET_IMPL(Type, Name, Index, Desc)                               \
58     inline const Type GlobalEnvConstants::Get##Name() const                  \
59     {                                                                        \
60         return constants_[static_cast<int>(ConstantIndex::Index)];           \
61     }                                                                        \
62     inline const JSHandle<Type> GlobalEnvConstants::GetHandled##Name() const \
63     {                                                                        \
64         return JSHandle<Type>(reinterpret_cast<uintptr_t>(                   \
65             &constants_[static_cast<int>(ConstantIndex::Index)]));           \
66     }                                                                        \
67     inline size_t GlobalEnvConstants::GetOffsetOf##Name()                    \
68     {                                                                        \
69         return sizeof(JSTaggedValue)                                         \
70             * static_cast<int>(ConstantIndex::Index);                        \
71     }
72 
73     GLOBAL_ENV_CONSTANT_CLASS(DECL_GET_IMPL)  // NOLINT(readability-const-return-type)
74     GLOBAL_ENV_CONSTANT_SPECIAL(DECL_GET_IMPL)  // NOLINT(readability-const-return-type)
75     GLOBAL_ENV_CONSTANT_CONSTANT(DECL_GET_IMPL)  // NOLINT(readability-const-return-type)
76     GLOBAL_ENV_CONSTANT_ACCESSOR(DECL_GET_IMPL)  // NOLINT(readability-const-return-type)
77     GLOBAL_ENV_CACHES(DECL_GET_IMPL)  // NOLINT(readability-const-return-type)
78 #undef DECL_GET_IMPL
79 // clang-format on
80 }  // namespace panda::ecmascript
81 #endif  // ECMASCRIPT_GLOBAL_ENV_CONSTANTS_INL_H
82