0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-16 02:48:59 -05:00
denoland-rusty-v8/src/number.rs

53 lines
1.3 KiB
Rust
Raw Normal View History

2019-12-20 10:01:45 -05:00
use crate::isolate::Isolate;
2019-12-30 09:28:39 -05:00
use crate::Integer;
use crate::Local;
2019-12-30 09:28:39 -05:00
use crate::Number;
use crate::ToLocal;
extern "C" {
2019-12-20 10:01:45 -05:00
fn v8__Number__New(isolate: *mut Isolate, value: f64) -> *mut Number;
fn v8__Number__Value(this: &Number) -> f64;
2019-12-20 10:01:45 -05:00
fn v8__Integer__New(isolate: *mut Isolate, value: i32) -> *mut Integer;
fn v8__Integer__NewFromUnsigned(
2019-12-20 10:01:45 -05:00
isolate: *mut Isolate,
value: u32,
2019-12-04 08:12:27 -05:00
) -> *mut Integer;
2019-12-20 10:01:45 -05:00
fn v8__Integer__Value(this: *const Integer) -> i64;
}
impl Number {
2019-12-20 10:01:45 -05:00
pub fn new<'sc>(
scope: &mut impl ToLocal<'sc>,
2019-12-20 10:01:45 -05:00
value: f64,
) -> Local<'sc, Number> {
let local = unsafe { v8__Number__New(scope.isolate(), value) };
unsafe { scope.to_local(local) }.unwrap()
}
pub fn value(&self) -> f64 {
unsafe { v8__Number__Value(self) }
}
}
impl Integer {
2019-12-20 10:01:45 -05:00
pub fn new<'sc>(
scope: &mut impl ToLocal<'sc>,
2019-12-20 10:01:45 -05:00
value: i32,
) -> Local<'sc, Integer> {
let local = unsafe { v8__Integer__New(scope.isolate(), value) };
unsafe { scope.to_local(local) }.unwrap()
}
2019-12-20 10:01:45 -05:00
pub fn new_from_unsigned<'sc>(
scope: &mut impl ToLocal<'sc>,
2019-12-20 10:01:45 -05:00
value: u32,
) -> Local<'sc, Integer> {
let local = unsafe { v8__Integer__NewFromUnsigned(scope.isolate(), value) };
unsafe { scope.to_local(local) }.unwrap()
}
pub fn value(&self) -> i64 {
unsafe { v8__Integer__Value(self) }
}
}