2019-12-20 10:01:45 -05:00
|
|
|
use crate::isolate::Isolate;
|
2020-06-03 01:38:34 -04:00
|
|
|
use crate::HandleScope;
|
2019-12-30 09:28:39 -05:00
|
|
|
use crate::Integer;
|
2019-11-30 10:31:51 -05:00
|
|
|
use crate::Local;
|
2019-12-30 09:28:39 -05:00
|
|
|
use crate::Number;
|
2019-11-30 10:31:51 -05:00
|
|
|
|
|
|
|
extern "C" {
|
2020-04-13 08:43:56 -04:00
|
|
|
fn v8__Number__New(isolate: *mut Isolate, value: f64) -> *const Number;
|
|
|
|
fn v8__Number__Value(this: *const Number) -> f64;
|
|
|
|
fn v8__Integer__New(isolate: *mut Isolate, value: i32) -> *const Integer;
|
2019-11-30 10:31:51 -05:00
|
|
|
fn v8__Integer__NewFromUnsigned(
|
2019-12-20 10:01:45 -05:00
|
|
|
isolate: *mut Isolate,
|
2019-11-30 10:31:51 -05:00
|
|
|
value: u32,
|
2020-04-13 08:43:56 -04:00
|
|
|
) -> *const Integer;
|
2019-12-20 10:01:45 -05:00
|
|
|
fn v8__Integer__Value(this: *const Integer) -> i64;
|
2019-11-30 10:31:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Number {
|
2020-06-03 01:38:34 -04:00
|
|
|
pub fn new<'s>(
|
|
|
|
scope: &mut HandleScope<'s, ()>,
|
2019-12-20 10:01:45 -05:00
|
|
|
value: f64,
|
2020-06-03 01:38:34 -04:00
|
|
|
) -> Local<'s, Number> {
|
|
|
|
unsafe {
|
|
|
|
scope.cast_local(|sd| v8__Number__New(sd.get_isolate_ptr(), value))
|
|
|
|
}
|
|
|
|
.unwrap()
|
2019-11-30 10:31:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn value(&self) -> f64 {
|
|
|
|
unsafe { v8__Number__Value(self) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Integer {
|
2020-06-03 01:38:34 -04:00
|
|
|
pub fn new<'s>(
|
|
|
|
scope: &mut HandleScope<'s, ()>,
|
2019-12-20 10:01:45 -05:00
|
|
|
value: i32,
|
2020-06-03 01:38:34 -04:00
|
|
|
) -> Local<'s, Integer> {
|
2020-05-31 09:00:23 -04:00
|
|
|
unsafe {
|
2020-06-03 01:38:34 -04:00
|
|
|
scope.cast_local(|sd| v8__Integer__New(sd.get_isolate_ptr(), value))
|
2020-05-31 09:00:23 -04:00
|
|
|
}
|
|
|
|
.unwrap()
|
2019-11-30 10:31:51 -05:00
|
|
|
}
|
|
|
|
|
2020-06-03 01:38:34 -04:00
|
|
|
pub fn new_from_unsigned<'s>(
|
|
|
|
scope: &mut HandleScope<'s, ()>,
|
2019-12-20 10:01:45 -05:00
|
|
|
value: u32,
|
2020-06-03 01:38:34 -04:00
|
|
|
) -> Local<'s, Integer> {
|
2020-05-31 09:00:23 -04:00
|
|
|
unsafe {
|
2020-06-03 01:38:34 -04:00
|
|
|
scope.cast_local(|sd| {
|
|
|
|
v8__Integer__NewFromUnsigned(sd.get_isolate_ptr(), value)
|
2020-05-31 09:00:23 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
.unwrap()
|
2019-11-30 10:31:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn value(&self) -> i64 {
|
|
|
|
unsafe { v8__Integer__Value(self) }
|
|
|
|
}
|
|
|
|
}
|