napi

napi@2.0.2

What's Changed

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.0.1...napi@2.0.2

napi@2.0.1

What's Changed

New Contributors

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@2.0.0...napi@2.0.1

napi@2.0.0

Breaking changes

Task trait

The fn resolve and fn reject methods of Task trait now accepted &mut self rather thant self. Because we introduced a new fn finally method on it.

struct BufferLength(Ref<JsBufferValue>);

impl Task for BufferLength {
  type Output = usize;
  type JsValue = JsNumber;

  fn compute(&mut self) -> Result<Self::Output> {
    Ok(self.0.len() + 1)
  }

-  fn resolve(self, env: Env, output: Self::Output) -> Result<Self::JsValue> {
-    self.0.unref(env)?;
+  fn resolve(&mut self, env: Env, output: Self::Output) -> Result<Self::JsValue> {
    env.create_uint32(output as u32)
   }

-  fn reject(self, err: Error) -> Result<Self::JsValue> {
-    self.0.unref(env)?;
-    Err(err)
-  }

+  fn finally(&mut self, env: Env) -> Result<()> {
+    self.0.unref(env)?;
+    Ok(())
+  }
}

Property::new

Property::new now accept single name: &str:

- Property::new(&env, "name)
+ Property::new("name")

Features

See Announcing NAPI-RS v2

napi@1.8.0

Features

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@1.7.11...napi@1.8.0

napi@1.7.11

Bugfix

Full Changelog: https://github.com/napi-rs/napi-rs/compare/napi@1.7.10...napi@1.7.11

napi@1.7.10

Bugfix

napi@1.7.9

Bugfix

napi@1.7.8

Features

Throw SyntaxError:

#[js_function(1)]
pub fn throw_syntax_error(ctx: CallContext) -> Result<JsUndefined> {
  let message: JsString = ctx.get(0)?;
  let syntax_error = ctx
    .env
    .get_global()?
    .get_named_property::<JsFunction>("SyntaxError")?;
  ctx.env.throw(syntax_error.new(&[message])?)?;
  ctx.env.get_undefined()
}

napi@1.7.7

Bugfix

  • fix(napi): drop_wrapped implementation 5fe8003

napi@1.7.6

Bugfix

  • fix(napi): utf16 value should not contains 0 terminate #697

Performance

  • perf(napi): make FuturePromise static dispatch #621

napi@1.7.5

Perf

  • perf(napi): reduce tokio future execution overhead #597

napi@1.7.4

Chore

  • chore(napi): remove useless build dependencies

napi@1.7.3

Bugfix

  • fix(napi): JsString* leak in from_js_value #584

napi@1.7.2

Bugfix

  • Allow dropping of string&buffer values when converting #582

napi@1.7.1

Bugfix

  • fix(napi): wrong memory location of data in future resolved callback #579

napi@1.7.0

Feature

  • feat(napi): impl more types AsRef and AsMut for TypedArray #578

Refactor

  • refactor(napi): change more generic constraint from NapiValue => NapiRaw #565

napi@1.6.1

Chore

  • chore(napi): upgrade once_cell

napi@1.6.0

Feature

napi8 feature added into napi crate.

Chore

  • Node.js@10 and Node.js@15 removed from CI.

napi@1.5.0

Feature

  • feat(napi): expose create_string_from_c_char for C ffi scenario d1bcecc

Fix

  • fix(napi): memory ordering issues in tsfn 5a21bbe

napi@1.4.0

Feature

  • refactor(napi): split NapiRaw trait from NapiValue #524

napi@1.3.4

Bugfix

  • fix(napi): do not call release tsfn in Drop when ref count is 0 #522

napi@1.3.3

Bugfix

  • fix(napi): finalizer maybe_ref pointer value f45f1ae
  • Add a way to convert stateful (Rust) closures into JsFunction 4aba159

Docs

  • Remove deprecated register_module from example in README.md 5527451

napi@1.3.2

Bugfix

  • fix(napi): napi_adjust_external_memory issue on wini686. 1e3290c

napi@1.3.1

Bugfix

  • fix(napi): InvalidArg error when create_external with size hint. 50f207f

napi@1.3.0

Feature

  • Add a way to opt out of error handling for ThreadsafeFunction #500

napi@1.2.0

Feature

  • feat(napi): unwrap &'static value from Ref object e622d96
  • feat(napi): add back clone trait to ThreadsafeFunction 071dcff

Chore

  • chore(napi): relax the tokio version from 1.1 to 1. c39b364

napi@1.1.3

Chore

  • chore(napi): upgrade tokio to 1.1 2775b47

napi@1.1.2

Bugfix

  • fix(napi): throw JavaScript error in tsfn rather than rust thread panic f46aa1f

napi@1.1.1

Feature

  • Implement Copy and Clone trait for JavaScript Primitive types. c121537

Bugfix

  • Remove unexpected into_*_ref from JsString. e24738a

napi@1.1.0

Feature

  • Implement Env::create_arraybuffer_with_borrowed_data for ffi scenario. 911a0c1

napi@1.0.1

Bugfix

  • enable napi4 feature when tokio_rt enabled.
  • Remove unexpected napi_acquire_threadsafe_function in Env::execute_tokio_future which would prevent Node.js process to exit: #397

napi@1.0.0

Breaking changes

Module register

The old way:

register_module!(test_module, init);

fn init(module: &mut Module) -> Result<()> {
  // ....
  Ok(())
}

The new way:

#[module_exports]
fn init(mut exports: JsObject) -> Result<()> {
  // ...
  Ok(())
}

or

#[module_exports]
fn init(mut exports: JsObject, env: Env) -> Result<()> {
  // ...
  Ok(())
}

Task

- pub trait Task: Send {
+ pub trait Task: Send + Sized {
    type Output: Send + Sized + 'static;
    type JsValue: NapiValue;


-   fn compute(&self) -> Result<Self::Output>;
+   fn compute(&mut self) -> Result<Self::Output>;


-   fn resolve(&self, env: &mut Env, output: Self::Output) -> Result<Self::JsValue>;
+   fn resolve(self, env: Env, output: Self::Output) -> Result<Self::JsValue>;


+   fn reject(self, _env: Env, err: Error) -> Result<Self::JsValue> {
+     Err(err)
+   }
}