feat(napi): major upgrades for napi@1
1. inline everything 2. change `check_status` and `type_of` to macro 3. provide #[module_exports] macro 4. remove debug and repr[transparent] for ffi struct
This commit is contained in:
parent
9c8a4dee99
commit
1a3621b727
59 changed files with 903 additions and 1014 deletions
bench/src
|
@ -1,8 +1,6 @@
|
|||
use napi::{
|
||||
CallContext, Env, JsBuffer, JsBufferValue, JsNumber, JsObject, Module, Ref, Result, Task,
|
||||
};
|
||||
use napi::{CallContext, Env, JsBuffer, JsBufferValue, JsNumber, JsObject, Ref, Result, Task};
|
||||
|
||||
|
||||
#[repr(transparent)]
|
||||
struct BufferLength(Ref<JsBufferValue>);
|
||||
|
||||
impl Task for BufferLength {
|
||||
|
@ -27,7 +25,7 @@ fn bench_async_task(ctx: CallContext) -> Result<JsObject> {
|
|||
Ok(async_promise.promise_object())
|
||||
}
|
||||
|
||||
pub fn register_js(module: &mut Module) -> Result<()> {
|
||||
module.create_named_method("benchAsyncTask", bench_async_task)?;
|
||||
pub fn register_js(exports: &mut JsObject) -> Result<()> {
|
||||
exports.create_named_method("benchAsyncTask", bench_async_task)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
#[macro_use]
|
||||
extern crate napi;
|
||||
#[macro_use]
|
||||
extern crate napi_derive;
|
||||
|
||||
use napi::{Module, Result};
|
||||
use napi::{JsObject, Result};
|
||||
|
||||
mod async_compute;
|
||||
mod noop;
|
||||
mod plus;
|
||||
|
||||
register_module!(bench, init);
|
||||
#[module_exports]
|
||||
fn init(mut exports: JsObject) -> Result<()> {
|
||||
exports.create_named_method("noop", noop::noop)?;
|
||||
|
||||
fn init(module: &mut Module) -> Result<()> {
|
||||
module.create_named_method("noop", noop::noop)?;
|
||||
|
||||
async_compute::register_js(module)?;
|
||||
plus::register_js(module)?;
|
||||
async_compute::register_js(&mut exports)?;
|
||||
plus::register_js(&mut exports)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::convert::TryInto;
|
||||
|
||||
use napi::{CallContext, JsNumber, Module, Result};
|
||||
use napi::{CallContext, JsNumber, JsObject, Result};
|
||||
|
||||
#[js_function(2)]
|
||||
fn bench_plus(ctx: CallContext) -> Result<JsNumber> {
|
||||
|
@ -9,7 +9,7 @@ fn bench_plus(ctx: CallContext) -> Result<JsNumber> {
|
|||
ctx.env.create_uint32(a + b)
|
||||
}
|
||||
|
||||
pub fn register_js(module: &mut Module) -> Result<()> {
|
||||
module.create_named_method("plus", bench_plus)?;
|
||||
pub fn register_js(exports: &mut JsObject) -> Result<()> {
|
||||
exports.create_named_method("plus", bench_plus)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue