2019-11-20 13:34:32 -08:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
use crate::array_buffer::Allocator;
|
|
|
|
use crate::support::Delete;
|
2019-11-15 16:21:34 -08:00
|
|
|
use crate::support::Opaque;
|
2019-11-20 13:34:32 -08:00
|
|
|
use crate::support::UniqueRef;
|
2019-11-15 16:21:34 -08:00
|
|
|
|
|
|
|
extern "C" {
|
2019-11-27 07:14:39 -08:00
|
|
|
fn v8__Isolate__New(params: *mut CreateParams) -> &'static mut CxxIsolate;
|
|
|
|
fn v8__Isolate__Dispose(this: &mut CxxIsolate) -> ();
|
2019-11-20 13:34:32 -08:00
|
|
|
|
|
|
|
fn v8__Isolate__CreateParams__NEW() -> *mut CreateParams;
|
|
|
|
fn v8__Isolate__CreateParams__DELETE(this: &mut CreateParams);
|
|
|
|
fn v8__Isolate__CreateParams__SET__array_buffer_allocator(
|
|
|
|
this: &mut CreateParams,
|
|
|
|
value: *mut Allocator,
|
|
|
|
);
|
2019-11-15 16:21:34 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[repr(C)]
|
2019-11-27 07:14:39 -08:00
|
|
|
pub struct CxxIsolate(Opaque);
|
|
|
|
|
|
|
|
pub trait LockedIsolate {
|
|
|
|
fn cxx_isolate(&mut self) -> &mut CxxIsolate;
|
|
|
|
}
|
2019-11-15 16:21:34 -08:00
|
|
|
|
|
|
|
#[repr(transparent)]
|
2019-11-27 07:14:39 -08:00
|
|
|
pub struct Isolate(&'static mut CxxIsolate);
|
2019-11-15 16:21:34 -08:00
|
|
|
|
|
|
|
impl Isolate {
|
2019-11-20 13:34:32 -08:00
|
|
|
pub fn new(params: UniqueRef<CreateParams>) -> Self {
|
2019-11-15 16:21:34 -08:00
|
|
|
// TODO: support CreateParams.
|
2019-11-30 09:16:25 -08:00
|
|
|
crate::V8::assert_initialized();
|
2019-11-20 13:34:32 -08:00
|
|
|
Self(unsafe { v8__Isolate__New(params.into_raw()) })
|
2019-11-15 16:21:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Isolate {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { v8__Isolate__Dispose(self.0) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for Isolate {
|
2019-11-27 07:14:39 -08:00
|
|
|
type Target = CxxIsolate;
|
|
|
|
fn deref(&self) -> &CxxIsolate {
|
2019-11-15 16:21:34 -08:00
|
|
|
self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 13:34:32 -08:00
|
|
|
#[repr(C)]
|
|
|
|
pub struct CreateParams(Opaque);
|
|
|
|
|
|
|
|
impl CreateParams {
|
|
|
|
pub fn new() -> UniqueRef<CreateParams> {
|
|
|
|
unsafe { UniqueRef::from_raw(v8__Isolate__CreateParams__NEW()) }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn set_array_buffer_allocator(&mut self, value: UniqueRef<Allocator>) {
|
|
|
|
unsafe {
|
|
|
|
v8__Isolate__CreateParams__SET__array_buffer_allocator(
|
|
|
|
self,
|
|
|
|
value.into_raw(),
|
|
|
|
)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Delete for CreateParams {
|
|
|
|
fn delete(&'static mut self) {
|
|
|
|
unsafe { v8__Isolate__CreateParams__DELETE(self) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-27 07:14:39 -08:00
|
|
|
#[cfg(disabled_test)]
|
2019-11-15 16:21:34 -08:00
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use crate::platform::*;
|
2019-11-30 08:47:26 -08:00
|
|
|
use crate::V8::*;
|
2019-11-15 16:21:34 -08:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_isolate() {
|
|
|
|
initialize_platform(new_default_platform());
|
|
|
|
initialize();
|
2019-11-20 13:34:32 -08:00
|
|
|
let mut params = CreateParams::new();
|
|
|
|
params.set_array_buffer_allocator(Allocator::new_default_allocator());
|
|
|
|
Isolate::new(params);
|
2019-11-15 16:21:34 -08:00
|
|
|
}
|
|
|
|
}
|