v8/
property_handler_flags.rs1#[repr(C)]
4#[derive(Debug, Eq, PartialEq)]
5pub struct PropertyHandlerFlags(u32);
6
7impl PropertyHandlerFlags {
8 pub const NONE: Self = Self(0);
10
11 pub const NON_MASKING: Self = Self(1 << 0);
15
16 pub const ONLY_INTERCEPT_STRINGS: Self = Self(1 << 1);
19
20 pub const HAS_NO_SIDE_EFFECT: Self = Self(1 << 2);
22
23 #[inline(always)]
25 pub fn is_none(&self) -> bool {
26 *self == Self::NONE
27 }
28
29 #[inline(always)]
31 pub fn is_non_masking(&self) -> bool {
32 self.has(Self::NON_MASKING)
33 }
34
35 #[inline(always)]
37 pub fn is_only_intercept_strings(&self) -> bool {
38 self.has(Self::ONLY_INTERCEPT_STRINGS)
39 }
40
41 #[inline(always)]
43 pub fn is_has_no_side_effect(&self) -> bool {
44 self.has(Self::HAS_NO_SIDE_EFFECT)
45 }
46
47 #[inline(always)]
48 fn has(&self, that: Self) -> bool {
49 let Self(lhs) = self;
50 let Self(rhs) = that;
51 0 != lhs & rhs
52 }
53}
54
55impl Default for PropertyHandlerFlags {
57 fn default() -> Self {
58 Self::NONE
59 }
60}
61
62impl std::ops::BitOr for PropertyHandlerFlags {
63 type Output = Self;
64
65 fn bitor(self, Self(rhs): Self) -> Self {
66 let Self(lhs) = self;
67 Self(lhs | rhs)
68 }
69}
70
71#[test]
72fn test_attr() {
73 assert!(PropertyHandlerFlags::NONE.is_none());
74 assert!(!PropertyHandlerFlags::NONE.is_non_masking());
75 assert!(!PropertyHandlerFlags::NONE.is_only_intercept_strings());
76 assert!(!PropertyHandlerFlags::NONE.is_has_no_side_effect());
77
78 assert!(!PropertyHandlerFlags::NON_MASKING.is_none());
79 assert!(PropertyHandlerFlags::NON_MASKING.is_non_masking());
80 assert!(!PropertyHandlerFlags::NON_MASKING.is_only_intercept_strings());
81 assert!(!PropertyHandlerFlags::NON_MASKING.is_has_no_side_effect());
82
83 assert!(!PropertyHandlerFlags::ONLY_INTERCEPT_STRINGS.is_none());
84 assert!(!PropertyHandlerFlags::ONLY_INTERCEPT_STRINGS.is_non_masking());
85 assert!(
86 PropertyHandlerFlags::ONLY_INTERCEPT_STRINGS.is_only_intercept_strings()
87 );
88 assert!(
89 !PropertyHandlerFlags::ONLY_INTERCEPT_STRINGS.is_has_no_side_effect()
90 );
91
92 assert!(!PropertyHandlerFlags::HAS_NO_SIDE_EFFECT.is_none());
93 assert!(!PropertyHandlerFlags::HAS_NO_SIDE_EFFECT.is_non_masking());
94 assert!(
95 !PropertyHandlerFlags::HAS_NO_SIDE_EFFECT.is_only_intercept_strings()
96 );
97 assert!(PropertyHandlerFlags::HAS_NO_SIDE_EFFECT.is_has_no_side_effect());
98
99 assert_eq!(PropertyHandlerFlags::NONE, Default::default());
100
101 let attr = PropertyHandlerFlags::ONLY_INTERCEPT_STRINGS
102 | PropertyHandlerFlags::HAS_NO_SIDE_EFFECT
103 | PropertyHandlerFlags::NON_MASKING;
104 assert!(!attr.is_none());
105 assert!(attr.is_non_masking());
106 assert!(attr.is_only_intercept_strings());
107 assert!(attr.is_has_no_side_effect());
108}