Skip to content

Commit 1943e29

Browse files
authored
Fix breakage from changing Closure::forget (#2258)
Add a new method for now instead of changing `Closure::forget`
1 parent ebc1e92 commit 1943e29

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

guide/src/reference/weak-references.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ in Rust, for example:
1212
allocated.
1313
* Rust closures converted to JS values (the `Closure` type) may not be executed
1414
and cleaned up.
15-
* Rust closures have a `Closure::forget` method which explicitly doesn't free
16-
the underlying memory.
15+
* Rust closures have `Closure::{into_js_value,forget}` methods which explicitly
16+
do not free the underlying memory.
1717

1818
These issues are all solved with the weak references proposal in JS. The
1919
`--weak-refs` flag to the `wasm-bindgen` CLI will enable usage of

src/closure.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,16 @@ where
374374
/// JS closure is GC'd. Weak references are not enabled by default since
375375
/// they're still a proposal for the JS standard. They can be enabled with
376376
/// `WASM_BINDGEN_WEAKREF=1` when running `wasm-bindgen`, however.
377-
pub fn forget(self) -> JsValue {
377+
pub fn into_js_value(self) -> JsValue {
378378
let idx = self.js.idx;
379379
mem::forget(self);
380380
JsValue::_new(idx)
381381
}
382+
383+
/// Same as `into_js_value`, but doesn't return a value.
384+
pub fn forget(self) {
385+
drop(self.into_js_value());
386+
}
382387
}
383388

384389
// NB: we use a specific `T` for this `Closure<T>` impl block to avoid every

0 commit comments

Comments
 (0)