-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(neon): RFC#44 Borrow API breaking changes
Implements neon-bindings/rfcs#44
- Loading branch information
1 parent
f2e1960
commit d26eee0
Showing
23 changed files
with
1,134 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::ffi::c_void; | ||
use std::mem::MaybeUninit; | ||
|
||
use crate::napi::bindings::{self as napi, TypedArrayType}; | ||
use crate::raw::{Env, Local}; | ||
|
||
#[derive(Debug)] | ||
/// Information describing a JavaScript [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) | ||
pub struct TypedArrayInfo { | ||
pub typ: TypedArrayType, | ||
pub length: usize, | ||
pub data: *mut c_void, | ||
pub buf: Local, | ||
pub offset: usize, | ||
} | ||
|
||
/// Get [information](TypedArrayInfo) describing a JavaScript `TypedArray` | ||
/// | ||
/// # Safety | ||
/// * `env` must be valid `napi_env` for the current scope | ||
/// * `value` must be a handle pointing to a `TypedArray` | ||
pub unsafe fn info(env: Env, value: Local) -> TypedArrayInfo { | ||
let mut info = MaybeUninit::<TypedArrayInfo>::zeroed(); | ||
let ptr = info.as_mut_ptr(); | ||
|
||
assert_eq!( | ||
napi::get_typedarray_info( | ||
env, | ||
value, | ||
&mut (*ptr).typ, | ||
&mut (*ptr).length, | ||
&mut (*ptr).data, | ||
&mut (*ptr).buf, | ||
&mut (*ptr).offset, | ||
), | ||
napi::Status::Ok, | ||
); | ||
|
||
info.assume_init() | ||
} |
Oops, something went wrong.