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