File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ in Rust, for example:
12
12
allocated.
13
13
* Rust closures converted to JS values (the ` Closure ` type) may not be executed
14
14
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.
17
17
18
18
These issues are all solved with the weak references proposal in JS. The
19
19
` --weak-refs ` flag to the ` wasm-bindgen ` CLI will enable usage of
Original file line number Diff line number Diff line change @@ -374,11 +374,16 @@ where
374
374
/// JS closure is GC'd. Weak references are not enabled by default since
375
375
/// they're still a proposal for the JS standard. They can be enabled with
376
376
/// `WASM_BINDGEN_WEAKREF=1` when running `wasm-bindgen`, however.
377
- pub fn forget ( self ) -> JsValue {
377
+ pub fn into_js_value ( self ) -> JsValue {
378
378
let idx = self . js . idx ;
379
379
mem:: forget ( self ) ;
380
380
JsValue :: _new ( idx)
381
381
}
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
+ }
382
387
}
383
388
384
389
// NB: we use a specific `T` for this `Closure<T>` impl block to avoid every
You can’t perform that action at this time.
0 commit comments