[oden-js] Ensure callbacks have 'static lifetime

Because we smuggle them through we need to make sure they're not
holding references that will go invalid- we can make no promises about
how long they stay alive. Although maybe bounding to context lifetime
is OK? But anyway.
This commit is contained in:
John Doty 2023-06-21 22:02:07 -07:00
parent 14f9eb655f
commit e36ab17235
3 changed files with 8 additions and 8 deletions

View file

@ -270,7 +270,7 @@ impl ValueRef {
&mut self,
ctx: &ContextRef,
prop: &str,
func: impl RustFunction<F>,
func: impl RustFunction<F> + 'static,
) -> Result<()> {
let vr: Value = ctx.new_fn(func)?;
self.set_property(ctx, prop, &vr)
@ -278,7 +278,7 @@ impl ValueRef {
pub fn set_dynamic_method<F>(&mut self, ctx: &ContextRef, prop: &str, func: F) -> Result<()>
where
F: Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> Result<Value>,
F: 'static + Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> Result<Value>,
{
let vr: Value = ctx.new_dynamic_fn(func)?;
self.set_property(ctx, prop, &vr)