napi-derive

js_function

```rust

[macro_use]

extern crate napi_derive;

use napi::{CallContext, Error, JsNumber, JsUnknown, Module, Result, Status}; use std::convert::TryInto;

[module_exports]

fn init(mut exports: JsObject) -> Result<()> { exports.createnamedmethod("testThrow", testthrow)?; exports.createnamed_method("fibonacci", fibonacci)?; Ok(()) }

[js_function]

fn testthrow(ctx: CallContext) -> Result { Err(Error::from_status(Status::GenericFailure)) }

[js_function(1)]

fn fibonacci(ctx: CallContext) -> Result { let n = ctx.get::(0)?.tryinto()?; ctx.env.createint64(fibonacci_native(n)) }

[inline]

fn fibonaccinative(n: i64) -> i64 { match n { 1 | 2 => 1, _ => fibonaccinative(n - 1) + fibonacci_native(n - 2), } } ```