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
pub mod task;

pub use task::{Task, TaskBase, TaskImpl};

use crate::support::Opaque;
use crate::support::UniquePtr;
use crate::Isolate;

extern "C" {
  // TODO: move this to libplatform.rs?
  fn v8__platform__NewDefaultPlatform() -> *mut Platform;

  fn v8__Platform__DELETE(this: *mut Platform);
}

pub fn new_default_platform() -> UniquePtr<Platform> {
  // TODO: support optional arguments.
  unsafe { UniquePtr::from_raw(v8__platform__NewDefaultPlatform()) }
}

#[repr(C)]
pub struct Platform(Opaque);

impl Drop for Platform {
  fn drop(&mut self) {
    unsafe { v8__Platform__DELETE(self) }
  }
}

impl Platform {
  /// Pumps the message loop for the given isolate.
  ///
  /// The caller has to make sure that this is called from the right thread.
  /// Returns true if a task was executed, and false otherwise. Unless requested
  /// through the |behavior| parameter, this call does not block if no task is
  /// pending. The |platform| has to be created using |NewDefaultPlatform|.
  pub fn pump_message_loop(_platform: &Self, _isolate: &Isolate) -> bool {
    todo!()
  }
}