This fix is similar to the one in 5b5f616d81.
In both the then_callback & catch_callback, expect was being called in case
the send failed. This means that if we call a function that returns a promise
and the received gets closed (the calling thread stopped at the wrong time),
this will panic.
In such scenarios, it is fine not to panic. If the receiver doesn't care about
the output, we should just let it be.
* feat(napi): support to use tuple with either (#1993)
`Either` uses `ValidateNapiValue` + `TypeName` to validate and report error on value not being matched. So there's no way to remove these super traits from it. So I implemented these types to `Tuple` types.
* feat(napi): support `Return` generic of ThreadsafeFunction
* depracate JsFunction
* CalleeHandled tsfn should handle Result in callback
* Pass env to call_with_return_value callback
* Fix compile
* clippy fix
* Fix electron test
* Function args
---------
Co-authored-by: Hana <andywangsy@gmail.com>
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.15.5 to 1.15.6.
<details>
<summary>Commits</summary>
<ul>
<li><a href="35a517c586"><code>35a517c</code></a> Release version 1.15.6 of the npm package.</li>
<li><a href="c4f847f851"><code>c4f847f</code></a> Drop Proxy-Authorization across hosts.</li>
<li><a href="8526b4a1b2"><code>8526b4a</code></a> Use GitHub for disclosure.</li>
<li>See full diff in <a href="https://github.com/follow-redirects/follow-redirects/compare/v1.15.5...v1.15.6">compare view</a></li>
</ul>
</details>
<br />
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=follow-redirects&package-manager=npm_and_yarn&previous-version=1.15.5&new-version=1.15.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/napi-rs/napi-rs/network/alerts).
</details>
`Either` uses `ValidateNapiValue` + `TypeName` to validate and report error on value not being matched. So there's no way to remove these super traits from it. So I implemented these types to `Tuple` types.
* Refactor js-binding to support bundling single-package artifacts
The existsSync check breaks the bundlers I've tested (esbuild, webpack,
ncc), so you cannot bundle napi-rs packages that have all binarys in a
single package.
I've tested this change with both single package and multi package
libraries.
* Update snapshots
* Update CI
* Fix electron test
---------
Co-authored-by: Caleb ツ Everett <calebev@amazon.com>
Co-authored-by: LongYinan <lynweklm@gmail.com>
As of before this commit, there was a lock in the codegen preventing Reference
from being used as a function argument outside of a Reference<Self>.
This changes it, allowing Reference of any class to be added as a class method
argument anywhere. It has the same limitations as reference, as in it requires
the class to have been created with a factory or constructor. This change
implements FromNapiValue on Reference, which will unwrap the class and call the
existing from_value_ptr method. It also updated typegen so that we only emit
the reference type if we're in an impl block that doesn't match the Reference
we're getting. This ensures that typegen works as expected with the previous
behaviour.
For many reasons, in an app we can end up in a scenario where the thread / task that initially called the ThreadsafeFunction gets interrupted. This means that the receiver would get collected, should a ThreadsafeFunction be awaited on the said thread. This will create an error when the ThreadsafeFunction's callback will be called, and call a napi_fatal_error.
This change makes it so that if the send errors, this error is hidden and thus prevents any hard failure. If a ThreadsafeFunction is called in such a case, its output won't be used, but we'll still run all the logic to ensure it ran properly.
Fixes https://github.com/napi-rs/napi-rs/issues/1665 - cc @Brooooooklyn
Bumps [ip](https://github.com/indutny/node-ip) from 1.1.8 to 1.1.9.
<details>
<summary>Commits</summary>
<ul>
<li><a href="1ecbf2fd8c"><code>1ecbf2f</code></a> 1.1.9</li>
<li><a href="6a3ada9b47"><code>6a3ada9</code></a> lib: fixed CVE-2023-42282 and added unit test</li>
<li>See full diff in <a href="https://github.com/indutny/node-ip/compare/v1.1.8...v1.1.9">compare view</a></li>
</ul>
</details>
<br />
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=ip&package-manager=npm_and_yarn&previous-version=1.1.8&new-version=1.1.9)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)
Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.
[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)
---
<details>
<summary>Dependabot commands and options</summary>
<br />
You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/napi-rs/napi-rs/network/alerts).
</details>
There is a piece of custom logic that has been added a while back to ensure
that Buffers can be sent across threads, and be dropped properly. This involves
a custom GC that runs on NodeJS's current thread (per my understanding). The
logic to drop the buffer on that custom GC differed from the one in the Drop
impl. This meant that everytime Node sent a buffer back to a napi-rs function,
the reference wouldn't be cleaned up properly, and it would leak (96 bytes per
Reference on an ARM MacOS machine).
This commit updates the logic in the custom GC so that it matches the one in
the Drop impl. This worked locally, and fixed any occurence of the leak I could
find.