Commit graph

403 commits

Author SHA1 Message Date
6a9ae1322d
feat(napi): implement From/ToNapiValue for chrono::DateTime<Local> and chrono::DateTime<FixedOffset> (#1902) 2024-04-29 19:26:15 +09:00
LongYinan
8f5d7e5274
fix(napi): handle panic in async block (#2050)
- Close https://github.com/napi-rs/napi-rs/issues/2047
2024-04-17 23:34:47 +08:00
LongYinan
dacfeac1f5
Release independent packages
napi@3.0.0-alpha.2
2024-04-15 23:59:37 +08:00
LongYinan
e3a403b441
feat(napi): allow user defined tokio runtime (#2040) 2024-04-15 23:58:28 +08:00
Louis
19dbadefba
fix(ThreadsafeFunction): ensure CalleeHandled works as expected (#2039)
This was refactored in 4719caa643. This codepath
was swapped, as the fatal exception must be the normal codepath when the callee
handled field is false. This fixes it by swapping this if statement, all the
other calls have been checked and seem fine.
2024-04-15 23:19:15 +08:00
翠 / green
923b82aee9
feat(napi): allow &External to be created from napi value (#2037) 2024-04-15 17:54:10 +08:00
LongYinan
63c8ab3f20
Release independent packages
napi@3.0.0-alpha.1
napi-derive@3.0.0-alpha.1
napi-sys@2.4.0
2024-04-10 17:03:00 +08:00
Ranger
e86e3add2b
fix(napi): napi_adjust_external_memory should be hidden with wasm target (#2031) 2024-04-10 14:57:04 +08:00
翠 / green
a394984f5d
docs: update platform support in README (#2029)
Co-authored-by: LongYinan <lynweklm@gmail.com>
2024-04-09 18:29:04 +08:00
翠 / green
2e0f983ccf
feat(target): add support for s390x-unknown-linux-gnu (#2028)
* feat(target): add support for s390x-unknown-linux-gnu

* chore: rerun CI
2024-04-09 14:16:09 +08:00
翠 / green
71a528535a
fix(napi): create_bigint_from_*128 returned incorrect word_count (#2024)
The value of `word_count` was inconsistent between the node side and rust side when calling `create_bigint_from_i128`/`create_bigint_from_u128`.
2024-04-08 10:43:23 +09:00
LongYinan
f2e5094345
feat(napi-sys): support load Node-API symbols dynamically (#2014) 2024-03-27 14:35:16 +08:00
LongYinan
0550c56fcf
fix(napi): External should impl FromNapiRef rather than FromNapiValue (#2013)
- Close https://github.com/napi-rs/napi-rs/issues/1994
2024-03-25 15:11:11 +08:00
LongYinan
be610c9353
style: clippy fix (#2012) 2024-03-23 19:35:58 +08:00
Louis
15521fb90f
fix(napi): no panic when caller stops listening (#2010)
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.
2024-03-22 22:03:19 +08:00
LongYinan
2a7c000275
Release independent packages
- napi@3.0.0-alpha.0
- napi-derive@3.0.0-alpha.0
2024-03-20 22:46:59 +08:00
LongYinan
13651c5ff1
chore(napi): add Send and Sync to Reference (#2007) 2024-03-20 22:30:45 +08:00
LongYinan
4719caa643
feat(napi): support Return generic of ThreadsafeFunction (#1997)
* 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>
2024-03-20 21:37:08 +08:00
Louis
693f0ac269
feat(napi): implement From<String> for Buffer (#2002) 2024-03-17 22:43:01 +08:00
Hana
97746b79a9
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.
2024-03-13 13:29:06 +08:00
LongYinan
d962e34d3a
fix(napi): remove useless FromNapiValue bound check for ValidateNapiValue (#1999) 2024-03-10 21:22:46 +08:00
LongYinan
e3e8a0fb39
Release independent packages
napi@2.16.0

napi-derive@2.16.0
2024-02-28 15:06:11 +08:00
LongYinan
aeb0b4766d
fix(napi): add back the typecheck logic that was accidentally removed in Object::get_named_property (#1982)
- Close https://github.com/napi-rs/napi-rs/issues/1641
2024-02-28 14:29:02 +08:00
LongYinan
8ca1967bd8
feat(napi): impl BufferSlice and Uint8ClampedSlice (#1979) 2024-02-25 01:00:28 +08:00
LongYinan
f88a041fa3
feat(napi): impl chained Into for TypedArray types (#1978) 2024-02-25 00:58:27 +08:00
LongYinan
71bbe0ef6f
fix(napi): remove useless create_reference in slice => TypedArray impl (#1975) 2024-02-25 00:52:30 +08:00
Louis
43415251b8
feat(napi): allow Reference as a class method param (#1966)
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.
2024-02-22 22:37:50 +08:00
LongYinan
33cf208758
Release independent packages
napi@2.15.4
2024-02-22 19:01:18 +08:00
Tom Barham
ebd5eef267
fix(napi): require static lifetime on add_finalizer callback (#1968)
Co-authored-by: LongYinan <lynweklm@gmail.com>
2024-02-22 18:40:04 +08:00
Louis
5b5f616d81
fix(napi): no hard fail on ThreadsafeFunction::call_async (#1970)
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
2024-02-22 17:34:10 +08:00
LongYinan
8855f18f50
Release independent packages
napi@2.15.3
2024-02-21 23:16:27 +08:00
Louis
9391196eef
fix(napi): prevent memory leak when Custom GC is used (#1963)
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.
2024-02-20 20:36:21 +08:00
Louis
90e3a349db
fix: remove outdated rustdoc about tokio channels (#1961)
This seems to be a relic of when napi-rs used channels to send data to the
tokio runtime. This removes the outdated doc, as this could be misleading if
one wants to understand what those channels are about.
2024-02-20 16:36:29 +08:00
LongYinan
97039b2f08
Release independent packages
- napi@2.15.2
- napi-derive@2.15.2
2024-02-17 22:58:31 +08:00
LongYinan
c49309fdc2
fix(napi): memory leak while using Reference (#1954)
- Close https://github.com/napi-rs/napi-rs/issues/1952
2024-02-17 22:14:27 +08:00
LongYinan
5ac153388f
feat(napi): accept slice as TypedArray (#1951) 2024-02-15 23:40:45 +08:00
LongYinan
d7dc4dc5a2
feat(napi): extends the Map types interoperability (#1950) 2024-02-15 15:43:21 +08:00
LongYinan
5b66467e09
Release independent packages
- napi@2.15.1
2024-02-01 22:16:22 +08:00
jkomyno
a5f3b2e78c fix(napi): in "Object::get", return null values wrapped in a "Some" 2024-01-31 15:50:58 +01:00
Janrupf
ac3626a023
fix(napi): Fix buffer corruption and soundness issues (#1923)
* fix(napi): Fix buffer corruption and soundness issues

* test: fix tests to conform to buffer API
2024-01-29 18:32:28 +08:00
LongYinan
a6aaa94e7d
Release independent packages
- napi@2.15.0
- napi-derive@2.15.0
2024-01-26 14:32:24 +08:00
LongYinan
f625328868
fix(napi): move JsValuesTupleIntoVec trait to function.rs 2024-01-26 14:32:24 +08:00
LongYinan
f69771e2d4
fix(napi-derive): JsArrayBuffer generated type 2024-01-26 14:32:24 +08:00
LongYinan
b9ba7c9d68
fix(napi): memory issue while creating external buffer on electron 2024-01-26 14:32:24 +08:00
LongYinan
aff95d0271
chore(napi): remove napi_val on Ref because it is unused 2024-01-26 03:29:52 +00:00
LongYinan
12503a8061
chore(napi): delete unwrap_from_ref API because it was never work 2024-01-26 02:58:53 +00:00
LongYinan
fecd0d8049
Update crates/napi/src/bindgen_runtime/js_values/function.rs 2024-01-26 02:27:46 +00:00
LongYinan
5be7ab0f6b
feat(napi): new Function/FunctionRef API 2024-01-26 02:27:46 +00:00
LongYinan
134707ef1d
fix(napi): callback in execute_tokio_future does not need to be Send (#1917)
The resolver does not need to be `Send` or `Sync`, because it's assumed to be called from the same thread that the JavaScript thread is running on.
2024-01-26 10:27:17 +08:00
LongYinan
69d2a75384
Release independent packages
- napi@2.14.4
2024-01-24 17:20:46 +08:00