mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-02 10:21:07 +00:00
Add the binding valueOf to number
This commit is contained in:
parent
d79f982a01
commit
a7f8e071fe
14
src/js.rs
14
src/js.rs
@ -208,6 +208,20 @@ extern {
|
|||||||
pub fn entries(this: &Array) -> ArrayIterator;
|
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.
|
// Object.
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern {
|
||||||
|
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 Array;
|
||||||
mod ArrayIterator;
|
mod ArrayIterator;
|
||||||
mod JsString;
|
mod JsString;
|
||||||
|
mod Number;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user