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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use crate::HandleScope;
use crate::Isolate;
use crate::Local;
use crate::Private;
use crate::String;
use crate::Value;
extern "C" {
fn v8__Private__New(
isolate: *mut Isolate,
name: *const String,
) -> *const Private;
fn v8__Private__ForApi(
isolate: *mut Isolate,
name: *const String,
) -> *const Private;
fn v8__Private__Name(this: *const Private) -> *const Value;
}
impl Private {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s, ()>,
name: Option<Local<String>>,
) -> Local<'s, Private> {
unsafe {
scope.cast_local(|sd| {
v8__Private__New(
sd.get_isolate_ptr(),
name.map_or_else(std::ptr::null, |v| &*v),
)
})
}
.unwrap()
}
#[inline(always)]
pub fn for_api<'s>(
scope: &mut HandleScope<'s, ()>,
name: Option<Local<String>>,
) -> Local<'s, Private> {
unsafe {
scope.cast_local(|sd| {
v8__Private__ForApi(
sd.get_isolate_ptr(),
name.map_or_else(std::ptr::null, |v| &*v),
)
})
}
.unwrap()
}
#[inline(always)]
pub fn name<'s>(&self, scope: &mut HandleScope<'s, ()>) -> Local<'s, Value> {
unsafe { scope.cast_local(|_| v8__Private__Name(&*self)) }.unwrap()
}
}