Skip to content

Commit 73a49a6

Browse files
committed
fix: enhance safety documentation for OwnedJsValue and implement Send/Sync traits
1 parent 8c08569 commit 73a49a6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/value/value.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@ use super::OwnedJsObject;
2828
/// OwnedJsValue wraps a Javascript value owned by the QuickJs runtime.
2929
///
3030
/// Guarantees cleanup of resources by dropping the value from the runtime.
31+
///
32+
/// **Safety**:
33+
///
34+
/// This type is `Send` and `Sync` only for convenience, since [OwnedJsValue](crate::OwnedJsValue)
35+
/// itself is just a wrapper around a raw pointer. But any operation on the underlying raw pointer is unsafe.
36+
/// Make sure using it in a same thread.
37+
///
3138
pub struct OwnedJsValue {
3239
context: *mut q::JSContext,
3340
// FIXME: make private again, just for testing
3441
pub(crate) value: q::JSValue,
3542
}
3643

44+
unsafe impl Send for OwnedJsValue {}
45+
unsafe impl Sync for OwnedJsValue {}
46+
3747
impl PartialEq for OwnedJsValue {
3848
fn eq(&self, other: &Self) -> bool {
3949
unsafe { q::JS_VALUE_GET_PTR(self.value) == q::JS_VALUE_GET_PTR(other.value) }

0 commit comments

Comments
 (0)