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
use std::marker::PhantomData;
use std::mem::MaybeUninit;
use crate::isolate::CxxIsolate;
use crate::isolate::Isolate;
use crate::isolate::LockedIsolate;
extern "C" {
fn v8__Locker__CONSTRUCT(
buf: &mut MaybeUninit<Locker>,
isolate: &mut CxxIsolate,
);
fn v8__Locker__DESTRUCT(this: &mut Locker);
}
#[repr(C)]
pub struct Locker<'a> {
has_lock: bool,
top_level: bool,
isolate: &'a mut CxxIsolate,
phantom: PhantomData<&'a Isolate>,
}
impl<'a> Locker<'a> {
pub fn new(isolate: &mut CxxIsolate) -> Self {
let mut buf = MaybeUninit::<Self>::uninit();
unsafe {
v8__Locker__CONSTRUCT(&mut buf, isolate);
buf.assume_init()
}
}
}
impl<'a> Drop for Locker<'a> {
fn drop(&mut self) {
unsafe { v8__Locker__DESTRUCT(self) }
}
}
impl<'a> LockedIsolate for Locker<'a> {
fn cxx_isolate(&mut self) -> &mut CxxIsolate {
self.isolate
}
}