summaryrefslogtreecommitdiff
path: root/serde_v8
diff options
context:
space:
mode:
Diffstat (limited to 'serde_v8')
-rw-r--r--serde_v8/examples/basic.rs2
-rw-r--r--serde_v8/magic/rawbytes.rs2
-rw-r--r--serde_v8/serializable.rs2
-rw-r--r--serde_v8/utils.rs1
4 files changed, 7 insertions, 0 deletions
diff --git a/serde_v8/examples/basic.rs b/serde_v8/examples/basic.rs
index 81a8e6e6c..8f19e9405 100644
--- a/serde_v8/examples/basic.rs
+++ b/serde_v8/examples/basic.rs
@@ -52,6 +52,8 @@ fn main() {
println!("x = {}", x);
}
+ // SAFETY: all isolates have been destroyed, so we can now safely let V8 clean
+ // up its resources.
unsafe {
v8::V8::dispose();
}
diff --git a/serde_v8/magic/rawbytes.rs b/serde_v8/magic/rawbytes.rs
index d82e68717..2189ebfc3 100644
--- a/serde_v8/magic/rawbytes.rs
+++ b/serde_v8/magic/rawbytes.rs
@@ -87,8 +87,10 @@ mod tests {
#[test]
fn bytes_layout() {
+ // SAFETY: ensuring layout is the same
let u1: [usize; 4] =
unsafe { mem::transmute(from_static(HELLO.as_bytes())) };
+ // SAFETY: ensuring layout is the same
let u2: [usize; 4] =
unsafe { mem::transmute(bytes::Bytes::from_static(HELLO.as_bytes())) };
assert_eq!(u1[..3], u2[..3]); // Struct bytes are equal besides Vtables
diff --git a/serde_v8/serializable.rs b/serde_v8/serializable.rs
index a724f300e..abde544c7 100644
--- a/serde_v8/serializable.rs
+++ b/serde_v8/serializable.rs
@@ -97,6 +97,8 @@ impl<T: serde::Serialize + 'static> From<T> for SerializablePkg {
fn from(x: T) -> Self {
#[inline(always)]
fn tc<T, U>(src: T) -> U {
+ // SAFETY: the caller has ensured via the TypeId that the T and U types
+ // are the same.
let x = unsafe { transmute_copy(&src) };
std::mem::forget(src);
x
diff --git a/serde_v8/utils.rs b/serde_v8/utils.rs
index 427ac5f2f..d491ac093 100644
--- a/serde_v8/utils.rs
+++ b/serde_v8/utils.rs
@@ -17,6 +17,7 @@ pub fn v8_init() {
}
pub fn v8_shutdown() {
+ // SAFETY: this is safe, because all isolates have been shut down already.
unsafe {
v8::V8::dispose();
}