mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-26 11:34:22 +03:00
Added WeakSet has method
This commit is contained in:
parent
a0dda505d9
commit
846e5aaacc
@ -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
|
||||||
|
@ -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()
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user