Skip to content

Commit 5df8ebf

Browse files
Add test for imported getters and setters (#4270)
1 parent 9eda4ae commit 5df8ebf

File tree

4 files changed

+173
-0
lines changed

4 files changed

+173
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
export function exported(): void;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
let wasm;
2+
export function __wbg_set_wasm(val) {
3+
wasm = val;
4+
}
5+
6+
7+
const heap = new Array(128).fill(undefined);
8+
9+
heap.push(undefined, null, true, false);
10+
11+
function getObject(idx) { return heap[idx]; }
12+
13+
let heap_next = heap.length;
14+
15+
function addHeapObject(obj) {
16+
if (heap_next === heap.length) heap.push(heap.length + 1);
17+
const idx = heap_next;
18+
heap_next = heap[idx];
19+
20+
heap[idx] = obj;
21+
return idx;
22+
}
23+
24+
function dropObject(idx) {
25+
if (idx < 132) return;
26+
heap[idx] = heap_next;
27+
heap_next = idx;
28+
}
29+
30+
function takeObject(idx) {
31+
const ret = getObject(idx);
32+
dropObject(idx);
33+
return ret;
34+
}
35+
36+
export function exported() {
37+
wasm.exported();
38+
}
39+
40+
export function __wbg_another_edf1002f8e41a5da(arg0) {
41+
const ret = getObject(arg0).prop2;
42+
return ret;
43+
};
44+
45+
export function __wbg_b_f17802a22332a667(arg0) {
46+
const ret = getObject(arg0).a;
47+
return ret;
48+
};
49+
50+
export function __wbg_bar2_84566b6bcf547b19() {
51+
const ret = Bar.bar2();
52+
return ret;
53+
};
54+
55+
export function __wbg_getfoo_eae0175044c62418() {
56+
const ret = Bar.get_foo();
57+
return ret;
58+
};
59+
60+
export function __wbg_new_d728785ba7e8df96() {
61+
const ret = new SomeClass();
62+
return addHeapObject(ret);
63+
};
64+
65+
export function __wbg_setanother_2d160a2b6600e990(arg0, arg1) {
66+
getObject(arg0).prop2 = arg1 >>> 0;
67+
};
68+
69+
export function __wbg_setb_40f909ae19a05c10(arg0, arg1) {
70+
getObject(arg0).a = arg1 >>> 0;
71+
};
72+
73+
export function __wbg_setbar2_c8b4a150c6accea2(arg0) {
74+
Bar.set_bar2(arg0 >>> 0);
75+
};
76+
77+
export function __wbg_setfoo_6c6b6af72f779234(arg0) {
78+
Bar.set_foo(arg0 >>> 0);
79+
};
80+
81+
export function __wbg_setsignal_d386d151e7775c3f(arg0, arg1) {
82+
getObject(arg0).signal = arg1 >>> 0;
83+
};
84+
85+
export function __wbg_setsomeprop_afbca63b5d0f4c92(arg0, arg1) {
86+
getObject(arg0).some_prop = arg1 >>> 0;
87+
};
88+
89+
export function __wbg_signal_b82e5486ce265c55(arg0) {
90+
const ret = getObject(arg0).signal;
91+
return ret;
92+
};
93+
94+
export function __wbg_someprop_26178791e2719528(arg0) {
95+
const ret = getObject(arg0).some_prop;
96+
return ret;
97+
};
98+
99+
export function __wbindgen_object_drop_ref(arg0) {
100+
takeObject(arg0);
101+
};
102+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
#[wasm_bindgen]
4+
extern "C" {
5+
#[wasm_bindgen(js_namespace = Bar, getter = bar)]
6+
fn get_foo() -> u32;
7+
#[wasm_bindgen(js_namespace = Bar, setter = bar)]
8+
fn set_foo(value: u32);
9+
#[wasm_bindgen(js_namespace = Bar, getter, js_name = bar2)]
10+
fn get_foo2() -> u32;
11+
#[wasm_bindgen(js_namespace = Bar, setter, js_name = bar2)]
12+
fn set_foo2(value: u32);
13+
14+
#[wasm_bindgen]
15+
#[derive(Debug, Clone, PartialEq)]
16+
pub type SomeClass;
17+
18+
#[wasm_bindgen(method, getter, js_class = "SomeClass", js_name = signal)]
19+
pub fn signal(this: &SomeClass) -> u32;
20+
#[wasm_bindgen(method, setter, js_class = "SomeClass", js_name = signal)]
21+
pub fn set_signal(this: &SomeClass, value: u32);
22+
23+
#[wasm_bindgen(method, getter, js_class = "SomeClass")]
24+
pub fn some_prop(this: &SomeClass) -> u32;
25+
#[wasm_bindgen(method, setter, js_class = "SomeClass")]
26+
pub fn set_some_prop(this: &SomeClass, value: u32);
27+
28+
#[wasm_bindgen(method, getter = prop2, js_class = "SomeClass")]
29+
pub fn another(this: &SomeClass) -> u32;
30+
#[wasm_bindgen(method, setter = prop2, js_class = "SomeClass")]
31+
pub fn set_another(this: &SomeClass, value: u32);
32+
33+
// #[wasm_bindgen(getter, js_class = "SomeClass")]
34+
// pub fn static_controller() -> SomeClass;
35+
// #[wasm_bindgen(getter, js_class = "SomeClass")]
36+
// pub fn set_static_controller(value: &SomeClass);
37+
38+
#[wasm_bindgen(constructor, js_class = "SomeClass")]
39+
pub fn new() -> SomeClass;
40+
41+
// js_name conflicts with the getter/setter name
42+
#[wasm_bindgen(method, getter = a, js_class = "SomeClass", js_name = b)]
43+
pub fn c(this: &SomeClass) -> u32;
44+
#[wasm_bindgen(method, setter = a, js_class = "SomeClass", js_name = b)]
45+
pub fn set_c(this: &SomeClass, value: u32);
46+
}
47+
48+
#[wasm_bindgen]
49+
pub fn exported() {
50+
set_foo(get_foo());
51+
set_foo2(get_foo2());
52+
53+
let a = SomeClass::new();
54+
a.set_signal(a.signal());
55+
a.set_some_prop(a.some_prop());
56+
a.set_another(a.another());
57+
a.set_c(a.c());
58+
// let _ = static_signal();
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(module $reference_test.wasm
2+
(type (;0;) (func))
3+
(func $exported (;0;) (type 0))
4+
(memory (;0;) 17)
5+
(export "memory" (memory 0))
6+
(export "exported" (func $exported))
7+
(@custom "target_features" (after code) "\04+\0amultivalue+\0fmutable-globals+\0freference-types+\08sign-ext")
8+
)
9+

0 commit comments

Comments
 (0)