mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-02 18:31:05 +00:00
Add date value of
This commit is contained in:
parent
947dfbeae0
commit
cd189d53c4
13
src/js.rs
13
src/js.rs
@ -372,6 +372,19 @@ extern {
|
|||||||
pub fn value_of(this: &Number) -> Number;
|
pub fn value_of(this: &Number) -> Number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Date.
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern {
|
||||||
|
pub type Date;
|
||||||
|
|
||||||
|
/// The valueOf() method returns the primitive value of
|
||||||
|
/// a Date object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/valueOf
|
||||||
|
#[wasm_bindgen(method, js_name = valueOf)]
|
||||||
|
pub fn value_of(this: &Date) -> Date;
|
||||||
|
}
|
||||||
|
|
||||||
// Object.
|
// Object.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern {
|
||||||
|
30
tests/all/js_globals/Date.rs
Normal file
30
tests/all/js_globals/Date.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
use super::project;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn value_of() {
|
||||||
|
project()
|
||||||
|
.file("src/lib.rs", r#"
|
||||||
|
#![feature(proc_macro, wasm_custom_section)]
|
||||||
|
|
||||||
|
extern crate wasm_bindgen;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
use wasm_bindgen::js::Date;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn js_value_of(this: &Date) -> Date {
|
||||||
|
this.value_of()
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let date = new Date(Date.UTC(96, 1, 2, 3, 4, 5));
|
||||||
|
assert.equal(wasm.js_value_of(date), 823230245000);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
@ -9,6 +9,7 @@ mod JsFunction;
|
|||||||
mod JsString;
|
mod JsString;
|
||||||
mod Number;
|
mod Number;
|
||||||
mod Math;
|
mod Math;
|
||||||
|
mod Date;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user