2021-03-30 14:33:39 +02:00
|
|
|
use crate::support::Opaque;
|
|
|
|
use crate::support::UniquePtr;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
fn v8__platform__NewDefaultPlatform() -> *mut Platform;
|
2021-04-12 21:40:52 +02:00
|
|
|
fn v8__platform__NewSingleThreadedDefaultPlatform() -> *mut Platform;
|
2021-03-30 14:33:39 +02:00
|
|
|
fn v8__Platform__DELETE(this: *mut Platform);
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:40:52 +02:00
|
|
|
/// Returns a new instance of the default v8::Platform implementation.
|
2021-03-30 14:33:39 +02:00
|
|
|
pub fn new_default_platform() -> UniquePtr<Platform> {
|
|
|
|
unsafe { UniquePtr::from_raw(v8__platform__NewDefaultPlatform()) }
|
|
|
|
}
|
|
|
|
|
2021-04-12 21:40:52 +02:00
|
|
|
/// The same as new_default_platform() but disables the worker thread pool.
|
|
|
|
/// It must be used with the --single-threaded V8 flag.
|
|
|
|
pub fn new_single_threaded_default_platform() -> UniquePtr<Platform> {
|
|
|
|
unsafe {
|
|
|
|
UniquePtr::from_raw(v8__platform__NewSingleThreadedDefaultPlatform())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 14:33:39 +02:00
|
|
|
#[repr(C)]
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Platform(Opaque);
|
|
|
|
|
|
|
|
impl Drop for Platform {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { v8__Platform__DELETE(self) }
|
|
|
|
}
|
|
|
|
}
|