2020-09-30 15:34:26 +09:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
2020-11-25 18:42:14 +09:00
|
|
|
use napi::{CallContext, JsNumber, JsObject, Result};
|
2020-09-30 15:34:26 +09:00
|
|
|
|
|
|
|
#[js_function(2)]
|
|
|
|
fn bench_plus(ctx: CallContext) -> Result<JsNumber> {
|
|
|
|
let a: u32 = ctx.get::<JsNumber>(0)?.try_into()?;
|
|
|
|
let b: u32 = ctx.get::<JsNumber>(1)?.try_into()?;
|
|
|
|
ctx.env.create_uint32(a + b)
|
|
|
|
}
|
|
|
|
|
2020-11-25 18:42:14 +09:00
|
|
|
pub fn register_js(exports: &mut JsObject) -> Result<()> {
|
|
|
|
exports.create_named_method("plus", bench_plus)?;
|
2020-09-30 15:34:26 +09:00
|
|
|
Ok(())
|
|
|
|
}
|