mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-04 10:02:17 +00:00
Added WeakSet add method
This commit is contained in:
parent
846e5aaacc
commit
6b798a3508
@ -634,6 +634,12 @@ extern {
|
|||||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has
|
||||||
#[wasm_bindgen(method)]
|
#[wasm_bindgen(method)]
|
||||||
pub fn has(this: &WeakSet, value: Object) -> bool;
|
pub fn has(this: &WeakSet, value: Object) -> bool;
|
||||||
|
|
||||||
|
/// The add() method appends a new object to the end of a WeakSet object.
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/add
|
||||||
|
#[wasm_bindgen(method)]
|
||||||
|
pub fn add(this: &WeakSet, value: Object) -> WeakSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
// JsString
|
// JsString
|
||||||
|
@ -59,3 +59,38 @@ fn has() {
|
|||||||
"#)
|
"#)
|
||||||
.test()
|
.test()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn add() {
|
||||||
|
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 add_value(this: &js::WeakSet, value: js::Object) -> js::WeakSet {
|
||||||
|
this.add(value)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
let set = new WeakSet();
|
||||||
|
let value = {some: "value"};
|
||||||
|
wasm.add_value(set, value);
|
||||||
|
assert.equal(set.has(value), true);
|
||||||
|
|
||||||
|
assert.throws(() => { wasm.add_value(set, 1) }, TypeError);
|
||||||
|
assert.throws(() => { wasm.add_value(set, true) }, TypeError);
|
||||||
|
assert.throws(() => { wasm.add_value(set, "fail") }, TypeError);
|
||||||
|
assert.throws(() => { wasm.add_value(set, null) }, TypeError);
|
||||||
|
assert.throws(() => { wasm.add_value(set, undefined) }, TypeError);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user