v8/
property_descriptor.rs1use std::mem::MaybeUninit;
2use std::mem::size_of;
3
4use crate::Local;
5use crate::Value;
6
7unsafe extern "C" {
8 fn v8__PropertyDescriptor__CONSTRUCT(out: *mut PropertyDescriptor);
9 fn v8__PropertyDescriptor__CONSTRUCT__Value(
10 this: *const PropertyDescriptor,
11 value: *const Value,
12 );
13 fn v8__PropertyDescriptor__CONSTRUCT__Value_Writable(
14 this: *const PropertyDescriptor,
15 value: *const Value,
16 writable: bool,
17 );
18 fn v8__PropertyDescriptor__CONSTRUCT__Get_Set(
19 this: *const PropertyDescriptor,
20 get: *const Value,
21 set: *const Value,
22 );
23 fn v8__PropertyDescriptor__DESTRUCT(this: *mut PropertyDescriptor);
24 fn v8__PropertyDescriptor__configurable(
25 this: *const PropertyDescriptor,
26 ) -> bool;
27 fn v8__PropertyDescriptor__enumerable(
28 this: *const PropertyDescriptor,
29 ) -> bool;
30 fn v8__PropertyDescriptor__writable(this: *const PropertyDescriptor) -> bool;
31 fn v8__PropertyDescriptor__value(
32 this: *const PropertyDescriptor,
33 ) -> *const Value;
34 fn v8__PropertyDescriptor__get(
35 this: *const PropertyDescriptor,
36 ) -> *const Value;
37 fn v8__PropertyDescriptor__set(
38 this: *const PropertyDescriptor,
39 ) -> *const Value;
40 fn v8__PropertyDescriptor__has_configurable(
41 this: *const PropertyDescriptor,
42 ) -> bool;
43 fn v8__PropertyDescriptor__has_enumerable(
44 this: *const PropertyDescriptor,
45 ) -> bool;
46 fn v8__PropertyDescriptor__has_writable(
47 this: *const PropertyDescriptor,
48 ) -> bool;
49 fn v8__PropertyDescriptor__has_value(this: *const PropertyDescriptor)
50 -> bool;
51 fn v8__PropertyDescriptor__has_get(this: *const PropertyDescriptor) -> bool;
52 fn v8__PropertyDescriptor__has_set(this: *const PropertyDescriptor) -> bool;
53 fn v8__PropertyDescriptor__set_enumerable(
54 this: *mut PropertyDescriptor,
55 enumerable: bool,
56 );
57 fn v8__PropertyDescriptor__set_configurable(
58 this: *mut PropertyDescriptor,
59 configurable: bool,
60 );
61}
62
63#[repr(transparent)]
64pub struct PropertyDescriptor([usize; 1]);
65
66const _: () = {
67 assert!(
68 size_of::<PropertyDescriptor>() == size_of::<usize>(),
69 "PropertyDescriptor size is not 1 usize"
70 );
71};
72
73impl Default for PropertyDescriptor {
74 fn default() -> Self {
75 Self::new()
76 }
77}
78
79impl PropertyDescriptor {
80 pub fn new() -> Self {
81 let mut this = MaybeUninit::<Self>::uninit();
82 unsafe {
83 v8__PropertyDescriptor__CONSTRUCT(this.as_mut_ptr());
84 this.assume_init()
85 }
86 }
87
88 pub fn new_from_value(value: Local<Value>) -> Self {
89 let mut this = MaybeUninit::<Self>::uninit();
90 unsafe {
91 v8__PropertyDescriptor__CONSTRUCT__Value(this.as_mut_ptr(), &*value);
92 this.assume_init()
93 }
94 }
95
96 pub fn new_from_value_writable(value: Local<Value>, writable: bool) -> Self {
97 let mut this = MaybeUninit::<Self>::uninit();
98 unsafe {
99 v8__PropertyDescriptor__CONSTRUCT__Value_Writable(
100 this.as_mut_ptr(),
101 &*value,
102 writable,
103 );
104 this.assume_init()
105 }
106 }
107
108 pub fn new_from_get_set(get: Local<Value>, set: Local<Value>) -> Self {
109 let mut this = MaybeUninit::<Self>::uninit();
110 unsafe {
111 v8__PropertyDescriptor__CONSTRUCT__Get_Set(
112 this.as_mut_ptr(),
113 &*get,
114 &*set,
115 );
116 this.assume_init()
117 }
118 }
119
120 pub fn configurable(&self) -> bool {
121 unsafe { v8__PropertyDescriptor__configurable(self) }
122 }
123
124 pub fn enumerable(&self) -> bool {
125 unsafe { v8__PropertyDescriptor__enumerable(self) }
126 }
127
128 pub fn writable(&self) -> bool {
129 unsafe { v8__PropertyDescriptor__writable(self) }
130 }
131
132 pub fn value(&self) -> Local<'_, Value> {
133 unsafe { Local::from_raw(v8__PropertyDescriptor__value(self)) }.unwrap()
134 }
135
136 pub fn get(&self) -> Local<'_, Value> {
137 unsafe { Local::from_raw(v8__PropertyDescriptor__get(self)) }.unwrap()
138 }
139
140 pub fn set(&self) -> Local<'_, Value> {
141 unsafe { Local::from_raw(v8__PropertyDescriptor__set(self)) }.unwrap()
142 }
143
144 pub fn has_configurable(&self) -> bool {
145 unsafe { v8__PropertyDescriptor__has_configurable(self) }
146 }
147
148 pub fn has_enumerable(&self) -> bool {
149 unsafe { v8__PropertyDescriptor__has_enumerable(self) }
150 }
151
152 pub fn has_writable(&self) -> bool {
153 unsafe { v8__PropertyDescriptor__has_writable(self) }
154 }
155
156 pub fn has_value(&self) -> bool {
157 unsafe { v8__PropertyDescriptor__has_value(self) }
158 }
159
160 pub fn has_get(&self) -> bool {
161 unsafe { v8__PropertyDescriptor__has_get(self) }
162 }
163
164 pub fn has_set(&self) -> bool {
165 unsafe { v8__PropertyDescriptor__has_set(self) }
166 }
167
168 pub fn set_enumerable(&mut self, enumerable: bool) {
169 unsafe { v8__PropertyDescriptor__set_enumerable(self, enumerable) }
170 }
171
172 pub fn set_configurable(&mut self, configurable: bool) {
173 unsafe { v8__PropertyDescriptor__set_configurable(self, configurable) }
174 }
175}
176
177impl Drop for PropertyDescriptor {
178 fn drop(&mut self) {
179 unsafe { v8__PropertyDescriptor__DESTRUCT(self) }
180 }
181}