mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-24 02:01:35 +00:00
Move the js
module to a js_sys
crate (#512)
* Move the `js` module to a `js_sys` crate * Update js-sys tests to pass again * Update binding_to_unimplemented_apis_doesnt_break_everything Remove its dependency on the `js` module * Update metadata for js-sys * Fix the `closures` example
This commit is contained in:
76
crates/js-sys/tests/all/Proxy.rs
Normal file
76
crates/js-sys/tests/all/Proxy.rs
Normal file
@ -0,0 +1,76 @@
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use project;
|
||||
|
||||
#[test]
|
||||
fn new() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn new_proxy(target: JsValue, handler: js_sys::Object) -> js_sys::Proxy {
|
||||
js_sys::Proxy::new(&target, &handler)
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const target = { a: 100 };
|
||||
const handler = {
|
||||
get: function(obj, prop) {
|
||||
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()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn revocable() {
|
||||
project()
|
||||
.file("src/lib.rs", r#"
|
||||
#![feature(use_extern_macros)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
extern crate js_sys;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn new_revocable_proxy(target: JsValue, handler: js_sys::Object) -> js_sys::Object {
|
||||
js_sys::Proxy::revocable(&target, &handler)
|
||||
}
|
||||
"#)
|
||||
.file("test.js", r#"
|
||||
import * as assert from "assert";
|
||||
import * as wasm from "./out";
|
||||
|
||||
export function test() {
|
||||
const target = { a: 100 };
|
||||
const handler = {
|
||||
get: function(obj, prop) {
|
||||
return prop in obj ? obj[prop] : 37;
|
||||
}
|
||||
};
|
||||
const { proxy, revoke } =
|
||||
wasm.new_revocable_proxy(target, handler);
|
||||
assert.equal(proxy.a, 100);
|
||||
assert.equal(proxy.b, 37);
|
||||
revoke();
|
||||
assert.throws(() => { proxy.a }, TypeError);
|
||||
assert.throws(() => { proxy.b }, TypeError);
|
||||
assert.equal(typeof proxy, "object");
|
||||
}
|
||||
"#)
|
||||
.test()
|
||||
}
|
Reference in New Issue
Block a user