mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-21 16:51:33 +00:00
Fix an issue where closure rewriting required class internals
Surfaced through previous sanity-checking commits, this reorders some internal operations to... Closes #1174
This commit is contained in:
@ -171,8 +171,6 @@ impl<'a> Context<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn finalize(&mut self, module_name: &str) -> Result<(String, String), Error> {
|
pub fn finalize(&mut self, module_name: &str) -> Result<(String, String), Error> {
|
||||||
self.write_classes()?;
|
|
||||||
|
|
||||||
self.bind("__wbindgen_object_clone_ref", &|me| {
|
self.bind("__wbindgen_object_clone_ref", &|me| {
|
||||||
me.expose_get_object();
|
me.expose_get_object();
|
||||||
me.expose_add_heap_object();
|
me.expose_add_heap_object();
|
||||||
@ -429,6 +427,7 @@ impl<'a> Context<'a> {
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
closures::rewrite(self).with_context(|_| "failed to generate internal closure shims")?;
|
closures::rewrite(self).with_context(|_| "failed to generate internal closure shims")?;
|
||||||
|
self.write_classes()?;
|
||||||
self.unexport_unused_internal_exports();
|
self.unexport_unused_internal_exports();
|
||||||
|
|
||||||
// Handle the `start` function, if one was specified. If we're in a
|
// Handle the `start` function, if one was specified. If we're in a
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
|
const wasm = require('wasm-bindgen-test');
|
||||||
|
|
||||||
exports.works_call = a => {
|
exports.works_call = a => {
|
||||||
a();
|
a();
|
||||||
@ -97,3 +98,7 @@ exports.drop_during_call_save = f => {
|
|||||||
DROP_DURING_CALL = f;
|
DROP_DURING_CALL = f;
|
||||||
};
|
};
|
||||||
exports.drop_during_call_call = () => DROP_DURING_CALL();
|
exports.drop_during_call_call = () => DROP_DURING_CALL();
|
||||||
|
|
||||||
|
exports.js_test_closure_returner = () => {
|
||||||
|
wasm.closure_returner().someKey();
|
||||||
|
};
|
||||||
|
@ -63,6 +63,8 @@ extern "C" {
|
|||||||
|
|
||||||
fn drop_during_call_save(a: &Closure<Fn()>);
|
fn drop_during_call_save(a: &Closure<Fn()>);
|
||||||
fn drop_during_call_call();
|
fn drop_during_call_call();
|
||||||
|
|
||||||
|
fn js_test_closure_returner();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen_test]
|
#[wasm_bindgen_test]
|
||||||
@ -279,3 +281,33 @@ fn drop_during_call_ok() {
|
|||||||
assert!(HIT);
|
assert!(HIT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[wasm_bindgen_test]
|
||||||
|
fn test_closure_returner() {
|
||||||
|
type ClosureType = FnMut() -> BadStruct;
|
||||||
|
|
||||||
|
use js_sys::{Object, Reflect};
|
||||||
|
use wasm_bindgen::JsCast;
|
||||||
|
|
||||||
|
js_test_closure_returner();
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct ClosureHandle(Closure<ClosureType>);
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub struct BadStruct {}
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
pub fn closure_returner() -> Result<Object, JsValue> {
|
||||||
|
|
||||||
|
let o = Object::new();
|
||||||
|
|
||||||
|
let some_fn = Closure::wrap(Box::new(move || BadStruct {}) as Box<ClosureType>);
|
||||||
|
Reflect::set(&o, &JsValue::from("someKey"), &some_fn.as_ref().unchecked_ref())
|
||||||
|
.unwrap();
|
||||||
|
Reflect::set(&o, &JsValue::from("handle"), &JsValue::from(ClosureHandle(some_fn)))
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
|
Ok(o)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user