Skip to main content

v8/
date.rs

1// Copyright 2019-2021 the Deno authors. All rights reserved. MIT license.
2
3use crate::Context;
4use crate::Date;
5use crate::Local;
6use crate::scope::PinScope;
7
8unsafe extern "C" {
9  fn v8__Date__New(context: *const Context, value: f64) -> *const Date;
10  fn v8__Date__ValueOf(this: *const Date) -> f64;
11}
12
13/// An instance of the built-in Date constructor (ECMA-262, 15.9).
14impl Date {
15  #[inline(always)]
16  pub fn new<'s>(
17    scope: &PinScope<'s, '_>,
18    value: f64,
19  ) -> Option<Local<'s, Date>> {
20    unsafe {
21      scope.cast_local(|sd| v8__Date__New(sd.get_current_context(), value))
22    }
23  }
24
25  /// A specialization of Value::NumberValue that is more efficient
26  /// because we know the structure of this object.
27  #[inline(always)]
28  pub fn value_of(&self) -> f64 {
29    unsafe { v8__Date__ValueOf(self) }
30  }
31}