-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from goto-bus-stop/objects
Plain data objects
- Loading branch information
Showing
17 changed files
with
437 additions
and
146 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
//! Facilities for working with Array `napi_value`s. | ||
use raw::{Local, Env}; | ||
|
||
use nodejs_sys as napi; | ||
|
||
pub unsafe extern "C" fn new(_out: &mut Local, _env: Env, _length: u32) { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn len(_array: Local) -> u32 { unimplemented!() } | ||
/// Gets the length of a `napi_value` containing a JavaScript Array. | ||
/// | ||
/// # Panics | ||
/// This function panics if `array` is not an Array, or if a previous n-api call caused a pending | ||
/// exception. | ||
pub unsafe extern "C" fn len(env: Env, array: Local) -> u32 { | ||
let mut len = 0; | ||
assert_eq!(napi::napi_get_array_length(env, array, &mut len as *mut _), napi::napi_status::napi_ok); | ||
len | ||
} |
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,5 +1,11 @@ | ||
use raw::Local; | ||
use nodejs_sys as napi; | ||
|
||
use raw::{Env, Local}; | ||
|
||
pub unsafe extern "C" fn to_object(_out: &mut Local, _value: &Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn to_string(_out: &mut Local, _value: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn to_string(out: &mut Local, env: Env, value: Local) -> bool { | ||
let status = napi::napi_coerce_to_string(env, value, out as *mut _); | ||
|
||
status == napi::napi_status::napi_ok | ||
} |
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,23 +1,44 @@ | ||
use raw::Local; | ||
use raw::{Env, Local}; | ||
|
||
pub unsafe extern "C" fn is_undefined(_val: Local) -> bool { unimplemented!() } | ||
use nodejs_sys as napi; | ||
|
||
pub unsafe extern "C" fn is_null(_val: Local) -> bool { unimplemented!() } | ||
/// Return true if an `napi_value` `val` has the expected value type. | ||
unsafe fn is_type(env: Env, val: Local, expect: napi::napi_valuetype) -> bool { | ||
let mut actual = napi::napi_valuetype::napi_undefined; | ||
if napi::napi_typeof(env, val, &mut actual as *mut _) == napi::napi_status::napi_ok { | ||
actual == expect | ||
} else { | ||
false | ||
} | ||
} | ||
|
||
pub unsafe extern "C" fn is_number(_val: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn is_undefined(_env: Env, _val: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_boolean(_val: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn is_null(_env: Env, _val: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_string(_val: Local) -> bool { unimplemented!() } | ||
/// Is `val` a JavaScript number? | ||
pub unsafe extern "C" fn is_number(env: Env, val: Local) -> bool { | ||
is_type(env, val, napi::napi_valuetype::napi_number) | ||
} | ||
|
||
pub unsafe extern "C" fn is_object(_val: Local) -> bool { unimplemented!() } | ||
/// Is `val` a JavaScript boolean? | ||
pub unsafe extern "C" fn is_boolean(env: Env, val: Local) -> bool { | ||
is_type(env, val, napi::napi_valuetype::napi_boolean) | ||
} | ||
|
||
pub unsafe extern "C" fn is_array(_val: Local) -> bool { unimplemented!() } | ||
/// Is `val` a JavaScript string? | ||
pub unsafe extern "C" fn is_string(env: Env, val: Local) -> bool { | ||
is_type(env, val, napi::napi_valuetype::napi_string) | ||
} | ||
|
||
pub unsafe extern "C" fn is_function(_val: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn is_object(_env: Env, _val: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_error(_val: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn is_array(_env: Env, _val: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_buffer(_obj: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn is_function(_env: Env, _val: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_arraybuffer(_obj: Local) -> bool { unimplemented!() } | ||
pub unsafe extern "C" fn is_error(_env: Env, _val: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_buffer(_env: Env, _obj: Local) -> bool { unimplemented!() } | ||
|
||
pub unsafe extern "C" fn is_arraybuffer(_env: Env, _obj: Local) -> bool { unimplemented!() } |
Oops, something went wrong.