mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 10:59:13 +00:00
feat(npm): implement Node API (#13633)
This PR implements the NAPI for loading native modules into Deno. Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com> Co-authored-by: DjDeveloper <43033058+DjDeveloperr@users.noreply.github.com> Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
This commit is contained in:
parent
3a3a848406
commit
0b016a7fb8
55 changed files with 5299 additions and 2 deletions
23
cli/napi/util.rs
Normal file
23
cli/napi/util.rs
Normal file
|
@ -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<v8::BackingStore>,
|
||||
byte_offset: usize,
|
||||
byte_length: usize,
|
||||
) -> &mut [u8] {
|
||||
let cells: *const [Cell<u8>] =
|
||||
&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<v8::ArrayBuffer>) -> *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()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue