1
0
mirror of https://github.com/fluencelabs/wasm-bindgen synced 2025-06-26 19:21:35 +00:00
Files
.cargo
crates
backend
cli
cli-support
futures
js-sys
src
tests
wasm
Array.rs
ArrayBuffer.rs
ArrayIterator.rs
Boolean.rs
DataView.rs
Date.rs
Error.rs
EvalError.rs
Function.js
Function.rs
Generator.js
Generator.rs
Intl.rs
JSON.rs
JsString.js
JsString.rs
Map.rs
MapIterator.rs
Math.rs
Number.rs
Object.js
Object.rs
Promise.rs
Proxy.js
Proxy.rs
RangeError.rs
ReferenceError.rs
Reflect.js
Reflect.rs
RegExp.rs
Set.rs
SetIterator.rs
Symbol.js
Symbol.rs
SyntaxError.rs
TypeError.rs
TypedArray.rs
UriError.rs
WeakMap.rs
WeakSet.rs
WebAssembly.js
WebAssembly.rs
global_fns.rs
main.rs
headless.js
headless.rs
CHANGELOG.md
Cargo.toml
README.md
macro
macro-support
shared
test
test-macro
typescript
wasm-interpreter
web-sys
webidl
webidl-tests
examples
guide
releases
src
tests
.appveyor.yml
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
build.rs
package.json
publish.rs
wasm-bindgen/crates/js-sys/tests/wasm/Proxy.rs

47 lines
1.4 KiB
Rust
Raw Normal View History

2018-07-20 15:35:15 -07:00
use wasm_bindgen::prelude::*;
use wasm_bindgen_test::*;
use js_sys::*;
#[wasm_bindgen(module = "tests/wasm/Proxy.js")]
2018-07-20 15:35:15 -07:00
extern {
fn proxy_target() -> JsValue;
fn proxy_handler() -> Object;
type Custom;
#[wasm_bindgen(method, getter, structural, catch)]
fn a(this: &Custom) -> Result<u32, JsValue>;
#[wasm_bindgen(method, getter, structural, catch)]
fn b(this: &Custom) -> Result<u32, JsValue>;
type RevocableResult;
#[wasm_bindgen(method, getter, structural)]
fn proxy(this: &RevocableResult) -> JsValue;
#[wasm_bindgen(method, getter, structural)]
fn revoke(this: &RevocableResult) -> Function;
}
#[wasm_bindgen_test]
fn new() {
let proxy = Proxy::new(&proxy_target(), &proxy_handler());
let proxy = Custom::from(JsValue::from(proxy));
assert_eq!(proxy.a().unwrap(), 100);
assert_eq!(proxy.b().unwrap(), 37);
}
#[wasm_bindgen_test]
fn revocable() {
let result = Proxy::revocable(&proxy_target(), &proxy_handler());
let result = RevocableResult::from(JsValue::from(result));
let proxy = result.proxy();
let revoke = result.revoke();
let obj = Custom::from(proxy);
assert_eq!(obj.a().unwrap(), 100);
assert_eq!(obj.b().unwrap(), 37);
revoke.apply(&JsValue::undefined(), &Array::new()).unwrap();
assert!(obj.a().is_err());
assert!(obj.b().is_err());
assert!(JsValue::from(obj).is_object());
}