• 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_FILTER_HELPER_H
17 #define ECMASCRIPT_FILTER_HELPER_H
18 
19 #include "ecmascript/object_operator.h"
20 #include "ecmascript/property_attributes.h"
21 
22 #define NATIVE_DEFAULT 0
23 #define NATIVE_WRITABLE 1 << 0
24 #define NATIVE_ENUMERABLE 1 << 1
25 #define NATIVE_CONFIGURABLE 1 << 2
26 #define NATIVE_KEY_SKIP_STRINGS 1 << 3
27 #define NATIVE_KEY_SKIP_SYMBOLS 1 << 4
28 #define NATIVE_KEY_INCLUDE_PROTOTYPES 1 << 5
29 #define NATIVE_KEY_OWN_ONLY 1 << 6
30 #define NATIVE_KEY_KEEP_NUMBERS 1 << 7
31 #define NATIVE_KEY_NUMBERS_TO_STRINGS 1 << 8
32 
33 namespace panda::ecmascript {
34 class PropertyAttributes;
35 class ObjectOperator;
36 
37 class FilterHelper {
38 public:
39     template <typename T>
IgnoreKeyByFilter(T & desc,uint32_t filter)40     static bool IgnoreKeyByFilter(T &desc, uint32_t filter)
41     {
42         if (filter == NATIVE_DEFAULT) {
43             return false;
44         }
45         if ((filter & NATIVE_WRITABLE) && !desc.IsWritable()) {
46             return true;
47         }
48         if ((filter & NATIVE_ENUMERABLE) && !desc.IsEnumerable()) {
49             return true;
50         }
51         if ((filter & NATIVE_CONFIGURABLE) && !desc.IsConfigurable()) {
52             return true;
53         }
54         return false;
55     }
56 };
57 }  // namespace panda::ecmascript
58 
59 #endif  // ECMASCRIPT_GENERATOR_HELPER_H
60