A minimal library for building compiled Node.js add-ons in Rust via Node-API

Overview

napi-rs

Stake to support us chat

This project was initialized from xray

A minimal library for building compiled Node.js add-ons in Rust.

Ecosystem

Prisma     swc     Parcel   next.js   nextjs.svg

Platform Support

Lint Linux N-API@3 Linux musl macOS/Windows/Linux x64 Linux-aarch64 Linux-armv7 macOS-Android Windows i686 Windows arm64 FreeBSD

node12 node14 node16
Windows x64
Windows x86
Windows arm64
macOS x64
macOS aarch64
Linux x64 gnu
Linux x64 musl
Linux aarch64 gnu
Linux aarch64 musl
Linux arm gnueabihf
Linux aarch64 android
FreeBSD x64

This library depends on Node-API and requires [email protected] or later.

We already have some packages written by napi-rs: node-rs

One nice feature is that this crate allows you to build add-ons purely with the Rust/JavaScript toolchain and without involving node-gyp.

Taste

You can start from package-template to play with napi-rs

Define JavaScript functions

#[macro_use]
extern crate napi;

// import the preludes
use napi::bindgen_prelude::*;

/// module registerion is done by the runtime, no need to explicitly do it now.
#[napi]
fn fibonacci(n: u32) -> u32 {
  match n {
    1 | 2 => 1,
    _ => fibonacci_native(n - 1) + fibonacci_native(n - 2),
  }
}

/// use `Fn`, `FnMut` or `FnOnce` traits to defined JavaScript callbacks
/// the return type of callbacks can only be `Result`.
#[napi]
fn get_cwd
   Fn(
   String) -> 
   Result<()>>(callback: T) {
  
   callback(env
   ::
   current_dir().
   unwrap().
   to_string_lossy().
   to_string()).
   unwrap();
}


   /// or, define the callback signature in where clause
#[napi]

   fn 
   test_callback
   
    (callback: T)

    where T: 
    Fn(
    String) -> 
    Result<()>
{}
   
  

Checkout more examples in examples folder

Building

This repository is a Cargo crate. Any napi-based add-on should contain Cargo.toml to make it a Cargo crate.

In your Cargo.toml you need to set the crate-type to "cdylib" so that cargo builds a C-style shared library that can be dynamically loaded by the Node executable. You'll also need to add this crate as a dependency.

[package]
name = "awesome"

[lib]
crate-type = ["cdylib"]

[dependencies]
napi = "2"
napi-derive = "2"

[build-dependencies]
napi-build = "1"

And create build.rs in your own project:

// build.rs
extern crate napi_build;

fn main() {
  napi_build::setup();
}

So far, the napi build script has only been tested on macOS Linux Windows x64 MSVC and FreeBSD.

Install the @napi-rs/cli to help you build your Rust codes and copy Dynamic lib file to .node file in case you can require it in your program.

<----------- Config the name of native addon, or the napi command will use the name of `Cargo.toml` for the binary file name. }, "scripts": { "build": "napi build --release", "build:debug": "napi build" } } ">
{
  "package": "awesome-package",
  "devDependencies": {
    "@napi-rs/cli": "^1.0.0"
  },
  "napi": {
    "name": "jarvis" // <----------- Config the name of native addon, or the napi command will use the name of `Cargo.toml` for the binary file name.
  },
  "scripts": {
    "build": "napi build --release",
    "build:debug": "napi build"
  }
}

Then you can require your native binding:

require('./jarvis.node')

The module_name would be your package name in your Cargo.toml.

xxx => ./xxx.node

xxx-yyy => ./xxx_yyy.node

You can also copy Dynamic lib file to an appointed location:

napi build [--release] ./dll
napi build [--release] ./artifacts

There are documents which contains more details about the @napi-rs/cli usage.

Testing

Because libraries that depend on this crate must be loaded into a Node executable in order to resolve symbols, all tests are written in JavaScript in the test_module subdirectory.

To run tests:

yarn build:test
yarn test

Related projects

Features table

Rust Type Node Type NAPI Version Minimal Node version
u32 Number 1 v8.0.0
i32/i64 Number 1 v8.0.0
f64 Number 1 v8.0.0
bool Boolean 1 v8.0.0
String/&'a str String 1 v8.0.0
Latin1String String 1 v8.0.0
UTF16String String 1 v8.0.0
Object Object 1 v8.0.0
Array Array 1 v8.0.0
Vec Array 1 v8.0.0
Buffer Buffer 1 v8.0.0
Null null 1 v8.0.0
Undefined/() undefined 1 v8.0.0
Result<()> Error 1 v8.0.0
T: Fn(...) -> Result function 1 v8.0.0
(NOT YET) global 1 v8.0.0
(NOT YET) Symbol 1 v8.0.0
(NOT YET) Promise 1 b8.5.0
(NOT YET) ArrayBuffer/TypedArray 1 v8.0.0
(NOT YET) threadsafe function 4 v10.6.0
(NOT YET) BigInt 6 v10.7.0
Comments
  • Build fails with 32bit target

    Build fails with 32bit target

    Trying to build for MSVC x86 due to loading 32bit Dlls on WIndows...

    This fails with the NAPI library being the cause. Attached is a log of the build process:

    Seems to compain a lot about expecting u32 but finding u64

    build_log.txt

    bug 
    opened by rnd-ash 25
  • `#[napi]` questions

    `#[napi]` questions

    Hello I have some questions about the new #[napi]:

    • how to make a class with a static method that returns an instance (which is not the constructor, of course)
    • how to export a const/static?
    • ...I have (or probably will have) more, but these are the only ones that come to mind at the moment.

    Thanks a lot for your work!

    opened by Mesteery 17
  • Possible memory leak in value handling

    Possible memory leak in value handling

    We've had a user reporting unusually high memory usage, growing slowly in their use. I tried to reduce this to the minimal, and I think what I have in this test repo will reveal the leak:

    https://github.com/pimeys/napi-bug-repo

    I included a massif dump from valgrind in the repo to see it for yourself, but basically we just consume more memory, without collecting at any point.

    Here's the original user issue, which is kind of lot to build for testing. But I see similar trend from the user project:

    https://github.com/prisma/prisma/issues/7092

    I hope the reduced example is enough for you to debug!

    bug 
    opened by pimeys 14
  • exit 3221225477 running with nodejs x32 on windows 64 in release mode

    exit 3221225477 running with nodejs x32 on windows 64 in release mode

    Everything is just fine in debug mode, but node.exe exit with status 1 while loading the .node file compiled with --release flag

    See https://github.com/napi-rs/package-template/actions/runs/361398266

    bug 
    opened by Brooooooklyn 14
  • Pattern `napi_bigint` not covered

    Pattern `napi_bigint` not covered

    I am really new to rust and all that universe.

    i tried to install napi and so on, but i get:

    error[E0004]: non-exhaustive patterns: `napi_bigint` not covered
       --> ../.cargo/registry/src/github.com-1ecc6299db9ec823/napi-0.5.1/src/js_values/value_type.rs:46:11
        |
    46  |     match value {
        |           ^^^^^ pattern `napi_bigint` not covered
        | 
       ::: ../target/debug/build/napi-sys-c52f7ba1a7f9b699/out/bindings.rs:358:5
        |
    358 |     napi_bigint = 9,
        |     ----------- not covered
        |
        = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
        = note: the matched value is of type `napi_sys::napi_valuetype`
    

    Thanks :)

    bug 
    opened by KillerCodeMonkey 14
  • ThreadsafeFunction not available

    ThreadsafeFunction not available

    Hey @Brooooooklyn, tried to follow this example, but I can't use ThreadsafeFunction.

    no method named `create_threadsafe_function` found for reference `&napi::Env` in the current scope
    method not found in `&napi::Env`
    

    I have version 5.1 installed, does only 4.x support these methods?

    opened by martonlanga 11
  • Node Addon Crashed, Segmentation fault: 11

    Node Addon Crashed, Segmentation fault: 11

    napi-rs 是个很赞的项目,目前我在Electron内用来开发mac及Windows平台的原生node扩展,目前遇到一个(特定系统版本?)崩溃问题。

    问题描述:Mac OS X 10.15.3版本系统,Node Addon 崩溃,我尝试运行最简单的 addplus 扩展,依旧是崩溃的。在高版本的macOS系统上,运行正常。

    Electron版本:12.2.3 Node版本:14.16.0

    下面是崩溃日志,修改了部分敏感数据。

    ==================================================== Process: MyTestapp [5672] Path: /Applications/MyTestapp.app/Contents/MacOS/MyTestapp Identifier: my-test-app Version: 1.21.1-stable.1046709 (1046709) Code Type: X86-64 (Native) Parent Process: ??? [1] Responsible: MyTestapp [5672] User ID: 501

    Date/Time: 2022-09-13 17:06:00.816 +0800 OS Version: Mac OS X 10.15.3 (19D2064) Report Version: 12 Bridge OS Version: 4.3 (17P3561) Anonymous UUID: 0EA8FECE-F9FB-333C-F0B1-F98AFB3E85A7

    Sleep/Wake UUID: C64AD8EA-BA0A-4859-A172-B43E2DC5531B

    Time Awake Since Boot: 23000 seconds Time Since Wake: 4500 seconds

    System Integrity Protection: enabled

    Crashed Thread: 0 Dispatch queue: com.apple.main-thread

    Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: EXC_I386_GPFLT Exception Note: EXC_CORPSE_NOTIFY

    Termination Signal: Segmentation fault: 11 Termination Reason: Namespace SIGNAL, Code 0xb Terminating Process: exc handler [5672]

    Application Specific Information: /Applications/MyTestapp.app/Contents/Resources/app.asar.unpacked/node_modules/@pkgscope/my-lib/bin/darwin-x64/my-lib.darwin-x64.node

    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 my-lib.darwin-x64.node 0x0000000119b6f634 DYLD-STUB$$malloc + 0 1 dyld 0x00000001197f1320 ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 990 2 dyld 0x00000001197f1582 ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40 3 dyld 0x00000001197ebdc7 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 493 4 dyld 0x00000001197e9e58 ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 188 5 dyld 0x00000001197e9ef8 ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 82 6 dyld 0x00000001197dbf87 dyld::runInitializers(ImageLoader*) + 82 7 dyld 0x00000001197e5ad7 dlopen_internal + 609 8 libdyld.dylib 0x00007fff6dc8fa7f dlopen + 171 9 com.github.Electron.framework 0x000000010ea3ec58 node::binding::get_linked_module(char const*) + 3432 10 com.github.Electron.framework 0x000000010ea3d9d5 node_module_register + 2453 11 com.github.Electron.framework 0x000000010c9811c0 v8::internal::ClassScope::ResolvePrivateNamesPartially() + 14832 12 com.github.Electron.framework 0x000000010c980e15 v8::internal::ClassScope::ResolvePrivateNamesPartially() + 13893 13 com.github.Electron.framework 0x000000010c980493 v8::internal::ClassScope::ResolvePrivateNamesPartially() + 11459 14 com.github.Electron.framework 0x000000010cfdfd38 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 451304 15 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 16 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 17 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 18 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 19 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 20 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 21 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 22 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 23 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 24 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 25 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 26 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 27 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 28 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 29 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 30 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 31 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 32 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 33 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 34 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 35 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 36 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 37 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 38 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 39 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 40 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 41 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 42 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 43 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 44 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 45 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 46 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 47 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 48 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 49 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 50 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 51 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 52 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 53 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 54 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 55 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 56 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 57 com.github.Electron.framework 0x000000010cf79c0f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 33215 58 com.github.Electron.framework 0x000000010cf7787b v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 24107 59 com.github.Electron.framework 0x000000010cf77658 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 23560 60 com.github.Electron.framework 0x000000010c9da714 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handlev8::internal::Object, v8::internal::Handlev8::internal::Object, int, v8::internal::Handlev8::internal::Object) + 916 61 com.github.Electron.framework 0x000000010c9da41a v8::internal::Execution::Call(v8::internal::Isolate, v8::internal::Handlev8::internal::Object, v8::internal::Handlev8::internal::Object, int, v8::internal::Handlev8::internal::Object) + 154 62 com.github.Electron.framework 0x000000010c95781c v8::Function::Call(v8::Localv8::Context, v8::Localv8::Value, int, v8::Localv8::Value) + 332 63 com.github.Electron.framework 0x000000010ea355ac napi_is_detached_arraybuffer + 40396 64 com.github.Electron.framework 0x000000010ea3670a napi_is_detached_arraybuffer + 44842 65 com.github.Electron.framework 0x000000010ea3632c napi_is_detached_arraybuffer + 43852 66 com.github.Electron.framework 0x000000010e9d918e node::LoadEnvironment(node::Environment*) + 78 67 com.github.Electron.framework 0x000000010c484c7a ElectronInitializeICUandStartNode + 1388026 68 com.github.Electron.framework 0x000000010c401977 ElectronInitializeICUandStartNode + 850679 69 com.github.Electron.framework 0x000000010d18441c v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 2173388 70 com.github.Electron.framework 0x000000010d187f20 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 2188496 71 com.github.Electron.framework 0x000000010d183b97 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 2171207 72 com.github.Electron.framework 0x000000010c8e6a36 electron::fuses::IsRunAsNodeEnabled() + 4146790 73 com.github.Electron.framework 0x000000010c8e6743 electron::fuses::IsRunAsNodeEnabled() + 4146035 74 com.github.Electron.framework 0x000000010c8e5410 electron::fuses::IsRunAsNodeEnabled() + 4141120 75 com.github.Electron.framework 0x000000010c8e58d2 electron::fuses::IsRunAsNodeEnabled() + 4142338 76 com.github.Electron.framework 0x000000010c331e48 ElectronMain + 136 77 my-test-app 0x000000010c2b6426 0x10c2b3000 + 13350 78 libdyld.dylib 0x00007fff6dca47fd start + 1

    Thread 1: 0 libsystem_pthread.dylib 0x00007fff6dea4818 start_wqthread + 0

    Thread 2: 0 libsystem_pthread.dylib 0x00007fff6dea4818 start_wqthread + 0

    Thread 3: 0 libsystem_pthread.dylib 0x00007fff6dea4818 start_wqthread + 0

    Thread 4: 0 libsystem_pthread.dylib 0x00007fff6dea4818 start_wqthread + 0

    Thread 5:: ThreadPoolServiceThread 0 libsystem_kernel.dylib 0x00007fff6ddee072 kevent64 + 10 1 com.github.Electron.framework 0x000000010d57559a v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6306634 2 com.github.Electron.framework 0x000000010d5754be v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6306414 3 com.github.Electron.framework 0x000000010d531d8f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6030143 4 com.github.Electron.framework 0x000000010d50f0a9 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5887577 5 com.github.Electron.framework 0x000000010d53ab8d v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6066493 6 com.github.Electron.framework 0x000000010d54b179 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6133545 7 com.github.Electron.framework 0x000000010d560c88 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6222392 8 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 9 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 6:: ThreadPoolForegroundWorker 0 libsystem_kernel.dylib 0x00007fff6dde525a mach_msg_trap + 10 1 libsystem_kernel.dylib 0x00007fff6dde55d0 mach_msg + 60 2 com.github.Electron.framework 0x000000010d568c67 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6255127 3 com.github.Electron.framework 0x000000010d54299e v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6098766 4 com.github.Electron.framework 0x000000010d5431aa v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6100826 5 com.github.Electron.framework 0x000000010d542ead v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6100061 6 com.github.Electron.framework 0x000000010d560c88 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6222392 7 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 8 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 7:: ThreadPoolBackgroundWorker 0 libsystem_kernel.dylib 0x00007fff6dde525a mach_msg_trap + 10 1 libsystem_kernel.dylib 0x00007fff6dde55d0 mach_msg + 60 2 com.github.Electron.framework 0x000000010d568c67 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6255127 3 com.github.Electron.framework 0x000000010d54299e v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6098766 4 com.github.Electron.framework 0x000000010d542fd1 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6100353 5 com.github.Electron.framework 0x000000010d542e4d v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6099965 6 com.github.Electron.framework 0x000000010d560c88 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6222392 7 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 8 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 8:: ThreadPoolForegroundWorker 0 libsystem_kernel.dylib 0x00007fff6dde525a mach_msg_trap + 10 1 libsystem_kernel.dylib 0x00007fff6dde55d0 mach_msg + 60 2 com.github.Electron.framework 0x000000010d568c67 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6255127 3 com.github.Electron.framework 0x000000010d54299e v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6098766 4 com.github.Electron.framework 0x000000010d542fd1 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6100353 5 com.github.Electron.framework 0x000000010d542ead v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6100061 6 com.github.Electron.framework 0x000000010d560c88 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6222392 7 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 8 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 9:: Chrome_IOThread 0 libsystem_kernel.dylib 0x00007fff6ddee072 kevent64 + 10 1 com.github.Electron.framework 0x000000010d57559a v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6306634 2 com.github.Electron.framework 0x000000010d5754be v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6306414 3 com.github.Electron.framework 0x000000010d531d8f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6030143 4 com.github.Electron.framework 0x000000010d50f0a9 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5887577 5 com.github.Electron.framework 0x000000010d18881f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 2190799 6 com.github.Electron.framework 0x000000010d54b179 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6133545 7 com.github.Electron.framework 0x000000010d560c88 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6222392 8 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 9 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 10:: MemoryInfra 0 libsystem_kernel.dylib 0x00007fff6dde525a mach_msg_trap + 10 1 libsystem_kernel.dylib 0x00007fff6dde55d0 mach_msg + 60 2 com.github.Electron.framework 0x000000010d568c67 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6255127 3 com.github.Electron.framework 0x000000010d568aee v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6254750 4 com.github.Electron.framework 0x000000010d4f8500 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5794480 5 com.github.Electron.framework 0x000000010d531d8f v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6030143 6 com.github.Electron.framework 0x000000010d50f0a9 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 5887577 7 com.github.Electron.framework 0x000000010d54b179 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6133545 8 com.github.Electron.framework 0x000000010d560c88 v8::internal::SetupIsolateDelegate::SetupHeap(v8::internal::Heap*) + 6222392 9 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 10 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 11: 0 libsystem_kernel.dylib 0x00007fff6dde9bce kevent + 10 1 com.github.Electron.framework 0x000000010c33142a uv_free_interface_addresses + 1322 2 com.github.Electron.framework 0x000000010c32054c uv_run + 364 3 com.github.Electron.framework 0x000000010eacf0ef node::MultiIsolatePlatform::CancelPendingDelayedTasks(v8::Isolate*) + 687 4 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 5 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 12: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010eacf2c2 node::MultiIsolatePlatform::CancelPendingDelayedTasks(v8::Isolate*) + 1154 4 com.github.Electron.framework 0x000000010eaccb87 node::OnFatalError(char const*, char const*) + 438327 5 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 6 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 13: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010eacf2c2 node::MultiIsolatePlatform::CancelPendingDelayedTasks(v8::Isolate*) + 1154 4 com.github.Electron.framework 0x000000010eaccb87 node::OnFatalError(char const*, char const*) + 438327 5 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 6 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 14: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010eacf2c2 node::MultiIsolatePlatform::CancelPendingDelayedTasks(v8::Isolate*) + 1154 4 com.github.Electron.framework 0x000000010eaccb87 node::OnFatalError(char const*, char const*) + 438327 5 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 6 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 15: 0 libsystem_kernel.dylib 0x00007fff6dde5296 semaphore_wait_trap + 10 1 com.github.Electron.framework 0x000000010c32caa0 uv_sem_wait + 16 2 com.github.Electron.framework 0x000000010eb36383 node::SetTracingController(v8::TracingController*) + 65091 3 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 4 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 16: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010c31c6a0 uv_cancel + 512 4 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 5 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 17: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010c31c6a0 uv_cancel + 512 4 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 5 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 18: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010c31c6a0 uv_cancel + 512 4 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 5 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 19: 0 libsystem_kernel.dylib 0x00007fff6dde7ce6 __psynch_cvwait + 10 1 libsystem_pthread.dylib 0x00007fff6dea9185 _pthread_cond_wait + 701 2 com.github.Electron.framework 0x000000010c32c4f9 uv_cond_wait + 9 3 com.github.Electron.framework 0x000000010c31c6a0 uv_cancel + 512 4 libsystem_pthread.dylib 0x00007fff6dea8e65 _pthread_start + 148 5 libsystem_pthread.dylib 0x00007fff6dea483b thread_start + 15

    Thread 0 crashed with X86 Thread State (64-bit): rax: 0x000000011986c268 rbx: 0x000000011990e8d0 rcx: 0x00007ffee394cc50 rdx: 0x00007ffee394cbf8 rdi: 0x0000000000000070 rsi: 0x00007ffee394cbe8 rbp: 0x00007ffee3944120 rsp: 0x00007ffee3944068 r8: 0x000000011986c330 r9: 0x0000000000000000 r10: 0x0000000000000000 r11: 0x0000000000000000 r12: 0x00007fff96997218 r13: 0x00007ffee39441a0 r14: 0x0000000000000000 r15: 0x0000000000000000 rip: 0x0000000119b6f634 rfl: 0x0000000000010202 cr2: 0x000000011990e8d0

    Logical CPU: 6 Error Code: 0x00000000 Trap Number: 13

    Binary Images: 0x10c2b3000 - 0x10c306fdb +my-test-app (1.21.1-stable.1046709 - 1046709) /Applications/MyTestapp.app/Contents/MacOS/MyTestapp 0x10c318000 - 0x113d7ff0f +com.github.Electron.framework (12.2.3) /Applications/MyTestapp.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Electron Framework 0x114760000 - 0x11479bfff +com.github.Squirrel (1.0 - 1) /Applications/MyTestapp.app/Contents/Frameworks/Squirrel.framework/Versions/A/Squirrel 0x1147b4000 - 0x11481fff7 +com.electron.reactive (3.1.0 - 0.0.0) <88230766-080F-3E3C-8298-916D321C7C58> /Applications/MyTestapp.app/Contents/Frameworks/ReactiveObjC.framework/Versions/A/ReactiveObjC 0x114848000 - 0x11487bff7 +org.mantle.Mantle (1.0 - 0.0.0) /Applications/MyTestapp.app/Contents/Frameworks/Mantle.framework/Versions/A/Mantle 0x114891000 - 0x114b28ff7 +libffmpeg.dylib (0) /Applications/MyTestapp.app/Contents/Frameworks/Electron Framework.framework/Versions/A/Libraries/libffmpeg.dylib 0x1197d6000 - 0x119866cb7 dyld (733.8) <7F9973C3-4B94-3AEF-AD06-C2F09263733C> /usr/lib/dyld 0x1198da000 - 0x119c4d537 +my-lib.darwin-x64.node (0) /Applications/MyTestapp.app/Contents/Resources/app.asar.unpacked/node_modules/@pkgscope/my-lib/bin/darwin-x64/my-lib.darwin-x64.node 0x7fff298a4000 - 0x7fff298b3ff7 libSimplifiedChineseConverter.dylib (76) <87C156B8-C1C6-3D73-A09E-109F059EE010> /System/Library/CoreServices/Encodings/libSimplifiedChineseConverter.dylib 0x7fff31ef5000 - 0x7fff320eeff1 com.apple.avfoundation (2.0 - 1750.3) <4BA5F379-F35E-36E2-BA5A-E46592CB8B92> /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation 0x7fff320ef000 - 0x7fff321bbff8 com.apple.audio.AVFAudio (1.0 - ???) /System/Library/Frameworks/AVFoundation.framework/Versions/A/Frameworks/AVFAudio.framework/Versions/A/AVFAudio 0x7fff322db000 - 0x7fff322dbfff com.apple.Accelerate (1.11 - Accelerate 1.11) /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate 0x7fff322f3000 - 0x7fff3295efef com.apple.vImage (8.1 - 524.2) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage 0x7fff3295f000 - 0x7fff32bc8fff libBLAS.dylib (1303.60.1) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 0x7fff32bc9000 - 0x7fff32eb8ff7 libBNNS.dylib (144.40.3) <1E5D4826-EB84-3E89-BB90-C034F57B73C8> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBNNS.dylib 0x7fff32eba000 - 0x7fff3325ffff libLAPACK.dylib (1303.60.1) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib 0x7fff33260000 - 0x7fff33275ff8 libLinearAlgebra.dylib (1303.60.1) <8ED0ED54-727A-3E26-9ED5-9F3412386290> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLinearAlgebra.dylib 0x7fff33276000 - 0x7fff3327bff3 libQuadrature.dylib (7) <867F4640-738A-32BD-B01D-C9BC1F3679A0> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libQuadrature.dylib 0x7fff3327c000 - 0x7fff332ecfff libSparse.dylib (103) <9F075934-56FA-39D2-B497-EF3AA514F6F3> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libSparse.dylib 0x7fff332ed000 - 0x7fff332fffef libSparseBLAS.dylib (1303.60.1) <37C65F9E-FCBF-3FCF-96A6-25A415D6E321> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libSparseBLAS.dylib 0x7fff33300000 - 0x7fff334d9ffb libvDSP.dylib (735.40.1) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib 0x7fff334da000 - 0x7fff33595fd7 libvMisc.dylib (735.40.1) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib 0x7fff33596000 - 0x7fff33596fff com.apple.Accelerate.vecLib (3.11 - vecLib 3.11) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib 0x7fff33597000 - 0x7fff335f6ffc com.apple.Accounts (113 - 113) <52895808-567E-33E0-9FFE-6AADF5BB296B> /System/Library/Frameworks/Accounts.framework/Versions/A/Accounts 0x7fff3373c000 - 0x7fff344f7fff com.apple.AppKit (6.9 - 1894.30.142) /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit 0x7fff34547000 - 0x7fff34547fff com.apple.ApplicationServices (48 - 50) <3B86C07B-0396-35CA-BBD5-26BFCCF10B1B> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices 0x7fff34548000 - 0x7fff345b3fff com.apple.ApplicationServices.ATS (377 - 493.0.2.1) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/ATS 0x7fff3464c000 - 0x7fff3468aff8 libFontRegistry.dylib (274.0.2.3) <227A4DD9-932E-3A95-A890-D0B11D148CB7> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontRegistry.dylib 0x7fff346e5000 - 0x7fff34714ff7 com.apple.ATSUI (1.0 - 1) <781A8FCE-373E-3B3C-96CB-398B2D72E082> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATSUI.framework/Versions/A/ATSUI 0x7fff34715000 - 0x7fff34719ff3 com.apple.ColorSyncLegacy (4.13.0 - 1) <8D37759B-3F8F-3344-B5AD-BB4282D0A4AB> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSyncLegacy.framework/Versions/A/ColorSyncLegacy 0x7fff347b4000 - 0x7fff3480aff2 com.apple.HIServices (1.22 - 674.1) <71E6A6FF-0152-3FCE-AE09-5A7F3F80D41E> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices 0x7fff3480b000 - 0x7fff34819fff com.apple.LangAnalysis (1.7.0 - 1.7.0) <480935CD-E38F-306B-9461-99A3BBCA997B> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LangAnalysis.framework/Versions/A/LangAnalysis 0x7fff3481a000 - 0x7fff3485fff2 com.apple.print.framework.PrintCore (15 - 516) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/PrintCore 0x7fff34860000 - 0x7fff3486afff com.apple.QD (4.0 - 413) <858B1BC0-60D3-3B9E-9C1B-D7A63CF56D28> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/QD.framework/Versions/A/QD 0x7fff3486b000 - 0x7fff34878ff0 com.apple.speech.synthesis.framework (9.0.24 - 9.0.24) <0F58C272-3B38-3C2B-80AC-78057A2439E7> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesis 0x7fff34879000 - 0x7fff34959ffa com.apple.audio.toolbox.AudioToolbox (1.14 - 1.14) <3FA8D008-415F-3DA7-9A40-8AD4F69517E0> /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox 0x7fff3495b000 - 0x7fff3495bfff com.apple.audio.units.AudioUnit (1.14 - 1.14) /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit 0x7fff34cd1000 - 0x7fff3505dffe com.apple.CFNetwork (1121.2 - 1121.2) /System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork 0x7fff350d8000 - 0x7fff350d8fff com.apple.Carbon (160 - 162) /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon 0x7fff350d9000 - 0x7fff350dcffb com.apple.CommonPanels (1.2.6 - 101) <7AE19FA2-7763-3218-8220-373A3D597EEF> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/CommonPanels.framework/Versions/A/CommonPanels 0x7fff350dd000 - 0x7fff353d1ffb com.apple.HIToolbox (2.1.1 - 994) <4AFB7800-EA9E-38EE-93AD-BA45E687676F> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/HIToolbox 0x7fff353d2000 - 0x7fff353d5ff3 com.apple.help (1.3.8 - 68) <165F7A9F-D951-30E0-B0EB-B927DFA0513A> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Help.framework/Versions/A/Help 0x7fff353d6000 - 0x7fff353dbff7 com.apple.ImageCapture (9.0 - 1600.27.1) /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/ImageCapture.framework/Versions/A/ImageCapture 0x7fff353dc000 - 0x7fff353dcfff com.apple.ink.framework (10.15 - 227) <1681B8D8-6E34-355F-8101-60275674C209> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Ink.framework/Versions/A/Ink 0x7fff353dd000 - 0x7fff353f7ff2 com.apple.openscripting (1.7 - 185.1) <16A1FF21-7B1C-3038-8302-82D2E17F92A3> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/OpenScripting.framework/Versions/A/OpenScripting 0x7fff35418000 - 0x7fff35418fff com.apple.print.framework.Print (15 - 271) /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/Print.framework/Versions/A/Print 0x7fff35419000 - 0x7fff3541bff7 com.apple.securityhi (9.0 - 55008) <084B846F-AAD2-3920-8736-7EF36E0E5C93> /System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/SecurityHI.framework/Versions/A/SecurityHI 0x7fff3541c000 - 0x7fff35422ff7 com.apple.speech.recognition.framework (6.0.3 - 6.0.3) <4482D9CC-D16B-364F-8DA0- ......

    External Modification Summary: Calls made by other processes targeting this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by this process: task_for_pid: 0 thread_create: 0 thread_set_state: 0 Calls made by all processes on this machine: task_for_pid: 19634 thread_create: 0 thread_set_state: 0

    VM Region Summary: ReadOnly portion of Libraries: Total=791.9M resident=0K(0%) swapped_out_or_unallocated=791.9M(100%) Writable regions: Total=777.0M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=777.0M(100%)

                                VIRTUAL   REGION 
    

    REGION TYPE SIZE COUNT (non-coalesced) =========== ======= ======= Activity Tracing 256K 1 Kernel Alloc Once 8K 1 MALLOC 209.8M 48 MALLOC guard page 16K 3 MALLOC_NANO (reserved) 384.0M 1 reserved VM address space (unallocated) Memory Tag 255 4.0G 50 STACK GUARD 56.1M 20 Stack 122.2M 20 VM_ALLOCATE 68K 3 __DATA 55.7M 446 __DATA_CONST 116K 2 __FONT_DATA 4K 1 __LINKEDIT 360.3M 13 __OBJC_RO 32.0M 1 __OBJC_RW 1780K 2 __TEXT 431.6M 428 __UNICODE 564K 1 mapped file 54.6M 9 shared memory 640K 15 =========== ======= ======= TOTAL 5.7G 1065 TOTAL, minus reserved VM space 5.3G 1065

    Model: MacBookAir9,1, BootROM 1037.87.10.0.0 (iBridge: 17.16.13561.0.0,0), 4 processors, Quad-Core Intel Core i5, 1.1 GHz, 8 GB, SMC Graphics: kHW_IntelIrisPlusGraphicsItem, Intel Iris Plus Graphics, spdisplays_builtin Memory Module: BANK 0/ChannelA-DIMM0, 4 GB, LPDDR4, 3733 MHz, Samsung, K3UH5H50MM-JGCJ Memory Module: BANK 2/ChannelB-DIMM0, 4 GB, LPDDR4, 3733 MHz, Samsung, K3UH5H50MM-JGCJ

    USB Device: Apple T2 Controller Thunderbolt Bus: MacBook Air, Apple Inc., 79.0

    opened by niugm 9
  • link error with cargo test when I update napi to v2

    link error with cargo test when I update napi to v2

    It appears when I perform the cargo test. Some error like this:

    error: linking with `cc` failed: exit status: 1
      |
      = note: "cc" "-m64" "-arch" "x86_64"
    
     = note: Undefined symbols for architecture x86_64:
                "_napi_resolve_deferred", referenced from:
                    napi::async_work::complete::h58b79f8133f186b3 in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::complete::hde2ad72b68199f5e in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                "_napi_create_object", referenced from:
                    napi::async_work::run::h57508fc4ac0aa52b in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::run::h6b7c52897e415faf in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::env::Env::create_object::hce0207b3c83c96b9 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.14.rcgu.o)
                "_napi_delete_async_work", referenced from:
                    napi::async_work::complete::h58b79f8133f186b3 in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::complete::hde2ad72b68199f5e in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                "_napi_create_async_work", referenced from:
                    napi::async_work::run::h57508fc4ac0aa52b in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::run::h6b7c52897e415faf in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                "_napi_queue_async_work", referenced from:
                    napi::async_work::run::h57508fc4ac0aa52b in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::run::h6b7c52897e415faf in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                "_napi_create_error", referenced from:
                    napi::error::JsError::into_value::h0a8aceba48321f44 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.3.rcgu.o)
                "_napi_create_function", referenced from:
                    builder_swc::minify::__register__fn__minify_callback__::h6a476980ec60cfc0 in libbuilder_swc.rlib(builder_swc.s0ywgy6tvp412t0.rcgu.o)
                    builder_swc::minify::__register__fn__minify_sync_callback__::h0a46899311b535da in libbuilder_swc.rlib(builder_swc.s0ywgy6tvp412t0.rcgu.o)
                    napi::env::Env::create_function::h066624506c497338 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.14.rcgu.o)
                    builder_swc::transform::__register__fn__transform_callback__::h60478aa898e3bff8 in libbuilder_swc.rlib(builder_swc.2djjqd7zahstuzuf.rcgu.o)
                    builder_swc::transform::__register__fn__transform_sync_callback__::haa38ff9077aa9b45 in libbuilder_swc.rlib(builder_swc.2djjqd7zahstuzuf.rcgu.o)
                "_napi_get_buffer_info", referenced from:
                    _$LT$napi..bindgen_runtime..js_values..buffer..Buffer$u20$as$u20$napi..bindgen_runtime..js_values..FromNapiValue$GT$::from_napi_value::hb04ac6d07b129f20 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.3.rcgu.o)
                "_napi_get_cb_info", referenced from:
                    napi::bindgen_runtime::js_values::task::on_abort::hecf05a4313eaa393 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.4.rcgu.o)
                    napi::bindgen_runtime::callback_info::CallbackInfo$LT$_$GT$::new::h1103c82a67affbce in libbuilder_swc.rlib(builder_swc.4di0vqqldbe9ma9d.rcgu.o)
                    napi::bindgen_runtime::callback_info::CallbackInfo$LT$_$GT$::new::h458a9a38715aaa11 in libbuilder_swc.rlib(builder_swc.4di0vqqldbe9ma9d.rcgu.o)
                "_napi_throw", referenced from:
                    napi::error::JsError::throw_into::hc7742352c49bcfde in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.3.rcgu.o)
                "_napi_cancel_async_work", referenced from:
                    napi::bindgen_runtime::js_values::task::on_abort::hecf05a4313eaa393 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.4.rcgu.o)
                "_napi_get_value_string_utf8", referenced from:
                    napi::bindgen_runtime::js_values::string::_$LT$impl$u20$napi..bindgen_runtime..js_values..FromNapiValue$u20$for$u20$alloc..string..String$GT$::from_napi_value::hf524e90d294727ed in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.9.rcgu.o)
                "_napi_create_string_utf8", referenced from:
                    napi::bindgen_runtime::js_values::string::_$LT$impl$u20$napi..bindgen_runtime..js_values..ToNapiValue$u20$for$u20$alloc..string..String$GT$::to_napi_value::h41161b888a1bf027 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.9.rcgu.o)
                    napi::error::JsError::into_value::h0a8aceba48321f44 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.3.rcgu.o)
                "_napi_reject_deferred", referenced from:
                    napi::bindgen_runtime::js_values::task::on_abort::hecf05a4313eaa393 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.4.rcgu.o)
                    napi::async_work::complete::h58b79f8133f186b3 in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::complete::hde2ad72b68199f5e in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                "_napi_set_named_property", referenced from:
                    napi::bindgen_runtime::js_values::object::_$LT$impl$u20$napi..js_values..object..JsObject$GT$::set::h5ceeea7cafe0a132 in libswc-1762586e81faaa32.rlib(swc-1762586e81faaa32.swc.1877be33-cgu.3.rcgu.o)
                    napi::bindgen_runtime::js_values::object::_$LT$impl$u20$napi..js_values..object..JsObject$GT$::set::hdff5ce6f1e7150a4 in libswc-1762586e81faaa32.rlib(swc-1762586e81faaa32.swc.1877be33-cgu.3.rcgu.o)
                    napi::js_values::_$LT$impl$u20$napi..js_values..object..JsObject$GT$::set_named_property::h9569681803e5713d in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.15.rcgu.o)
                "_napi_wrap", referenced from:
                    _$LT$napi..bindgen_runtime..js_values..task..AbortSignal$u20$as$u20$napi..bindgen_runtime..js_values..FromNapiValue$GT$::from_napi_value::ha0d059bdde43af14 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.4.rcgu.o)
                "_napi_typeof", referenced from:
                    _$LT$core..option..Option$LT$T$GT$$u20$as$u20$napi..bindgen_runtime..js_values..FromNapiValue$GT$::from_napi_value::h69e63d697f168a1c in libbuilder_swc.rlib(builder_swc.ajr9co34169d2qk.rcgu.o)
                "_napi_create_promise", referenced from:
                    napi::async_work::run::h57508fc4ac0aa52b in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                    napi::async_work::run::h6b7c52897e415faf in libbuilder_swc.rlib(builder_swc.oqswmtdhvaii0ps.rcgu.o)
                "_napi_unwrap", referenced from:
                    napi::bindgen_runtime::js_values::task::on_abort::hecf05a4313eaa393 in libnapi-504eadb5d635feaa.rlib(napi-504eadb5d635feaa.napi.cfcb64b2-cgu.4.rcgu.o)
                "_napi_get_null", referenced from:
                    _$LT$core..option..Option$LT$T$GT$$u20$as$u20$napi..bindgen_runtime..js_values..ToNapiValue$GT$::to_napi_value::h791109598c656da6 in libswc-1762586e81faaa32.rlib(swc-1762586e81faaa32.swc.1877be33-cgu.11.rcgu.o)
              ld: symbol(s) not found for architecture x86_64
              clang: error: linker command failed with exit code 1 (use -v to see invocation)
    

    The repo is here: https://github.com/ice-lab/swc/tree/swc/update-napi

    bug 
    opened by SoloJiang 9
  • Addon functions become undefined when addon is also required in a `worker_thread`

    Addon functions become undefined when addon is also required in a `worker_thread`

    It appears that when a napi-rs 2.0 module is required both on the main thread and in a worker_thread, exported functions can become undefined. I originally saw this issue in blake-hash, and found a reproduction case that I've tested on package-template and @node-rs/xxhash as well.

    I also tested the same reproduction case with @node-rs/xxhash v1.0.1 and the issue doesn't reproduce -- it works as expected on that version.

    Reproduction case

    Using commit d6bb01d from main branch of package-template:

    const { Worker, isMainThread } = require('worker_threads')
    
    // When testing, replace with path to a local build of package-template
    const template = require('/Users/dguenther/repos/package-template')
    
    if (isMainThread) {
        console.log('outside worker')
        new Worker(__filename)
    } else {
        console.log('inside worker')
    }
    
    console.log(template)
    if (template.plus100) {
        console.log(template.plus100(0))
    }
    

    Logs from running the reproduction case:

    outside worker
    { plus100: [Function: plus100] }
    100
    inside worker
    { plus100: undefined }
    
    bug 
    opened by dguenther 9
  • Issue building classes for windows ia32

    Issue building classes for windows ia32

    I was not able to get this example to run with ia32 (worked fine with x64 and I could build it on my mac as well.) https://github.com/napi-rs/napi-rs/blob/main/examples/napi/src/class.rs

    Even with a simple class along the lines of this. It builds fine, but even when I just call require('./index.node') it shuts down the program:

    use napi::bindgen_prelude::*;
    
    #[napi]
    pub struct MyClass(u32);
    
    #[napi]
    impl MyClass {
        #[napi(constructor)]
        pub fn new() -> Result<Self> {
            Ok(Self(13))
        }
    }
    
    napi = "2.0.0-beta.2"
    napi-derive = "2.0.0-beta.1"
    
    napi-build = "1.2"
    
    "@napi-rs/cli": "2.0.0-beta.3"
    

    Originally posted by @kyleshay in https://github.com/napi-rs/napi-rs/issues/896#issuecomment-985769190

    opened by kyleshay 9
  • [napi] serde + serde_json serialization / errors

    [napi] serde + serde_json serialization / errors

    This code should "just work"

    #[napi]
    #[derive(Serialize, Deserialize, Debug)]
    struct PackageJson {
      name: String,
      version: String,
      dependencies: Option<HashMap<String, String>>,
    }
    
    #[napi]
    fn read_package_json() -> Result<PackageJson> {
      let raw = fs::read_to_string("package.json")?;
      let p: PackageJson = serde_json::from_str(&raw)?;
      Ok(p)
    }
    
    opened by jaredpalmer 9
  • Debian docker image now requires GLIBC 2.35

    Debian docker image now requires GLIBC 2.35

    After our last release, we've received some reports that lightningcss and parcel won't load anymore on ARM systems (or docker containers) with Ubuntu 20.04 LTS (e.g. https://github.com/parcel-bundler/lightningcss/issues/335). I think this is because of this commit in the base docker image https://github.com/messense/manylinux-cross/commit/76f103138b2c65450b1d181318004203ef760ad5, where Ubuntu was upgrade to 22.04. When loading a binary that is compiled using this image, an error occurs if using an older version of Ubuntu/GLIBC.

    For now I've pinned us to an older version of the docker image: https://github.com/parcel-bundler/lightningcss/pull/342.

    Should the base image be pinned to a specific version so that the Ubuntu version doesn't change without warning? Ideally LTS versions would continue to be supported by default for binaries compiled using napi-rs images.

    opened by devongovett 0
  • Callback usage in factory method results in macro error

    Callback usage in factory method results in macro error

    If a callback is used for a factory method, this results in a macro error.

    #[napi]
    pub struct ConnectionId(quiche::ConnectionId<'static>);
    
    // ERROR AT THIS MACRO
    #[napi]
    impl ConnectionId {
      #[napi(factory)]
      pub fn random<T: Fn(Buffer) -> Result<()>>(get_random_values: T) -> Result<Self> {
        let scid = [0; quiche::MAX_CONN_ID_LEN].to_vec();
        let scid = Buffer::from(scid);
        get_random_values(scid.clone()).or_else(
          |err| Err(Error::from_reason(err.to_string()))
        )?;
        let scid = quiche::ConnectionId::from_vec(scid.to_vec());
        eprintln!("New connection with scid {:?}", scid.as_ref());
        return Ok(ConnectionId(scid));
      }
    }
    

    But if the same function is made just normal class method, then there's no error.

    The error is:

    cannot move out of `cb` because it is borrowed
    borrow of `cb` occurs here
    
    opened by CMCDragonkai 0
  • Support for Tuples and Tuple Struct

    Support for Tuples and Tuple Struct

    Is there a reason why we cannot export a tuple struct or tuple to the JS side?

    #[napi]
    pub fn plus_100(input: u32) -> (u32, u32) {
      (input, input)
    }
    
    #[napi]
    pub struct X(u32, u32);
    
    #[napi]
    pub fn plus_200(input: u32) -> X {
      X(input, input)
    }
    

    In the first case, the macro complains:

    the trait bound `(u32, u32): NapiRaw` is not satisfied
    required because of the requirements on the impl of `napi::bindgen_prelude::ToNapiValue` for `(u32, u32)`
    

    In the second case, the macros don't complain, but on the JS side, I get a X object with no properties...

    On the JS side I would be expecting a heterogeneous array of some sort.

    opened by CMCDragonkai 3
  • Can potentially create unsound async fn without any warnings in safe code

    Can potentially create unsound async fn without any warnings in safe code

    Hey! I was experimenting with some code and managed to (from my understanding) break some of rust's ownership rules with totally safe code. Here's a minimal example (requires tokio_rt and tokio_time features):

    Rust:

    use napi_derive::napi;
    use std::time::Duration;
    use napi::tokio::time::sleep;
    
    #[napi]
    #[derive(Default)]
    struct MyStruct {
    	value: i32
    }
    
    #[napi]
    impl MyStruct {
    	#[napi(constructor)]
    	pub fn new() -> Self { Default::default() }
    
    	#[napi]
    	pub async fn call_a(&mut self) {
    		println!("A start value: {}", self.value);
    		sleep(Duration::from_secs(1)).await;
    		self.value += 1;
    		sleep(Duration::from_secs(1)).await;
    		println!("A end value: {}", self.value);
    	}
    
    	#[napi]
    	pub async fn call_b(&mut self) {
    		println!("B start value: {}", self.value);
    		sleep(Duration::from_secs(1)).await;
    		self.value += 1;
    		sleep(Duration::from_secs(1)).await;
    		println!("B end value: {}", self.value);
    	}
    }
    

    Node:

    const { MyStruct } = require('./index.node');
    
    (async () => {
    	const a = new MyStruct();
    	let b = a.callA()
    	let c = a.callB();
    
    	await Promise.all([b, c]);
    })()
    

    When executing the node code, you get this output:

    A start value: 0
    B start value: 0
    A end value: 2
    B end value: 2
    

    This doesn't feel sound to me, as we have mutable ownership in multiple places simultaneously. Is this a problem? This feels like a case that should at least throw a runtime error, or have some form of internal synchronization (there may be, but I am not knowledgeable enough yet enough to discern this myself if there is)

    opened by Silvea12 1
  • Guidance on implementing NapiRaw/ToNapi for web_sys::{Request, Response}

    Guidance on implementing NapiRaw/ToNapi for web_sys::{Request, Response}

    I've got a large number of functions that take in a Request and return a Response, and I'd love to use napi-rs instead of a JS function. I was wondering if you had any guidance on the best way one might implement that or maybe even someone who already has. Thanks!

    question 
    opened by benwis 0
Releases(@napi-rs/[email protected])
  • @napi-rs/[email protected](Nov 20, 2022)

    What's Changed

    See https://napi.rs/docs/cross-build/summary

    • fix(cli): support help command by @ahaoboy in https://github.com/napi-rs/napi-rs/pull/1355
    • feat(cli): auto choose the tooling for cross compiling by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1367
    • chore(cli): upgrade Node.js dependencies by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1368

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@napi-rs/[email protected]

    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Nov 17, 2022)

  • [email protected](Nov 12, 2022)

    What's Changed

    • fix(napi): BigInt::get_u64 lossless check by @Wodann in https://github.com/napi-rs/napi-rs/pull/1348
    • chore(napi): including type message in error message by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1350
    • fix(cli): support help command by @ahaoboy in https://github.com/napi-rs/napi-rs/pull/1355
    • ci: test for zig 0.10 by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1360

    New Contributors

    • @ahaoboy made their first contribution in https://github.com/napi-rs/napi-rs/pull/1355
    • @SASUKE40 made their first contribution in https://github.com/napi-rs/napi-rs/pull/1364

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.1

    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Nov 12, 2022)

  • [email protected](Oct 4, 2022)

    What's Changed

    • chore: fix ci for forked repo by @h-a-n-a in https://github.com/napi-rs/napi-rs/pull/1302
    • ci: add arm64 macOS CI by @messense in https://github.com/napi-rs/napi-rs/pull/1313
    • fix(napi): improve error propagation by @devongovett in https://github.com/napi-rs/napi-rs/pull/1303
    • fix(napi): propagation error in function call by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1315
    • feat(napi): add impl<T: Into<Vec>> From for Uint8Array by @usrtax in https://github.com/napi-rs/napi-rs/pull/1317
    • feat(napi): add support for Vec<(std::string::String, u16)> and some other small change by @usrtax in https://github.com/napi-rs/napi-rs/pull/1320
    • fix(napi): should also delete the reference while dropping the Buffer by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1331
    • fix(napi): make Buffer/ArrayBuffer truely Send/Sync safe by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1332
    • feat(napi): add threadsafe deferred values by @devongovett in https://github.com/napi-rs/napi-rs/pull/1306

    New Contributors

    • @Wodann made their first contribution in https://github.com/napi-rs/napi-rs/pull/1300
    • @usrtax made their first contribution in https://github.com/napi-rs/napi-rs/pull/1317

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.10.0

    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Oct 4, 2022)

  • [email protected](Sep 8, 2022)

    What's Changed

    • fix(napi): remove previous reference if value_ref existed by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1290
    • fix(napi): some of the unsoundness in Buffer by @seritools in https://github.com/napi-rs/napi-rs/pull/1294

    New Contributors

    • @mat-if made their first contribution in https://github.com/napi-rs/napi-rs/pull/1293

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.9.1

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Sep 8, 2022)

    What's Changed

    • fix(napi-derive): should not generate this types for Constructor/Getter/Setter by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1291
    • pin minimum usable version of dependency syn by @mat-if in https://github.com/napi-rs/napi-rs/pull/1293

    New Contributors

    • @mat-if made their first contribution in https://github.com/napi-rs/napi-rs/pull/1293

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.9.1

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Aug 23, 2022)

    Core changes

    as_object for ClassInstance

    You can use the ClassInstance as Object on the Rust side and manipulate it.

    #[napi]
    impl CanvasElement {
      #[napi(constructor)]
      pub fn new(mut env: Env, mut this: This, width: u32, height: u32) -> Result<Self> {
        let ctx = CanvasRenderingContext2D::into_instance(
          CanvasRenderingContext2D {
            context: Context::new(width, height, ColorSpace::default())?,
          },
          env,
        )?;
        ctx.as_object(env).define_properties(&[
          Property::new(FILL_STYLE_HIDDEN_NAME)?
            .with_value(&env.create_string("#000")?)
            .with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable),
          Property::new(STROKE_STYLE_HIDDEN_NAME)?
            .with_value(&env.create_string("#000")?)
            .with_property_attributes(PropertyAttributes::Writable | PropertyAttributes::Configurable),
        ])?;
        env.adjust_external_memory((width * height * 4) as i64)?;
        this.define_properties(&[Property::new("ctx")?
          .with_value(&ctx)
          .with_property_attributes(PropertyAttributes::Default)])?;
        Ok(Self { width, height, ctx })
      }
    }
    

    as_unknown for Either types

    For the scenario that preserves original JavaScript values in Either types and sets them into object property, and retrieves it back in the other place.

      #[napi(getter)]
      pub fn get_fill_style(&self, this: This) -> Result<Unknown> {
        this.get_named_property_unchecked(FILL_STYLE_HIDDEN_NAME)
      }
    
      #[napi(setter, return_if_invalid)]
      pub fn set_fill_style(
        &mut self,
        env: Env,
        mut this: This,
        fill_style: Either3<JsString, ClassInstance<CanvasGradient>, ClassInstance<CanvasPattern>>,
      ) -> Result<()> {
        // ... some logic
        let raw_fill_style = fill_style.as_unknown(env);  
        this.set(FILL_STYLE_HIDDEN_NAME, &raw_fill_style)?;
        Ok(())
      }
    

    ToNapiValue for f32

    You can use f32 as the return type:

    #[napi]
    pub fn return_f32() -> f32 {
      3.14
    }
    

    What's Changed

    • fix(napi): segfault when ThreadsafeFunction's callback closure captures data by @messense in https://github.com/napi-rs/napi-rs/pull/1281
    • feat(napi): implement as_object and validate for ClassInstance by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1284
    • feat(napi): implement as_unknown and validate for Either types by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1285
    • feat(napi): implement ToNapiValue for f32 by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1286

    New Contributors

    • @JSerFeng made their first contribution in https://github.com/napi-rs/napi-rs/pull/1278

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.9.0

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Aug 23, 2022)

    What's Changed

    • fix(napi-derive): fix macro expansion naming shadow by @JSerFeng in https://github.com/napi-rs/napi-rs/pull/1278
    • feat(napi-derive): catch_unwind attribute by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1280

    New Contributors

    • @JSerFeng made their first contribution in https://github.com/napi-rs/napi-rs/pull/1278

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.9.0

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Aug 17, 2022)

    Core changes

    Custom finalize trait

    https://napi.rs/docs/concepts/class#custom-finalize-logic

    use napi::bindgen_prelude::*;
    use napi_derive::napi;
     
    #[napi(custom_finalize)]
    pub struct CustomFinalize {
      width: u32,
      height: u32,
      inner: Vec<u8>,
    }
     
    #[napi]
    impl CustomFinalize {
      #[napi(constructor)]
      pub fn new(mut env: Env, width: u32, height: u32) -> Result<Self> {
        let inner = vec![0; (width * height * 4) as usize];
        let inner_size = inner.len();
        env.adjust_external_memory(inner_size as i64)?;
        Ok(Self {
          width,
          height,
          inner,
        })
      }
    }
     
    impl ObjectFinalize for CustomFinalize {
      fn finalize(self, mut env: Env) -> Result<()> {
        env.adjust_external_memory(-(self.inner.len() as i64))?;
        Ok(())
      }
    }
    

    Inject This in functions

    https://napi.rs/docs/concepts/inject-this

    use napi::bindgen_prelude::*;
    use napi_derive::napi;
     
    #[napi(constructor)]
    pub struct Width {
      pub value: i32,
    }
     
    #[napi]
    pub fn plus_one(this: This<&Width>) -> i32 {
      this.value + 1
    }
    

    instance of

    https://napi.rs/docs/concepts/class#instance-of

    use napi::bindgen_prelude::*;
    use napi_derive::napi;
    
    #[napi]
    pub struct NativeClass {}
    
    #[napi]
    pub fn is_native_class_instance(env: Env, value: Unknown) -> Result<bool> {
      NativeClass::instance_of(env, value)
    }
    
    import { NativeClass, isNativeClassInstance } from './index.js'
    
    const nc = new NativeClass()
    console.log(isNativeClassInstance(nc)) // true
    console.log(isNativeClassInstance(1)) // false
    

    What's Changed

    • feat(napi): allow implement custom finalize logic for Class by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1270
    • feat(napi): add get and get_mut method on WeakReference by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1274
    • feat(napi): error_anyhow feature by @i-user-link in https://github.com/napi-rs/napi-rs/pull/1275

    New Contributors

    • @i-user-link made their first contribution in https://github.com/napi-rs/napi-rs/pull/1275

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.8.0

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Aug 17, 2022)

    What's Changed

    • feat(napi-derive): implement instance_of for Class by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1272
    • feat(napi-derive): support inject This into raw function by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1273

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.8.0

    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Aug 12, 2022)

  • @napi-rs/[email protected](Aug 12, 2022)

  • @napi-rs/[email protected](Aug 12, 2022)

  • @napi-rs/[email protected](Aug 9, 2022)

  • [email protected](Aug 7, 2022)

    Core features

    Set property attribute in napi macro

    The Object property attribute in objects and Class created by NAPI-RS is Writable & Configurable & Enumerable by default now.

    For NativeClass:

    #[napi]
    pub struct NativeClass  {}
    
    #[napi]
    impl NativeClass {
      #[napi]
      pub fn hello(&self) {
        println!("hello");
      }
    }
    

    Before:

    const instance = new NativeClass()
    instance.hello = function() {} // Cannot assign to read only property \'hello\' of object \'#<NativeClass>\'
    

    After:

    const instance = new NativeClass()
    instance.hello = function() {} // Just fine
    

    You can also configure the Property attribute via #[napi]:

    #[napi]
    pub struct NativeClass  {}
    
    #[napi]
    impl NativeClass {
      #[napi(configurable = false, writable = false, enumerable = false)]
      pub fn hello(&self) {
        println!("hello");
      }
    }
    

    What's Changed

    • feat(napi): add some useful derived traits for the Null type by @Xaeroxe in https://github.com/napi-rs/napi-rs/pull/1241
    • ci: fix self testing for Android platforms by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1248
    • feat(napi): add derived traits to ThreadsafeFunctionCallMode by @seritools in https://github.com/napi-rs/napi-rs/pull/1243
    • feat(napi): Call sync functions within tokio runtime by @Xaeroxe in https://github.com/napi-rs/napi-rs/pull/1242
    • fix(napi): either for #[napi(object)] types by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1258

    New Contributors

    • @amrbashir made their first contribution in https://github.com/napi-rs/napi-rs/pull/1251
    • @seritools made their first contribution in https://github.com/napi-rs/napi-rs/pull/1243
    Source code(tar.gz)
    Source code(zip)
  • [email protected](Aug 7, 2022)

    What's Changed

    • feat(napi-derive): support set property attribute in napi macro by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1257
    • feat(napi-derive): Support #[napi(strict)] on &T and &mut T by @Hywan in https://github.com/napi-rs/napi-rs/pull/1238
    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Aug 7, 2022)

    What's Changed

    • feat(cli): support npmClient config by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1253
    • feat(cli): use CARGO_TARGET_DIR if set by @amrbashir in https://github.com/napi-rs/napi-rs/pull/1251
    • chore(cli): improve *.node doesn't exist warning msg wording by @amrbashir in https://github.com/napi-rs/napi-rs/pull/1254
    • feat(cli): add an option to specify the github release name by @amrbashir in https://github.com/napi-rs/napi-rs/pull/1255
    • feat(napi): call sync functions within tokio runtime by @Xaeroxe in https://github.com/napi-rs/napi-rs/pull/1242
    • feat(cli): allow specifying an existing release by @amrbashir in https://github.com/napi-rs/napi-rs/pull/1256

    New Contributors

    • @amrbashir made their first contribution in https://github.com/napi-rs/napi-rs/pull/1251
    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Jul 27, 2022)

  • @napi-rs/[email protected](Jul 22, 2022)

  • [email protected](Jul 11, 2022)

    What's Changed

    • fix(napi): use Mutex instead of Atomic in ThreadsafeFunction by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1234
    • fix(napi): memory leak in Buffer/ArrayBuffer by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1235

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.6.3

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Jul 8, 2022)

    What's Changed

    • fix(napi) undefined is recognized as a valid None for Option<T> by @Hywan in https://github.com/napi-rs/napi-rs/pull/1228
    • fix(napi): memory leak in ThreadsafeFunction by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1230

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.6.2

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Jul 6, 2022)

    What's Changed

    • fix(napi): drop buffer inner data only when Reference count is 0 by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1227

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.6.1

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Jul 6, 2022)

    What's Changed

    • chore(napi): replace lazy_static with once_cell by @jplatte in https://github.com/napi-rs/napi-rs/pull/1213
    • feat(napi) Implement Either3 to Either26. by @Hywan in https://github.com/napi-rs/napi-rs/pull/1200
    • fix(napi): validate fn for Option by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1223
    • feat(napi): clone reference for TypedArray/Buffer by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1224

    New Contributors

    • @jplatte made their first contribution in https://github.com/napi-rs/napi-rs/pull/1213

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/@napi-rs/[email protected]@napi-rs/[email protected]

    Source code(tar.gz)
    Source code(zip)
  • [email protected](Jul 6, 2022)

    What's Changed

    • feat(napi-derive): support return_if_invalid by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1219
    • feat(napi-derive): allow injecting this in class method by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1221

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.6.0

    Source code(tar.gz)
    Source code(zip)
  • @napi-rs/[email protected](Jul 6, 2022)

  • [email protected](Jun 10, 2022)

    What's Changed

    • Add rust-version field to Cargo.tomls by @messense in https://github.com/napi-rs/napi-rs/pull/1190
    • feat(napi) Implement ToNapiValue for 8 and 16-bits numbers by @Hywan in https://github.com/napi-rs/napi-rs/pull/1195
    • feat(napi) implement From<Infallible> for napi::Error by @sunli829 in https://github.com/napi-rs/napi-rs/pull/1197
    • feat(napi) Extend #1195 to Vec<T>. by @Hywan in https://github.com/napi-rs/napi-rs/pull/1198
    • feat(napi): support into_instance in class struct by @Brooooooklyn in https://github.com/napi-rs/napi-rs/pull/1201

    New Contributors

    • @Hywan made their first contribution in https://github.com/napi-rs/napi-rs/pull/1195
    • @sunli829 made their first contribution in https://github.com/napi-rs/napi-rs/pull/1197

    Full Changelog: https://github.com/napi-rs/napi-rs/compare/[email protected]@2.5.0

    Source code(tar.gz)
    Source code(zip)
Owner
Node-API (N-API) for Rust
High-level and typesafe Node.js Node-API (N-API) bindings for Rust
Node-API (N-API) for Rust
WASM-compiled built-in actors used by all Filecoin clients

Built-in Filecoin actors (v8) This repo contains the code for the on-chain built-in actors that power the Filecoin network starting from network versi

Filecoin 34 Dec 2, 2022
lzma-rs binding to Node.js via napi-rs.

@napi-rs/lzma lzma-rs binding to Node.js via napi-rs. ?? Help me to become a full-time open-source developer by sponsoring me on Github Install yarn a

LongYinan 8 Aug 16, 2022
Calling the JVM from Rust via JNI

Rucaja (Rust calls Java) Calling JVM code from Rust via JNI. Usage JNI calls are about 10-20 times slower than regular JVM instructions. It is adviced

null 31 Sep 27, 2022
A parser, compiler, and virtual machine evaluator for a minimal subset of Lua; written from scratch in Rust.

lust: Lua in Rust This project implements a parser, compiler, and virtual machine evaluator for a minimal subset of Lua. It is written from scratch in

Phil Eaton 145 Dec 3, 2022
Minimal framework to inject the .NET Runtime into a process in Rust

錆の核 sabinokaku Minimal framework to inject the .NET Runtime into a process. Supports Windows and Linux. macOS support is complicated due to SIP, and w

Snowflake Emulator Frontend 8 Mar 6, 2022
Lagoon is a dynamic, weakly-typed and minimal scripting language. 🏞

Lagoon is a dynamic, weakly-typed and minimal scripting language. It draws inspiration from a handful of modern languages including JavaScript, Rust and PHP.

Ryan Chandler 25 Jul 5, 2022
Node.js bindings to the ripgrep library, for fast file searching in JavaScript without child processes!

ripgrepjs ripgrepjs: Node.js bindings to the ripgrep library, for direct integration with JS programs without spawning an extra subprocess! This proje

Annika 1 May 10, 2022
Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex.

Lz4 Fastest lz4 compression library in Node.js, powered by napi-rs and lz4-flex. Install this package yarn add lz4-napi API export function compress:

Antonio Musolino 34 Nov 22, 2022
Rust bindings for writing safe and fast native Node.js modules.

Rust bindings for writing safe and fast native Node.js modules. Getting started Once you have the platform dependencies installed, getting started is

The Neon Project 6.9k Dec 2, 2022
Easy way to write Node.js module using Rust

node-bindgen Easy way to write native Node.js module using idiomatic Rust Features Easy: Just write idiomatic Rust code, node-bindgen take care of gen

InfinyOn 342 Nov 30, 2022
Benchmark over Node.js binding frameworks in Rust

Benchmark over Node.js binding frameworks in Rust

LongYinan 6 Jul 10, 2022
Rust Blake hash bindings for Node.js.

@napi-rs/blake-hash Node.js binding for https://github.com/BLAKE3-team/BLAKE3. High performance, and no postinstall scripts. Support matrix node12 nod

LongYinan 35 Aug 12, 2022
🚀 Fast and simple Node.js version manager, built in Rust

Fast Node Manager (fnm) ?? Fast and simple Node.js version manager, built in Rust Features ?? Cross-platform support (macOS, Windows, Linux) ✨ Single

Gal Schlezinger 9.6k Dec 3, 2022
Native webview bindings for Node.js

webview-native Native webview bindings for Node.js Installing webview-native Installing webview-native requires a supported version of Node and Rust.

SnowflakeDev Community ❄️ 7 Nov 16, 2022
Node.js bindings to Lua

Node.js bindings to Lua

Connor Brewster 5 May 7, 2022
Libsodium for Node.js

Libsodium for Node.js

Tomio 7 Oct 30, 2022
High-level Rust bindings to Perl XS API

Perl XS for Rust High-level Rust bindings to Perl XS API. Example xs! { package Array::Sum; sub sum_array(ctx, array: AV) { array.iter().map(|

Vickenty Fesunov 59 Oct 6, 2022
🚀 Fast and 100% API compatible postcss replacer, built in Rust

postcss-rs ?? Fast and 100% API compatible postcss replacer, built in Rust ⚠️ DO NOT USE. STILL WORK IN PROGRESS. Performance Improvement Tokenize boo

null 471 Nov 30, 2022
call rest api using rust + yew

Call Rest API With Rust and Yew: USA Weather Service API Open Data YEW Complete Tutorial YouTube Video https://youtu.be/dSJULWtd3y0 How to run trunk s

Security Union 6 Oct 19, 2022