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