diff --git a/src/js.rs b/src/js.rs index b7fead95..8db2d1a1 100644 --- a/src/js.rs +++ b/src/js.rs @@ -738,6 +738,12 @@ extern "C" { extern "C" { pub type Number; + /// The Number.isInteger() method determines whether the passed value is an integer. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger + #[wasm_bindgen(static_method_of = Number, js_name = isInteger)] + pub fn is_integer(object: &Object) -> bool; + /// The `Number` JavaScript object is a wrapper object allowing /// you to work with numerical values. A `Number` object is /// created using the `Number()` constructor. @@ -794,6 +800,13 @@ extern "C" { extern "C" { pub type Date; + /// The getDate() method returns the day of the month for the + /// specified date according to local time. + /// + /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/getDate + #[wasm_bindgen(method, js_name = getDate)] + pub fn get_date(this: &Date) -> Number; + /// The getDay() method returns the day of the week for the specified date according to local time, /// where 0 represents Sunday. For the day of the month see getDate(). /// diff --git a/tests/all/js_globals/Date.rs b/tests/all/js_globals/Date.rs index 740044f7..a0c4423a 100644 --- a/tests/all/js_globals/Date.rs +++ b/tests/all/js_globals/Date.rs @@ -2,6 +2,40 @@ use super::project; +#[test] +fn get_date() { + 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, Number}; + + #[wasm_bindgen] + pub fn get_date(this: &Date) -> Number { + this.get_date() + } + "#, + ) + .file( + "test.js", + r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + let date = new Date(1993, 6, 28, 14, 39, 7); + + assert.equal(wasm.get_date(date), 28); + } + "#, + ) + .test() +} + #[test] fn get_day() { project() diff --git a/tests/all/js_globals/Number.rs b/tests/all/js_globals/Number.rs index 4c06fc9e..f7d44dba 100644 --- a/tests/all/js_globals/Number.rs +++ b/tests/all/js_globals/Number.rs @@ -2,6 +2,33 @@ use super::project; +#[test] +fn is_integer() { + project() + .file("src/lib.rs", r#" + #![feature(proc_macro, wasm_custom_section)] + + extern crate wasm_bindgen; + use wasm_bindgen::prelude::*; + use wasm_bindgen::js; + + #[wasm_bindgen] + pub fn is_integer(obj: &js::Object) -> bool { + js::Number::is_integer(&obj) + } + "#) + .file("test.js", r#" + import * as assert from "assert"; + import * as wasm from "./out"; + + export function test() { + assert.ok(wasm.is_integer(123)); + assert.ok(!wasm.is_integer(123.45)); + } + "#) + .test() +} + #[test] fn new() { project()