mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-16 10:10:52 +00:00
Add the binding valueOf to number
This commit is contained in:
parent
d79f982a01
commit
a7f8e071fe
16
src/js.rs
16
src/js.rs
@ -208,6 +208,20 @@ extern {
|
||||
pub fn entries(this: &Array) -> ArrayIterator;
|
||||
}
|
||||
|
||||
// Number.
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
pub type Number;
|
||||
|
||||
/// The valueOf() method returns the wrapped primitive value of
|
||||
/// a Number object.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/valueOf
|
||||
#[wasm_bindgen(method, js_name = valueOf)]
|
||||
pub fn value_of(this: &Number) -> Number;
|
||||
|
||||
}
|
||||
|
||||
// Object.
|
||||
#[wasm_bindgen]
|
||||
extern {
|
||||
@ -268,4 +282,4 @@ extern {
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
|
||||
#[wasm_bindgen(method, js_class = "String")]
|
||||
pub fn slice(this: &JsString, start: u32, end: u32) -> JsString;
|
||||
}
|
||||
}
|
||||
|
32
tests/all/js_globals/Number.rs
Normal file
32
tests/all/js_globals/Number.rs
Normal file
@ -0,0 +1,32 @@
|
||||
#![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;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn js_value_of(this: &js::Number) -> js::Number {
|
||||
this.value_of()
|
||||
}
|
||||
"#)
|
||||
.file("test.ts", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
let number = 42;
|
||||
assert.equal(wasm.js_value_of(number), 42);
|
||||
assert.equal(typeof wasm.js_value_of(number), "number");
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
@ -6,6 +6,7 @@ mod Object;
|
||||
mod Array;
|
||||
mod ArrayIterator;
|
||||
mod JsString;
|
||||
mod Number;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "std")]
|
||||
|
Loading…
x
Reference in New Issue
Block a user