feat(js) Implement Number.new binding.

This commit is contained in:
Ivan Enderlin 2018-06-27 09:36:37 +02:00
parent c16b9a903c
commit 869d99b870
No known key found for this signature in database
GPG Key ID: 461F31FCE31F4AAD
2 changed files with 34 additions and 0 deletions

View File

@ -367,6 +367,14 @@ extern {
extern { extern {
pub type Number; pub type Number;
/// The `Number` JavaScript object is a wrapper object allowing
/// you to work with numerical values. A `Number` object is
/// created using the `Number()` constructor.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number
#[wasm_bindgen(constructor)]
pub fn new(value: JsValue) -> Number;
/// The toLocaleString() method returns a string with a language sensitive /// The toLocaleString() method returns a string with a language sensitive
/// representation of this number. /// representation of this number.
/// ///

View File

@ -2,6 +2,32 @@
use super::project; use super::project;
#[test]
fn new() {
project()
.file("src/lib.rs", r#"
#![feature(proc_macro, wasm_custom_section)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
use wasm_bindgen::js::Number;
#[wasm_bindgen]
pub fn new_number() -> Number {
Number::new(JsValue::from(42))
}
"#)
.file("test.ts", r#"
import * as assert from "assert";
import * as wasm from "./out";
export function test() {
assert.equal(typeof wasm.new_number(), "object");
assert.equal(wasm.new_number(), 42);
}
"#)
.test()
}
#[test] #[test]
fn to_locale_string() { fn to_locale_string() {