mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-18 07:11:56 +03:00
2b8e789c9c
Signed-off-by: Stephan Renatus <srenatus@chef.io>
38 lines
1.0 KiB
Rust
38 lines
1.0 KiB
Rust
#![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()
|
|
}
|