Repository navigation
v0.15.1 — closure data the collector frees
Closure data the collector frees. The fix 0.15.0 made for promise
continuations, applied to plain function closures: JsFunction.create_with_data
gains a finalize_cb overload that ties heap data to the function's lifetime,
and the demo createAdder, which leaked its capture on every call, uses it.
No existing Mojo signature changed — the overload is an addition — so
downstream addons compile against 0.15.1 unmodified. createAdder gains an
optional second argument; calling it with one behaves as before.
Added
JsFunction.create_with_data(b, env, name, cb_ptr, data, finalize_cb)—
the closure form for heap data. The collector runsfinalize_cbonce the
function is gone;datais adopted on every path, so if the function
cannot be created or the finalizer attached,finalize_cbruns before the
call raises. Nothing is freed on the call path, because a function may be
called many times or never. The existing five-argument form is unchanged
and still frees nothing.JsPromise.on_settledis now built on this
overload, so the adopt-on-failure logic and the one function-pointer cast
it needs live in a single place.
Fixed
createAdderleaked its capture on every call. The closure example the
docs pointed to allocated its data per call and handed it to a function
with no finalizer, so nothing ever freed it — the same defect class 0.15.0
fixed for promise continuations. It now uses thefinalize_cboverload. It
takes an optionalcounterArrayBuffer(8) whose Int64 the capture's
finalizer increments, and GC tests pin both halves: the capture is freed
when the adder is collected, and is not freed while the adder is reachable.
Both regressions were mutation-checked against the suite.