0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-01 16:51:32 -05:00
denoland-rusty-v8/src/primitives.rs

36 lines
915 B
Rust
Raw Normal View History

use crate::isolate::Isolate;
2019-12-30 09:28:39 -05:00
use crate::Boolean;
use crate::Local;
2019-12-30 09:28:39 -05:00
use crate::Primitive;
use crate::ToLocal;
extern "C" {
2019-12-20 10:01:45 -05:00
fn v8__Null(isolate: *mut Isolate) -> *mut Primitive;
2019-12-20 10:01:45 -05:00
fn v8__Undefined(isolate: *mut Isolate) -> *mut Primitive;
2020-01-04 18:08:27 -05:00
fn v8__Boolean__New(isolate: *mut Isolate, value: bool) -> *mut Boolean;
}
pub fn new_null<'sc>(scope: &mut impl ToLocal<'sc>) -> Local<'sc, Primitive> {
let ptr = unsafe { v8__Null(scope.isolate()) };
unsafe { scope.to_local(ptr) }.unwrap()
}
2019-12-20 10:01:45 -05:00
pub fn new_undefined<'sc>(
scope: &mut impl ToLocal<'sc>,
2019-12-20 10:01:45 -05:00
) -> Local<'sc, Primitive> {
let ptr = unsafe { v8__Undefined(scope.isolate()) };
unsafe { scope.to_local(ptr) }.unwrap()
}
2020-01-04 18:08:27 -05:00
impl Boolean {
pub fn new<'sc>(
scope: &mut impl ToLocal<'sc>,
value: bool,
) -> Local<'sc, Boolean> {
let ptr = unsafe { v8__Boolean__New(scope.isolate(), value) };
unsafe { scope.to_local(ptr) }.unwrap()
}
}