From 0b016a7fb8639ce49603c8c339539174b191a4b1 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Wed, 5 Oct 2022 07:06:44 -0700 Subject: feat(npm): implement Node API (#13633) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR implements the NAPI for loading native modules into Deno. Co-authored-by: Bartek IwaƄczuk Co-authored-by: DjDeveloper <43033058+DjDeveloperr@users.noreply.github.com> Co-authored-by: Ryan Dahl --- cli/napi/util.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cli/napi/util.rs (limited to 'cli/napi/util.rs') diff --git a/cli/napi/util.rs b/cli/napi/util.rs new file mode 100644 index 000000000..2dea03554 --- /dev/null +++ b/cli/napi/util.rs @@ -0,0 +1,23 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +use deno_runtime::deno_napi::*; +use std::cell::Cell; + +unsafe fn get_backing_store_slice( + backing_store: &mut v8::SharedRef, + byte_offset: usize, + byte_length: usize, +) -> &mut [u8] { + let cells: *const [Cell] = + &backing_store[byte_offset..byte_offset + byte_length]; + let mut bytes = cells as *mut [u8]; + &mut *bytes +} + +pub fn get_array_buffer_ptr(ab: v8::Local) -> *mut u8 { + let mut backing_store = ab.get_backing_store(); + let byte_length = ab.byte_length(); + let mut slice = + unsafe { get_backing_store_slice(&mut backing_store, 0, byte_length) }; + slice.as_mut_ptr() +} -- cgit v1.2.3