use typescript_types::TsValue;
use super::header::ObjectHeader;
#[repr(C)]
pub struct GcObject {
pub header: ObjectHeader,
pub value: TsValue,
}
unsafe impl Send for GcObject {}
unsafe impl Sync for GcObject {}
impl GcObject {
pub fn new(value: TsValue, size: usize, type_id: u8) -> Self {
Self { header: ObjectHeader::new(size, type_id), value }
}
pub fn total_size(&self) -> usize {
std::mem::size_of::<ObjectHeader>() + self.header.size
}
pub fn data_size(&self) -> usize {
self.header.size
}
pub fn is_marked(&self) -> bool {
self.header.is_marked()
}
pub fn mark(&mut self) {
self.header.set_mark();
}
pub fn unmark(&mut self) {
self.header.clear_mark();
}
pub fn age(&self) -> u8 {
self.header.get_age()
}
pub fn increment_age(&mut self) {
self.header.increment_age();
}
pub fn is_tenured(&self) -> bool {
self.header.is_tenured()
}
pub fn type_id(&self) -> u8 {
self.header.type_id
}
pub fn ref_count(&self) -> usize {
self.header.ref_count
}
pub fn increment_ref_count(&mut self) {
self.header.increment_ref_count();
}
pub fn decrement_ref_count(&mut self) -> usize {
self.header.decrement_ref_count()
}
}