From 99403b7282d6e6632baff1072e643976b0b04843 Mon Sep 17 00:00:00 2001 From: Akulij Date: Sat, 7 Jun 2025 01:28:21 +0500 Subject: [PATCH] fix: implement js's db callback without box leak --- src/botscript/db.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/botscript/db.rs b/src/botscript/db.rs index 912b48a..1f3329e 100644 --- a/src/botscript/db.rs +++ b/src/botscript/db.rs @@ -16,16 +16,14 @@ pub fn attach_db_obj(c: &Context, o: &mut OwnedJsObject, db: &DB) -> Result<(), .expect("the created object was not an object :/"); let db: std::sync::Arc> = std::sync::Arc::new(RwLock::new(db.clone())); - let dbbox = Box::new(db); - let db: &'static _ = Box::leak(dbbox); let find_one = c.create_callback( - |collection: String, q: OwnedJsObject| -> Result<_, ScriptError> { + move |collection: String, q: OwnedJsObject| -> Result<_, ScriptError> { + // let db = db.clone(); let query: serde_json::Value = match from_js(q.context(), &q) { Ok(q) => q, Err(_) => todo!(), }; - let db = db.clone(); let value = futures::executor::block_on( db.write()