Expand description
Finalize is executed on the main JavaScript thread and executed immediately
before garbage collection.
Values contained by a JsBox
must implement Finalize
.
Examples
Finalize
provides a default implementation that does not perform any finalization.
struct Point(f64, f64);
impl Finalize for Point {}
A finalize
method may be specified for performing clean-up operations before dropping
the contained value.
struct Point(f64, f64);
impl Finalize for Point {
fn finalize<'a, C: Context<'a>>(self, cx: &mut C) {
let global = cx.global();
let emit: Handle<JsFunction> = global
.get(cx, "emit")
.unwrap();
let args = vec![
cx.string("gc_point").upcast::<JsValue>(),
cx.number(self.0).upcast(),
cx.number(self.1).upcast(),
];
emit.call(cx, global, args).unwrap();
}
}