feat(napi): impl create_uint32

This commit is contained in:
LongYinan 2020-04-20 00:43:48 +08:00
parent 6b032caca8
commit f29ddc3a19
No known key found for this signature in database
GPG key ID: C3666B7FC82ADAD7
2 changed files with 16 additions and 1 deletions

View file

@ -127,7 +127,7 @@ npm test
| [napi_create_typedarray](https://nodejs.org/api/n-api.html#n_api_napi_create_typedarray) | 1 | v8.0.0 | ⛔️ |
| [napi_create_dataview](https://nodejs.org/api/n-api.html#n_api_napi_create_dataview) | 1 | v8.3.0 | ⛔️ |
| [napi_create_int32](https://nodejs.org/api/n-api.html#n_api_napi_create_int32) | 1 | v8.4.0 | ⛔️ |
| [napi_create_uint32](https://nodejs.org/api/n-api.html#n_api_napi_create_uint32) | 1 | v8.4.0 | ⛔️ |
| [napi_create_uint32](https://nodejs.org/api/n-api.html#n_api_napi_create_uint32) | 1 | v8.4.0 | |
| [napi_create_int64](https://nodejs.org/api/n-api.html#n_api_napi_create_int64) | 1 | v8.4.0 | ✅ |
| [napi_create_double](https://nodejs.org/api/n-api.html#n_api_napi_create_double) | 1 | v8.4.0 | ⛔️ |
| [napi_create_bigint_int64](https://nodejs.org/api/n-api.html#n_api_napi_create_bigint_int64) | 6 | v10.7.0 | ⛔️ |

View file

@ -45,6 +45,7 @@ pub struct Boolean {
#[derive(Clone, Copy, Debug)]
pub enum Number {
Int(i64),
U32(u32),
Double(f64),
}
@ -266,6 +267,14 @@ impl Env {
Ok(Value::from_raw_value(self, raw_value, Number::Int(int)))
}
pub fn create_uint32<'a>(&'a self, number: u32) -> Result<Value<'a, Number>> {
let mut raw_value = ptr::null_mut();
let status =
unsafe { sys::napi_create_uint32(self.0, number, (&mut raw_value) as *mut sys::napi_value) };
check_status(status)?;
Ok(Value::from_raw_value(self, raw_value, Number::U32(number)))
}
pub fn create_double<'a>(&'a self, double: f64) -> Result<Value<'a, Number>> {
let mut raw_value = ptr::null_mut();
let status =
@ -1043,6 +1052,12 @@ impl<'env> Value<'env, Object> {
}
}
impl<'env> AsRef<[u8]> for Value<'env, Buffer> {
fn as_ref(&self) -> &[u8] {
self.deref()
}
}
impl<'env> Deref for Value<'env, Buffer> {
type Target = [u8];