mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-05-05 18:42:16 +00:00
Bindings for Proxy.new()
Signed-off-by: Stephan Renatus <srenatus@chef.io>
This commit is contained in:
parent
efa4a2b8fa
commit
2b8e789c9c
14
src/js.rs
14
src/js.rs
@ -1030,6 +1030,20 @@ extern "C" {
|
|||||||
pub fn values(object: &Object) -> Array;
|
pub fn values(object: &Object) -> Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Proxy
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern {
|
||||||
|
pub type Proxy;
|
||||||
|
|
||||||
|
/// The Proxy object is used to define custom behavior for fundamental
|
||||||
|
/// operations (e.g. property lookup, assignment, enumeration, function
|
||||||
|
/// invocation, etc).
|
||||||
|
///
|
||||||
|
/// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
|
||||||
|
#[wasm_bindgen(constructor)]
|
||||||
|
pub fn new(target: &JsValue, handler: &Object) -> Proxy;
|
||||||
|
}
|
||||||
|
|
||||||
// Set
|
// Set
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
extern {
|
extern {
|
||||||
|
37
tests/all/js_globals/Proxy.rs
Normal file
37
tests/all/js_globals/Proxy.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#![allow(non_snake_case)]
|
||||||
|
|
||||||
|
use project;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn new() {
|
||||||
|
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 new_proxy(target: JsValue, handler: js::Object) -> js::Proxy {
|
||||||
|
js::Proxy::new(&target, &handler)
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.file("test.ts", r#"
|
||||||
|
import * as assert from "assert";
|
||||||
|
import * as wasm from "./out";
|
||||||
|
|
||||||
|
export function test() {
|
||||||
|
const target = { a: 100 };
|
||||||
|
const handler = {
|
||||||
|
get: function(obj: any, prop: any) {
|
||||||
|
return prop in obj ? obj[prop] : 37;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const proxy = wasm.new_proxy(target, handler);
|
||||||
|
assert.equal(proxy.a, 100);
|
||||||
|
assert.equal(proxy.b, 37);
|
||||||
|
}
|
||||||
|
"#)
|
||||||
|
.test()
|
||||||
|
}
|
@ -16,6 +16,7 @@ mod MapIterator;
|
|||||||
mod Math;
|
mod Math;
|
||||||
mod Number;
|
mod Number;
|
||||||
mod Object;
|
mod Object;
|
||||||
|
mod Proxy;
|
||||||
mod Set;
|
mod Set;
|
||||||
mod SetIterator;
|
mod SetIterator;
|
||||||
mod TypedArray;
|
mod TypedArray;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user