use bitflags::bitflags;
use gc::{unsafe_empty_trace, Finalize, Trace};
#[cfg(test)]
mod tests;
bitflags! {
#[derive(Finalize)]
pub struct Attribute: u8 {
const WRITABLE = 0b0000_0011;
const READONLY = 0b0000_0010;
const HAS_WRITABLE = 0b0000_0010;
const ENUMERABLE = 0b0000_1100;
const NON_ENUMERABLE = 0b0000_1000;
const HAS_ENUMERABLE = 0b0000_1000;
const CONFIGURABLE = 0b0011_0000;
const PERMANENT = 0b0010_0000;
const HAS_CONFIGURABLE = 0b0010_0000;
}
}
unsafe impl Trace for Attribute {
unsafe_empty_trace!();
}
impl Attribute {
#[inline]
pub fn clear(&mut self) {
self.bits = 0;
}
#[inline]
pub fn has_writable(self) -> bool {
self.contains(Self::HAS_WRITABLE)
}
#[inline]
pub fn set_writable(&mut self, value: bool) {
if value {
*self |= Self::WRITABLE;
} else {
*self |= *self & !Self::WRITABLE;
}
}
#[inline]
pub fn writable(self) -> bool {
debug_assert!(self.has_writable());
self.contains(Self::WRITABLE)
}
#[inline]
pub fn has_enumerable(self) -> bool {
self.contains(Self::HAS_ENUMERABLE)
}
#[inline]
pub fn set_enumerable(&mut self, value: bool) {
if value {
*self |= Self::ENUMERABLE;
} else {
*self |= *self & !Self::ENUMERABLE;
}
}
#[inline]
pub fn enumerable(self) -> bool {
debug_assert!(self.has_enumerable());
self.contains(Self::ENUMERABLE)
}
#[inline]
pub fn has_configurable(self) -> bool {
self.contains(Self::HAS_CONFIGURABLE)
}
#[inline]
pub fn set_configurable(&mut self, value: bool) {
if value {
*self |= Self::CONFIGURABLE;
} else {
*self |= *self & !Self::CONFIGURABLE;
}
}
#[inline]
pub fn configurable(self) -> bool {
debug_assert!(self.has_configurable());
self.contains(Self::CONFIGURABLE)
}
}
impl Default for Attribute {
fn default() -> Self {
Self::READONLY | Self::NON_ENUMERABLE | Self::PERMANENT
}
}