Added WeakSet has method

This commit is contained in:
Dimitrii Nemkov 2018-06-27 13:26:53 +05:00
parent a0dda505d9
commit 846e5aaacc
2 changed files with 38 additions and 0 deletions

View File

@ -628,6 +628,12 @@ extern {
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet /// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet
#[wasm_bindgen(constructor)] #[wasm_bindgen(constructor)]
pub fn new() -> WeakSet; pub fn new() -> WeakSet;
/// The has() method returns a boolean indicating whether an object exists in a WeakSet or not.
///
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet/has
#[wasm_bindgen(method)]
pub fn has(this: &WeakSet, value: Object) -> bool;
} }
// JsString // JsString

View File

@ -27,3 +27,35 @@ fn new() {
"#) "#)
.test() .test()
} }
#[test]
fn has() {
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 has_value(this: &js::WeakSet, value: js::Object) -> bool {
this.has(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"};
set.add(value);
assert.equal(wasm.has_value(set, value), true);
let nonex = {nonexistent: "value"};
assert.equal(wasm.has_value(set, nonex), false);
}
"#)
.test()
}