0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-03-11 06:26:44 -04:00
rusty-v8/src/platform.rs

32 lines
901 B
Rust
Raw Normal View History

use crate::support::Opaque;
use crate::support::UniquePtr;
extern "C" {
fn v8__platform__NewDefaultPlatform() -> *mut Platform;
fn v8__platform__NewSingleThreadedDefaultPlatform() -> *mut Platform;
fn v8__Platform__DELETE(this: *mut Platform);
}
/// Returns a new instance of the default v8::Platform implementation.
pub fn new_default_platform() -> UniquePtr<Platform> {
unsafe { UniquePtr::from_raw(v8__platform__NewDefaultPlatform()) }
}
/// 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())
}
}
#[repr(C)]
#[derive(Debug)]
pub struct Platform(Opaque);
impl Drop for Platform {
fn drop(&mut self) {
unsafe { v8__Platform__DELETE(self) }
}
}