You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Currently moving any Gc<T> inside a closure causes a panic. This issue comes from Manishearth/rust-gc#50, and it doesn't seem like it will get fixed until there's some API for garbage collectors in rustc.
However, we currently allow moving JsObjects and JsValues inside closures, which causes a panic on destruction.
To Reproduce
use boa::{Context,JsValue};fnmain() -> Result<(),JsValue>{letmut context = Context::new();let object = context.construct_object();let moved_object = object.clone();
context.register_global_closure("closure",0,move |_, _, _| {// This value is captured from main function.
moved_object.is_array();Ok(JsValue::Undefined)})?;Ok(())}
Additional comments
Should we restrict closures to only Fn(..) + Copy? Or should we allow any Fn and document that moving a JsObject into a closure causes a panic?
Maybe we could even make all closures Fn(..) + Copy and ask the user to pass a Captures type, then we change the definition of our closures to Fn(&JsValue, &[JsValue], &mut Closure, Box<dyn Any>) and ask the user to downcast the dyn Any to the type of its Captures. This allows maximum flexibility because the user can pass JsValue and JsObject, but it's also not very ergonomic.
The text was updated successfully, but these errors were encountered:
I forgot to mention this blocks the implementation of Arguments Mapped exotic objects, because to create one we need to capture the current Environment in a closure and save that closure inside the object.
Describe the bug
Currently moving any
Gc<T>
inside a closure causes a panic. This issue comes from Manishearth/rust-gc#50, and it doesn't seem like it will get fixed until there's some API for garbage collectors in rustc.However, we currently allow moving
JsObjects
andJsValues
inside closures, which causes a panic on destruction.To Reproduce
Additional comments
Should we restrict closures to only
Fn(..) + Copy
? Or should we allow any Fn and document that moving aJsObject
into a closure causes a panic?Maybe we could even make all closures
Fn(..) + Copy
and ask the user to pass aCaptures
type, then we change the definition of our closures toFn(&JsValue, &[JsValue], &mut Closure, Box<dyn Any>)
and ask the user to downcast thedyn Any
to the type of itsCaptures
. This allows maximum flexibility because the user can passJsValue
andJsObject
, but it's also not very ergonomic.The text was updated successfully, but these errors were encountered: