mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-24 18:43:33 +03:00
Add support Symbol.hasInstance as sample of static prop getter
This commit is contained in:
parent
e6b2a0d98c
commit
2518048f25
14
src/js.rs
14
src/js.rs
@ -1388,3 +1388,17 @@ if_std! {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Symbol
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
pub type Symbol;
|
||||
|
||||
/// The Symbol.hasInstance well-known symbol is used to determine
|
||||
/// if a constructor object recognizes an object as its instance.
|
||||
/// The instanceof operator's behavior can be customized by this symbol.
|
||||
///
|
||||
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/hasInstance
|
||||
#[wasm_bindgen(static_method_of = Symbol, getter, structural, js_name = hasInstance)]
|
||||
pub fn has_instance() -> Symbol;
|
||||
}
|
||||
|
37
tests/all/js_globals/Symbol.rs
Normal file
37
tests/all/js_globals/Symbol.rs
Normal file
@ -0,0 +1,37 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use project;
|
||||
|
||||
#[test]
|
||||
fn has_instance() {
|
||||
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 symbol_has_instance() -> js::Symbol {
|
||||
js::Symbol::has_instance()
|
||||
}
|
||||
|
||||
"#,
|
||||
)
|
||||
.file(
|
||||
"test.ts",
|
||||
r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
assert.ok(wasm.symbol_has_instance());
|
||||
assert.ok([] instanceof Array);
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.test()
|
||||
}
|
@ -19,6 +19,7 @@ mod Object;
|
||||
mod Proxy;
|
||||
mod Set;
|
||||
mod SetIterator;
|
||||
mod Symbol;
|
||||
mod TypedArray;
|
||||
mod WeakMap;
|
||||
mod WeakSet;
|
||||
|
Loading…
Reference in New Issue
Block a user