Skip to main content

v8/
primitives.rs

1use crate::Boolean;
2use crate::Local;
3use crate::Primitive;
4use crate::isolate::Isolate;
5use crate::isolate::RealIsolate;
6
7unsafe extern "C" {
8  fn v8__Null(isolate: *mut RealIsolate) -> *const Primitive;
9  fn v8__Undefined(isolate: *mut RealIsolate) -> *const Primitive;
10
11  fn v8__Boolean__New(isolate: *mut RealIsolate, value: bool)
12  -> *const Boolean;
13}
14
15#[inline(always)]
16pub fn null<'s, R>(scope: &R) -> Local<'s, Primitive>
17where
18  R: AsRef<Isolate>,
19{
20  unsafe { Local::from_raw_unchecked(v8__Null(scope.as_ref().as_real_ptr())) }
21}
22
23#[inline(always)]
24pub fn undefined<'s, R>(scope: &R) -> Local<'s, Primitive>
25where
26  R: AsRef<Isolate>,
27{
28  unsafe {
29    Local::from_raw_unchecked(v8__Undefined(scope.as_ref().as_real_ptr()))
30  }
31}
32
33impl Boolean {
34  #[inline(always)]
35  pub fn new<'s, R>(scope: &R, value: bool) -> Local<'s, Boolean>
36  where
37    R: AsRef<Isolate>,
38  {
39    unsafe {
40      Local::from_raw_unchecked(v8__Boolean__New(
41        scope.as_ref().as_real_ptr(),
42        value,
43      ))
44    }
45  }
46}