mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-25 19:11:45 +03:00
feat(js) Implement Number.new
binding.
This commit is contained in:
parent
c16b9a903c
commit
869d99b870
@ -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.
|
||||||
///
|
///
|
||||||
|
@ -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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user