0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2024-12-26 09:13:46 -05:00
denoland-rusty-v8/src/date.rs
2022-09-21 08:15:33 +05:30

31 lines
812 B
Rust

// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
use crate::Context;
use crate::Date;
use crate::HandleScope;
use crate::Local;
extern "C" {
fn v8__Date__New(context: *const Context, value: f64) -> *const Date;
fn v8__Date__ValueOf(this: *const Date) -> f64;
}
/// An instance of the built-in Date constructor (ECMA-262, 15.9).
impl Date {
#[inline(always)]
pub fn new<'s>(
scope: &mut HandleScope<'s>,
value: f64,
) -> Option<Local<'s, Date>> {
unsafe {
scope.cast_local(|sd| v8__Date__New(sd.get_current_context(), value))
}
}
/// A specialization of Value::NumberValue that is more efficient
/// because we know the structure of this object.
#[inline(always)]
pub fn value_of(&self) -> f64 {
unsafe { v8__Date__ValueOf(self) }
}
}