1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use foreign_types::ForeignTypeRef;
use crate::{ffi, value::FALSE, ContextRef, Local, Runtime, RuntimeRef, Value};
pub type ClassId = ffi::JSClassID;
pub type ClassDef = ffi::JSClassDef;
impl Runtime {
pub fn new_class_id() -> ClassId {
let mut class_id = 0;
unsafe { ffi::JS_NewClassID(&mut class_id) }
}
}
impl RuntimeRef {
pub fn new_class(&self, class_id: ClassId, class_def: &ClassDef) -> bool {
unsafe { ffi::JS_NewClass(self.as_ptr(), class_id, class_def as *const _) != FALSE }
}
pub fn is_registered_class(&self, class_id: ClassId) -> bool {
unsafe { ffi::JS_IsRegisteredClass(self.as_ptr(), class_id) != FALSE }
}
}
impl ContextRef {
pub fn set_class_proto<T: Into<ffi::JSValue>>(&self, class_id: ClassId, obj: T) {
unsafe { ffi::JS_SetClassProto(self.as_ptr(), class_id, obj.into()) }
}
pub fn get_class_proto(&self, class_id: ClassId) -> Local<Value> {
self.bind(unsafe { ffi::JS_GetClassProto(self.as_ptr(), class_id) })
}
}