mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-12 07:06:07 +00:00
Merge pull request #373 from rail44/static-property
Add support getter and setter for static props
This commit is contained in:
commit
15b346994d
@ -1817,8 +1817,9 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
if import.structural {
|
if import.structural {
|
||||||
format!(
|
format!(
|
||||||
"function() {{
|
"function() {{
|
||||||
return this.{};
|
return {}.{};
|
||||||
}}",
|
}}",
|
||||||
|
if is_static { &class } else { "this" },
|
||||||
g
|
g
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -1835,8 +1836,9 @@ impl<'a, 'b> SubContext<'a, 'b> {
|
|||||||
if import.structural {
|
if import.structural {
|
||||||
format!(
|
format!(
|
||||||
"function(y) {{
|
"function(y) {{
|
||||||
this.{} = y;
|
{}.{} = y;
|
||||||
}}",
|
}}",
|
||||||
|
if is_static { &class } else { "this" },
|
||||||
s
|
s
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
42
tests/all/js_globals/Symbol.rs
Normal file
42
tests/all/js_globals/Symbol.rs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#![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.js",
|
||||||
|
r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
class Array1 {
|
||||||
|
static [wasm.symbol_has_instance()](instance) {
|
||||||
|
return Array.isArray(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
assert.equal(typeof wasm.symbol_has_instance(), "symbol");
|
||||||
|
assert.ok([] instanceof Array1);
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.test()
|
||||||
|
}
|
@ -19,6 +19,7 @@ mod Object;
|
|||||||
mod Proxy;
|
mod Proxy;
|
||||||
mod Set;
|
mod Set;
|
||||||
mod SetIterator;
|
mod SetIterator;
|
||||||
|
mod Symbol;
|
||||||
mod TypedArray;
|
mod TypedArray;
|
||||||
mod WeakMap;
|
mod WeakMap;
|
||||||
mod WeakSet;
|
mod WeakSet;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user