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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::ops::Deref;
use crate::isolate::Isolate;
use crate::support::Opaque;
use crate::Local;
use crate::Value;
#[repr(C)]
pub struct Primitive(Opaque);
#[repr(C)]
pub struct Boolean(Opaque);
#[repr(C)]
pub struct Name(Opaque);
extern "C" {
fn v8__Null(isolate: *mut Isolate) -> *mut Primitive;
fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive;
fn v8__True(isolate: *mut Isolate) -> *mut Boolean;
fn v8__False(isolate: *mut Isolate) -> *mut Boolean;
}
pub fn new_null<'sc>(scope: &mut impl AsMut<Isolate>) -> Local<'sc, Primitive> {
unsafe { Local::from_raw(v8__Null(scope.as_mut())) }.unwrap()
}
pub fn new_undefined<'sc>(
scope: &mut impl AsMut<Isolate>,
) -> Local<'sc, Primitive> {
unsafe { Local::from_raw(v8__Undefined(scope.as_mut())) }.unwrap()
}
pub fn new_true<'sc>(scope: &mut impl AsMut<Isolate>) -> Local<'sc, Boolean> {
unsafe { Local::from_raw(v8__True(scope.as_mut())) }.unwrap()
}
pub fn new_false<'sc>(scope: &mut impl AsMut<Isolate>) -> Local<'sc, Boolean> {
unsafe { Local::from_raw(v8__False(scope.as_mut())) }.unwrap()
}
impl Deref for Primitive {
type Target = Value;
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const _ as *const Value) }
}
}
impl Deref for Boolean {
type Target = Primitive;
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const _ as *const Primitive) }
}
}
impl Deref for Name {
type Target = Primitive;
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const _ as *const Primitive) }
}
}