summaryrefslogtreecommitdiff
path: root/cli/napi/util.rs
diff options
context:
space:
mode:
authorsnek <snek@deno.com>2024-06-11 17:40:44 -0700
committerGitHub <noreply@github.com>2024-06-11 17:40:44 -0700
commit3765e6b3a625151e2c0377cad57420e2a82c9943 (patch)
tree63860ec64b0e0246ade25e5f3cd6935657644295 /cli/napi/util.rs
parent07437acc74f63c4f2e218c4424ef8fe6cf0f8de2 (diff)
fix: clean up some node-api details (#24178)
- fix a few napi_* types - clean up env hooks - implement blocking queue in tsfn - reduce transmutes - use new `DataView::new` api from rusty_v8
Diffstat (limited to 'cli/napi/util.rs')
-rw-r--r--cli/napi/util.rs13
1 files changed, 5 insertions, 8 deletions
diff --git a/cli/napi/util.rs b/cli/napi/util.rs
index cd3ef14a2..63d8effbf 100644
--- a/cli/napi/util.rs
+++ b/cli/napi/util.rs
@@ -15,10 +15,11 @@ impl<T> SendPtr<T> {
unsafe impl<T> Send for SendPtr<T> {}
unsafe impl<T> Sync for SendPtr<T> {}
-pub fn get_array_buffer_ptr(ab: v8::Local<v8::ArrayBuffer>) -> *mut u8 {
- // SAFETY: Thanks to the null pointer optimization, NonNull<T> and Option<NonNull<T>> are guaranteed
- // to have the same size and alignment.
- unsafe { std::mem::transmute(ab.data()) }
+pub fn get_array_buffer_ptr(ab: v8::Local<v8::ArrayBuffer>) -> *mut c_void {
+ match ab.data() {
+ Some(p) => p.as_ptr(),
+ None => std::ptr::null_mut(),
+ }
}
struct BufferFinalizer {
@@ -216,10 +217,6 @@ impl<'s> Nullable for napi_value<'s> {
}
}
-// TODO: replace Nullable with some sort of "CheckedUnwrap" trait
-// *mut T -> &mut MaybeUninit<T>
-// Option<T> -> T
-// napi_value -> Local<Value>
#[macro_export]
macro_rules! check_arg {
($env: expr, $ptr: expr) => {