mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-03-31 01:11:06 +00:00
Js binding for to_string
This commit is contained in:
parent
5eda5504e9
commit
d89c7958eb
@ -85,4 +85,12 @@ extern {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
|
||||||
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
#[wasm_bindgen(method, js_name = hasOwnProperty)]
|
||||||
pub fn has_own_property(this: &Object, property: &str) -> bool;
|
pub fn has_own_property(this: &Object, property: &str) -> bool;
|
||||||
|
|
||||||
|
/// The toString() method returns a string representing the object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
|
||||||
|
#[wasm_bindgen(method, js_name = toString)]
|
||||||
|
pub fn to_string(this: &Object) -> String;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,3 +54,36 @@ fn has_own_property() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn to_string() {
|
||||||
|
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 to_string(obj: &js::Object) -> String {
|
||||||
|
obj.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn test() {
|
||||||
|
let object = js::Object::new();
|
||||||
|
assert_eq!(object.to_string(), "[object Object]");
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
assert.equal(wasm.to_string({ foo: 42 }), "[object Object]");
|
||||||
|
wasm.test();
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user