diff --git a/cli/ops/plugin.rs b/cli/ops/plugin.rs index 775178f1eda612..e648b1919dfd20 100644 --- a/cli/ops/plugin.rs +++ b/cli/ops/plugin.rs @@ -105,7 +105,7 @@ impl<'a> plugin_api::Interface for PluginInterface<'a> { fn register_op( &mut self, name: &str, - dispatch_op_fn: plugin_api::DispatchOpFn, + dispatch_op_fn: Box, ) -> OpId { let plugin_lib = self.plugin_lib.clone(); self.isolate_state.op_registry.register( diff --git a/core/core_isolate.rs b/core/core_isolate.rs index dc22d821adbc8a..04f1ab72078972 100644 --- a/core/core_isolate.rs +++ b/core/core_isolate.rs @@ -109,6 +109,15 @@ pub struct CoreIsolateState { waker: AtomicWaker, } +impl Drop for CoreIsolateState { + fn drop(&mut self) { + // TODO(afinch7) this is a temporary fix for a segfault that occurus when + // dropping plugin ops. I know that the plugin Rc value gets dropped + // early for some reason, but still not quite sure why. + drop(std::mem::take(&mut self.op_registry)); + } +} + // TODO(ry) The trait v8::InIsolate is superfluous. HandleScope::new should just // take &mut v8::Isolate. impl v8::InIsolate for CoreIsolate { diff --git a/core/plugin_api.rs b/core/plugin_api.rs index 16f5d4a365b6c4..b82073359731ba 100644 --- a/core/plugin_api.rs +++ b/core/plugin_api.rs @@ -15,8 +15,9 @@ pub use crate::ZeroCopyBuf; pub type InitFn = fn(&mut dyn Interface); -pub type DispatchOpFn = fn(&mut dyn Interface, &[u8], &mut [ZeroCopyBuf]) -> Op; +pub type DispatchOpFn = + dyn Fn(&mut dyn Interface, &[u8], &mut [ZeroCopyBuf]) -> Op; pub trait Interface { - fn register_op(&mut self, name: &str, dispatcher: DispatchOpFn) -> OpId; + fn register_op(&mut self, name: &str, dispatcher: Box) -> OpId; } diff --git a/test_plugin/src/lib.rs b/test_plugin/src/lib.rs index 781bc42594fda3..906afa34b5834a 100644 --- a/test_plugin/src/lib.rs +++ b/test_plugin/src/lib.rs @@ -6,8 +6,8 @@ use futures::future::FutureExt; #[no_mangle] pub fn deno_plugin_init(interface: &mut dyn Interface) { - interface.register_op("testSync", op_test_sync); - interface.register_op("testAsync", op_test_async); + interface.register_op("testSync", Box::new(op_test_sync)); + interface.register_op("testAsync", Box::new(op_test_async)); } fn op_test_sync(