2019-12-06 09:36:34 -05:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
2019-12-19 19:15:52 -05:00
|
|
|
use crate::isolate::Isolate;
|
2019-12-05 17:03:18 -05:00
|
|
|
use crate::support::Opaque;
|
|
|
|
use crate::Local;
|
2019-12-06 09:36:34 -05:00
|
|
|
use crate::Value;
|
2019-12-05 17:03:18 -05:00
|
|
|
|
|
|
|
/// The superclass of primitive values. See ECMA-262 4.3.2.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Primitive(Opaque);
|
|
|
|
|
|
|
|
/// A primitive boolean value (ECMA-262, 4.3.14). Either the true
|
|
|
|
/// or false value.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Boolean(Opaque);
|
|
|
|
|
2019-12-09 19:14:07 -05:00
|
|
|
/// A superclass for symbols and strings.
|
|
|
|
#[repr(C)]
|
|
|
|
pub struct Name(Opaque);
|
|
|
|
|
2019-12-05 17:03:18 -05:00
|
|
|
extern "C" {
|
2019-12-20 10:01:45 -05:00
|
|
|
fn v8__Null(isolate: *mut Isolate) -> *mut Primitive;
|
2019-12-05 17:03:18 -05:00
|
|
|
|
2019-12-20 10:01:45 -05:00
|
|
|
fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive;
|
2019-12-05 17:03:18 -05:00
|
|
|
|
2019-12-20 10:01:45 -05:00
|
|
|
fn v8__True(isolate: *mut Isolate) -> *mut Boolean;
|
2019-12-05 17:03:18 -05:00
|
|
|
|
2019-12-20 10:01:45 -05:00
|
|
|
fn v8__False(isolate: *mut Isolate) -> *mut Boolean;
|
2019-12-05 17:03:18 -05:00
|
|
|
}
|
|
|
|
|
2019-12-23 18:09:03 -05:00
|
|
|
pub fn new_null<'sc>(scope: &mut impl AsMut<Isolate>) -> Local<'sc, Primitive> {
|
2019-12-20 10:01:45 -05:00
|
|
|
unsafe { Local::from_raw(v8__Null(scope.as_mut())) }.unwrap()
|
2019-12-05 17:03:18 -05:00
|
|
|
}
|
|
|
|
|
2019-12-20 10:01:45 -05:00
|
|
|
pub fn new_undefined<'sc>(
|
2019-12-23 18:09:03 -05:00
|
|
|
scope: &mut impl AsMut<Isolate>,
|
2019-12-20 10:01:45 -05:00
|
|
|
) -> Local<'sc, Primitive> {
|
|
|
|
unsafe { Local::from_raw(v8__Undefined(scope.as_mut())) }.unwrap()
|
2019-12-05 17:03:18 -05:00
|
|
|
}
|
|
|
|
|
2019-12-23 18:09:03 -05:00
|
|
|
pub fn new_true<'sc>(scope: &mut impl AsMut<Isolate>) -> Local<'sc, Boolean> {
|
2019-12-20 10:01:45 -05:00
|
|
|
unsafe { Local::from_raw(v8__True(scope.as_mut())) }.unwrap()
|
2019-12-05 17:03:18 -05:00
|
|
|
}
|
|
|
|
|
2019-12-23 18:09:03 -05:00
|
|
|
pub fn new_false<'sc>(scope: &mut impl AsMut<Isolate>) -> Local<'sc, Boolean> {
|
2019-12-20 10:01:45 -05:00
|
|
|
unsafe { Local::from_raw(v8__False(scope.as_mut())) }.unwrap()
|
2019-12-05 17:03:18 -05:00
|
|
|
}
|
2019-12-06 09:36:34 -05:00
|
|
|
|
|
|
|
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) }
|
|
|
|
}
|
|
|
|
}
|
2019-12-09 19:14:07 -05:00
|
|
|
|
|
|
|
impl Deref for Name {
|
|
|
|
type Target = Primitive;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
unsafe { &*(self as *const _ as *const Primitive) }
|
|
|
|
}
|
|
|
|
}
|