From fa6c92575157d2bae5e23c613acd85b0c8fe841e Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Thu, 7 Aug 2025 07:47:10 +0300 Subject: [PATCH] bindings/javascript: Switch from RefCell to Cell --- bindings/javascript/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/bindings/javascript/src/lib.rs b/bindings/javascript/src/lib.rs index d1b77e9d7..01a5b3d5e 100644 --- a/bindings/javascript/src/lib.rs +++ b/bindings/javascript/src/lib.rs @@ -13,7 +13,11 @@ use napi::bindgen_prelude::*; use napi::{Env, Task}; use napi_derive::napi; -use std::{cell::RefCell, num::NonZeroUsize, sync::Arc}; +use std::{ + cell::{Cell, RefCell}, + num::NonZeroUsize, + sync::Arc, +}; /// Step result constants const STEP_ROW: u32 = 1; @@ -35,7 +39,7 @@ pub struct Database { io: Arc, conn: Arc, is_memory: bool, - is_open: RefCell, + is_open: Cell, } #[napi] @@ -77,7 +81,7 @@ impl Database { io, conn, is_memory, - is_open: RefCell::new(true), + is_open: Cell::new(true), }) } @@ -90,7 +94,7 @@ impl Database { /// Returns whether the database connection is open. #[napi(getter)] pub fn open(&self) -> bool { - *self.is_open.borrow() + self.is_open.get() } /// Executes a batch of SQL statements. @@ -173,7 +177,7 @@ impl Database { /// `Ok(())` if the database is closed successfully. #[napi] pub fn close(&self) -> Result<()> { - *self.is_open.borrow_mut() = false; + self.is_open.set(false); // Database close is handled automatically when dropped Ok(()) }