124 Commits

Author SHA1 Message Date
Igor Matuszewski
cc21452f65
fix(napi): nullptr handling in TypedArrays (#2258)
* fix: Safely return empty slices if TypedArray buffer is null ptr

* fix: Only dispose of TypedArray if the data is not a nullptr

* test: Add a regression test for typed array null ptr deref
2024-09-19 13:38:19 +08:00
LongYinan
20b9de3ec7
fix(cli): extra line break in the tail of dts file (#2255) 2024-09-15 11:44:29 +08:00
Richer
5934ecd2a9
feat(napi): mark JsArraybufferValue's value pub (#2226) 2024-08-23 22:25:52 +08:00
CPunisher
249c27e06d
fix(napi-derive): tuple object and enum (#2227)
* Fix tuple struct

* Add testcase
2024-08-23 14:10:39 +08:00
CPunisher
c459f0acf6
feat: support structured enum with discriminated unions (#2222)
* Structured enum

* Type indent

* Add test example

* Remove trailing commas

* discriminant

* discriminant conflict

* more test

* typo
2024-08-22 14:59:50 +08:00
LongYinan
d84fc42832
fix(napi-derive): string enum validate logic (#2213) 2024-08-10 21:27:17 +08:00
CPunisher
a154612019
fix(napi-derive): add more cases for typegen of function args (#2210)
* Handle more arg pat

* Update testcase

* Revert
2024-08-08 11:07:21 +08:00
LongYinan
282ce1c00a
fix(napi): allow ThreadsafeFunction in Either (#2204) 2024-08-03 13:22:09 +08:00
LongYinan
3f6822d9cd
test: skip unstable test in WASI env (#2196) 2024-07-24 12:09:08 +08:00
LongYinan
727f5a831a
test: skip memory exhausting test in wasi env (#2185) 2024-07-13 02:34:04 +08:00
renovate[bot]
4d39940fa0
chore(deps): update vitest monorepo to v2 (major) (#2177)
* chore(deps): update vitest monorepo to v2

* Fix lockfile

* Add playwright

* Update snapshots

* Fix vitest

* Fix vitest

* Fix wasi test

* Fix worker test condition

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: LongYinan <lynweklm@gmail.com>
2024-07-11 14:58:46 +08:00
LongYinan
45a404c30b
ci: use shell to run tests in Docker (#2175) 2024-07-08 15:18:50 +08:00
LongYinan
349996b699
test: update snapshots 2024-07-07 22:34:36 +08:00
LongYinan
3a511bacee
fix(napi): Promise callbacks should require static lifetime (#2172) 2024-07-07 20:42:17 +08:00
LongYinan
bc9e931a4e
feat(napi): provide PromiseRaw for non-await scenario (#2168) 2024-07-06 19:09:16 +08:00
LongYinan
aef57fb196
feat(napi): impl from_string for Uint8Array (#2167) 2024-07-06 14:32:09 +08:00
Jade-fu
c2bda9a900
fix(napi-derive): class constructor and factory should support custom error status (#2161) 2024-06-30 16:12:00 +08:00
LongYinan
d7a5a7e9a1
test(napi): spwan thread in thread (#2139) 2024-06-24 16:09:07 +08:00
Ranger
80d9d87ef9
chore(example): remove JsFunction from example (#2123)
* chore(example): remove jsfunction

* feat(napi): implement ToNapiValue for Ref as required by TSFN

* fix(test): tsfn test build failed

* chore: lint code

* fix(test): fix tsfn unit test
2024-05-26 21:07:01 +08:00
magic-akari
734d74bd02
fix(typegen): add missing declare keyword (#2117) 2024-05-19 16:53:23 +08:00
Ranger
c52d2042a2
feat(napi): Function build_thfn support calledhandled mode (#2114)
* feat(napi): Function build_thfn support calledhandled mode

* test(example): add calleehandle example
2024-05-18 20:20:12 +08:00
Louis
c223954dc6
chore(napi): allow value attribute on enum variants (#2115)
This allows us to customize the enum value for string_enum. So far, only the case attribute was allowing us to customize the value of those variants, this is a next step in allowing the value to be different from the actual name.

This has a new test, and snapshots have been updated accordingly.

@Brooooooklyn - could we include that in napi v2 and tag after it?
2024-05-17 11:22:33 +08:00
LongYinan
1e781a589c
chore(napi): remove depracated get_js_function (#2101) 2024-05-09 15:13:44 +08:00
Niklas Mischkulnig
f3d665d5b1
fix(napi): panic when deserializing empty buffer with Rust 1.78 (#2094)
* Add test for #2083

* Add test for serde_byte with empty buffer

* Fix using serde_bytes with empty buffers

* skip wasi test

* fix test

* clippy fix

* avoid ub

* use safer impl

---------

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
Co-authored-by: LongYinan <lynweklm@gmail.com>
2024-05-07 17:57:15 +08:00
LongYinan
4572ede9f5
refactor(napi): split T and CallJsBackArgs generic type (#2091) 2024-05-06 18:25:40 +08:00
naskya
68b5f2c587
feat(napi): support chrono datetime with timezones (#2074)
* feat(napi): implement From/ToNapiValue for chrono::DateTime<Local> and chrono::DateTime<FixedOffset> (#1902)

* chore(napi): update tests

Co-authored-by: sup39 <dev@sup39.dev>

---------

Co-authored-by: sup39 <dev@sup39.dev>
2024-04-30 22:51:40 +08:00
LongYinan
46cbcf3ff1
feat(cli): allow sync fs operation between workers/mainThread (#2064)
* feat(cli): allow sync fs operation between workers/mainThread

* allow sync fs operation between workers/mainThread (#2065)

* Fix

* Update fixture

* flaky test

* Fix cross compile target

* Update zig

* macos-cross test was filtered

---------

Co-authored-by: Toyo Li <lifenglin314@outlook.com>
2024-04-23 12:14:06 +08:00
LongYinan
cd3a850dcb
ci: improve test speed (#2057) 2024-04-19 16:00:20 +08: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
b3dd94649a
feat(cli): allow to define dtsHeader in napi config (#2045) 2024-04-16 17:40:41 +08:00
翠 / green
923b82aee9
feat(napi): allow &External to be created from napi value (#2037) 2024-04-15 17:54:10 +08:00
LongYinan
e274cf7ae6
feat(napi-derive): enhance the error messages in object validator (#2034) 2024-04-10 16:52:23 +08:00
LongYinan
67f03a7fd4
ci: fix flaky tests (#2033)
* ci: fix flaky tests

* chore: remove useless deps

* chore: decresse worker_threads counts
2024-04-10 15:43:05 +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
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
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
Andrew Toth
6b1058a268
feat(napi-derive): add optional enum_string case conversion (#1995) 2024-03-11 20:10:00 +08:00
LongYinan
d962e34d3a
fix(napi): remove useless FromNapiValue bound check for ValidateNapiValue (#1999) 2024-03-10 21:22:46 +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
Caleb Everett
95dd6ef485
refactor(cli): refactor js-binding to support easier bundling. (#1957)
* 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>
2024-02-26 15:46:07 +08:00
LongYinan
117e4ce153
fix(napi-derive): wrong dependency condition (#1980) 2024-02-25 15:25:42 +08:00
LongYinan
8ca1967bd8
feat(napi): impl BufferSlice and Uint8ClampedSlice (#1979) 2024-02-25 01:00:28 +08:00
LongYinan
3e187151a6
fix(napi-derive): HashMap/IndexMap and slice generated types (#1977) 2024-02-25 00:56:30 +08:00
サポミク
ebe97257a6
feat(napi-derive): add use_nullable attribute (#1971)
* feat(napi-derive): add use_nullable attribute

Co-authored-by: naskya <m@naskya.net>

* chore(napi-derive): update tests

Co-authored-by: naskya <m@naskya.net>

---------

Co-authored-by: naskya <m@naskya.net>
2024-02-24 21:49:54 +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
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
f69771e2d4
fix(napi-derive): JsArrayBuffer generated type 2024-01-26 14:32:24 +08:00
LongYinan
5be7ab0f6b
feat(napi): new Function/FunctionRef API 2024-01-26 02:27:46 +00:00
LongYinan
120accd965
feat: add wasm runtime package (#1904) 2024-01-16 23:28:40 +08:00