-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Loading #646
Merged
Merged
Dynamic Loading #646
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
84c2f51
chore(neon-runtime): Update to 2018 edition
kjvalencik 7422e60
chore(neon-runtime): Rename nodejs-sys feature to napi
kjvalencik 0900dd2
feature(neon-runtime): Dynamic module loading
kjvalencik 1c0a540
hack(test/napi): Remove neon-build to test dynamic loading
kjvalencik ccd508d
doc(neon-runtime): Add documentation from dynamic loading review comm…
kjvalencik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,15 +5,20 @@ authors = ["Dave Herman <[email protected]>"] | |
description = "Bindings to the Node.js native addon API, used by the Neon implementation." | ||
repository = "https://github.com/neon-bindings/neon" | ||
license = "MIT/Apache-2.0" | ||
edition = "2018" | ||
|
||
[dependencies] | ||
cfg-if = "0.1.9" | ||
libloading = { version = "0.6.5", optional = true } | ||
neon-sys = { version = "=0.5.3", path = "../neon-sys", optional = true } | ||
nodejs-sys = { version = "0.7.0", optional = true } | ||
smallvec = "1.4.2" | ||
|
||
[dev-dependencies] | ||
nodejs-sys = "0.7.0" # Not strictly needed; just here for easy manual copying | ||
|
||
[features] | ||
default = [] | ||
napi = ["libloading"] | ||
docs-only = ["neon-sys/docs-only"] | ||
|
||
[package.metadata.docs.rs] | ||
|
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 |
---|---|---|
@@ -1,26 +1,21 @@ | ||
extern crate cfg_if; | ||
extern crate smallvec; | ||
|
||
#[cfg(all(not(feature = "neon-sys"), not(feature = "nodejs-sys")))] | ||
compile_error!("The Neon runtime must have at least one of the `neon-sys` or `nodejs-sys` backends enabled."); | ||
#[cfg(all(not(feature = "neon-sys"), not(feature = "napi")))] | ||
compile_error!("The Neon runtime must have at least one of the `neon-sys` or `napi` backends enabled."); | ||
|
||
use cfg_if::cfg_if; | ||
|
||
cfg_if! { | ||
if #[cfg(feature = "nodejs-sys")] { | ||
pub extern crate nodejs_sys; | ||
if #[cfg(feature = "napi")] { | ||
pub mod napi; | ||
} | ||
} | ||
|
||
cfg_if! { | ||
if #[cfg(feature = "neon-sys")] { | ||
extern crate neon_sys; | ||
pub mod nan; | ||
// The legacy variant is the default API as long as it's present. | ||
pub use nan::*; | ||
} else if #[cfg(feature = "nodejs-sys")] { | ||
pub use crate::nan::*; | ||
} else if #[cfg(feature = "napi")] { | ||
// The N-API variant is only the default API if the legacy variant is disabled. | ||
pub use napi::*; | ||
pub use crate::napi::*; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,20 @@ | ||
use raw::{Env, Local}; | ||
use crate::raw::{Env, Local}; | ||
use std::os::raw::c_void; | ||
use std::ptr::null_mut; | ||
|
||
use nodejs_sys as napi; | ||
use crate::napi::bindings as napi; | ||
|
||
pub unsafe extern "C" fn new(out: &mut Local, env: Env, size: u32) -> bool { | ||
let status = napi::napi_create_arraybuffer(env, size as usize, null_mut(), out as *mut _); | ||
let status = napi::create_arraybuffer(env, size as usize, null_mut(), out as *mut _); | ||
|
||
status == napi::napi_status::napi_ok | ||
status == napi::Status::Ok | ||
} | ||
|
||
pub unsafe extern "C" fn data<'a, 'b>(env: Env, base_out: &'a mut *mut c_void, obj: Local) -> usize { | ||
let mut size = 0; | ||
assert_eq!( | ||
napi::napi_get_arraybuffer_info(env, obj, base_out as *mut _, &mut size as *mut _), | ||
napi::napi_status::napi_ok, | ||
napi::get_arraybuffer_info(env, obj, base_out as *mut _, &mut size as *mut _), | ||
napi::Status::Ok, | ||
); | ||
size | ||
} |
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,204 @@ | ||
#[cfg(windows)] | ||
use libloading::os::windows::Library; | ||
#[cfg(not(windows))] | ||
use libloading::os::unix::Library; | ||
|
||
use std::os::raw::{c_char, c_void}; | ||
use super::types::*; | ||
|
||
generate!(extern "C" { | ||
fn get_undefined(env: Env, result: *mut Value) -> Status; | ||
|
||
fn get_null(env: Env, result: *mut Value) -> Status; | ||
|
||
fn get_global(env: Env, result: *mut Value) -> Status; | ||
|
||
fn get_boolean(env: Env, value: bool, result: *mut Value) -> Status; | ||
|
||
fn create_double(env: Env, value: f64, result: *mut Value) -> Status; | ||
|
||
fn create_object(env: Env, result: *mut Value) -> Status; | ||
|
||
fn get_value_bool(env: Env, value: Value, result: *mut bool) -> Status; | ||
|
||
fn get_value_double(env: Env, value: Value, result: *mut f64) -> Status; | ||
|
||
fn create_array_with_length(env: Env, length: usize, result: *mut Value) -> Status; | ||
|
||
fn get_array_length(env: Env, value: Value, result: *mut u32)-> Status; | ||
|
||
fn get_new_target(env: Env, cbinfo: CallbackInfo, result: *mut Value) -> Status; | ||
|
||
fn coerce_to_object(env: Env, value: Value, result: *mut Value) -> Status; | ||
|
||
fn coerce_to_string(env: Env, value: Value, result: *mut Value) -> Status; | ||
|
||
fn throw(env: Env, error: Value) -> Status; | ||
|
||
fn create_error(env: Env, code: Value, msg: Value, result: *mut Value) -> Status; | ||
|
||
fn get_and_clear_last_exception(env: Env, result: *mut Value) -> Status; | ||
|
||
fn is_exception_pending(env: Env, result: *mut bool) -> Status; | ||
|
||
fn get_value_external(env: Env, value: Value, result: *mut *mut c_void) -> Status; | ||
|
||
fn typeof_value(env: Env, value: Value, result: *mut ValueType) -> Status; | ||
|
||
fn close_escapable_handle_scope(env: Env, scope: EscapableHandleScope) -> Status; | ||
|
||
fn open_escapable_handle_scope(env: Env, result: *mut EscapableHandleScope) -> Status; | ||
|
||
fn open_handle_scope(env: Env, result: *mut HandleScope) -> Status; | ||
|
||
fn close_handle_scope(env: Env, scope: HandleScope) -> Status; | ||
|
||
fn is_arraybuffer(env: Env, value: Value, result: *mut bool) -> Status; | ||
fn is_buffer(env: Env, value: Value, result: *mut bool) -> Status; | ||
fn is_error(env: Env, value: Value, result: *mut bool) -> Status; | ||
fn is_array(env: Env, value: Value, result: *mut bool) -> Status; | ||
|
||
fn get_value_string_utf8( | ||
env: Env, | ||
value: Value, | ||
buf: *mut c_char, | ||
bufsize: usize, | ||
result: *mut usize, | ||
) -> Status; | ||
|
||
fn create_type_error( | ||
env: Env, | ||
code: Value, | ||
msg: Value, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn create_range_error( | ||
env: Env, | ||
code: Value, | ||
msg: Value, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn create_string_utf8( | ||
env: Env, | ||
str: *const c_char, | ||
length: usize, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn create_arraybuffer( | ||
env: Env, | ||
byte_length: usize, | ||
data: *mut *mut c_void, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn get_arraybuffer_info( | ||
env: Env, | ||
arraybuffer: Value, | ||
data: *mut *mut c_void, | ||
byte_length: *mut usize, | ||
) -> Status; | ||
|
||
fn create_buffer( | ||
env: Env, | ||
length: usize, | ||
data: *mut *mut c_void, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn get_buffer_info( | ||
env: Env, | ||
value: Value, | ||
data: *mut *mut c_void, | ||
length: *mut usize, | ||
) -> Status; | ||
|
||
fn get_cb_info( | ||
env: Env, | ||
cbinfo: CallbackInfo, | ||
argc: *mut usize, | ||
argv: *mut Value, | ||
this_arg: *mut Value, | ||
data: *mut *mut c_void, | ||
) -> Status; | ||
|
||
fn create_external( | ||
env: Env, | ||
data: *mut c_void, | ||
finalize_cb: Finalize, | ||
finalize_hint: *mut c_void, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn new_instance( | ||
env: Env, | ||
constructor: Value, | ||
argc: usize, | ||
argv: *const Value, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn call_function( | ||
env: Env, | ||
recv: Value, | ||
func: Value, | ||
argc: usize, | ||
argv: *const Value, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn create_function( | ||
env: Env, | ||
utf8name: *const c_char, | ||
length: usize, | ||
cb: Callback, | ||
data: *mut c_void, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn set_property( | ||
env: Env, | ||
object: Value, | ||
key: Value, | ||
value: Value, | ||
) -> Status; | ||
|
||
fn get_property( | ||
env: Env, | ||
object: Value, | ||
key: Value, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn set_element( | ||
env: Env, | ||
object: Value, | ||
index: u32, | ||
value: Value, | ||
) -> Status; | ||
|
||
fn get_element( | ||
env: Env, | ||
object: Value, | ||
index: u32, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn get_all_property_names( | ||
env: Env, | ||
object: Value, | ||
key_mode: KeyCollectionMode, | ||
key_filter: KeyFilter, | ||
key_conversion: KeyConversion, | ||
result: *mut Value, | ||
) -> Status; | ||
|
||
fn escape_handle( | ||
env: Env, | ||
scope: EscapableHandleScope, | ||
escapee: Value, | ||
result: *mut Value, | ||
) -> Status; | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These naming conventions aren't, like, gonna change the world, but they're so nice 😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's not to love about repeating the word
napi
3x in a single identifier? 😆s/napi::napi_status::napi_ok/napi::Status::Ok/
napi, napi.... napi.
...napi