• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_ENUM_CONVERSION_H
17 #define ECMASCRIPT_ENUM_CONVERSION_H
18 
19 #include <optional>
20 #include "ecmascript/global_env_fields.h"
21 #include "ecmascript/ts_types/builtin_type_id.h"
22 
23 namespace panda::ecmascript {
ToGlobelEnvPrototypeField(BuiltinTypeId type)24 inline constexpr std::optional<GlobalEnvField> ToGlobelEnvPrototypeField(BuiltinTypeId type)
25 {
26     // case BuiltinTypeId::INT8_ARRAY ...
27     if (IsTypedArrayType(type)) {
28         return GlobalEnvField::TYPED_ARRAY_PROTOTYPE_INDEX;
29     }
30     switch (type) {
31         case BuiltinTypeId::ARRAY:
32             return GlobalEnvField::ARRAY_PROTOTYPE_INDEX;
33         case BuiltinTypeId::DATA_VIEW:
34             return GlobalEnvField::DATA_VIEW_PROTOTYPE_INDEX;
35         case BuiltinTypeId::DATE:
36             return GlobalEnvField::DATE_PROTOTYPE_INDEX;
37         case BuiltinTypeId::FUNCTION:
38             return GlobalEnvField::FUNCTION_PROTOTYPE_INDEX;
39         case BuiltinTypeId::GENERATOR_FUNCTION:
40             return GlobalEnvField::GENERATOR_FUNCTION_PROTOTYPE_OFFSET;
41         case BuiltinTypeId::MAP:
42             return GlobalEnvField::MAP_PROTOTYPE_INDEX;
43         case BuiltinTypeId::OBJECT:
44             return GlobalEnvField::OBJECT_FUNCTION_PROTOTYPE_INDEX;
45         case BuiltinTypeId::SET:
46             return GlobalEnvField::SET_PROTOTYPE_INDEX;
47         case BuiltinTypeId::STRING:
48             return GlobalEnvField::STRING_PROTOTYPE_INDEX;
49         default: // No corresponding entry in either BuiltinTypeId or GlobalEnvField
50             return std::nullopt;
51     }
52 }
53 } // namespace panda::ecmascript
54 #endif // ECMASCRIPT_ENUM_CONVERSION_H
55