Fix single shot timer leaks in the nodejs api

As discussed, don't use the persistent context approach for single
shot timers but store the callback directly in the global object
and "delete" it afterwards.
This commit is contained in:
Simon Hausmann 2020-12-19 13:49:41 +01:00
parent b42c16851a
commit 0e04149868
3 changed files with 25 additions and 20 deletions

View file

@ -40,16 +40,4 @@ impl<'a> PersistentContext<'a> {
pub fn from_object(cx: &mut impl Context<'a>, o: Handle<'a, JsObject>) -> NeonResult<Self> {
Ok(PersistentContext(o.get(cx, KEY)?.downcast_or_throw(cx)?))
}
pub fn global(cx: &mut impl Context<'a>) -> NeonResult<Self> {
let global_object: Handle<JsObject> = cx.global().downcast().unwrap();
Ok(match global_object.get(cx, KEY)?.downcast() {
Ok(array) => PersistentContext(array),
Err(_) => {
let ctx = PersistentContext::new(cx);
ctx.save_to_object(cx, global_object);
ctx
}
})
}
}