diff --git a/Cargo.lock b/Cargo.lock index fef9a58..606861d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -214,9 +214,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.7" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", @@ -420,18 +420,18 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "13e3bf6590cbc649f4d1a3eefc9d5d6eb746f5200ffb04e5e142700b8faa56e7" [[package]] name = "libloading" -version = "0.6.7" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351a32417a12d5f7e82c368a66781e307834dae04c6ce0cd4456d52989229883" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" dependencies = [ "cfg-if", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -489,7 +489,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -512,45 +512,28 @@ dependencies = [ [[package]] name = "neon" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28e15415261d880aed48122e917a45e87bb82cf0260bb6db48bbab44b7464373" +version = "1.0.0" +source = "git+https://github.com/neon-bindings/neon.git#d6db6ed51008d358e9de9933080793325029d5a4" dependencies = [ - "neon-build", + "getrandom", + "libloading", "neon-macros", - "neon-runtime", + "once_cell", "semver", + "send_wrapper", "smallvec", ] -[[package]] -name = "neon-build" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bac98a702e71804af3dacfde41edde4a16076a7bbe889ae61e56e18c5b1c811" - [[package]] name = "neon-macros" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7288eac8b54af7913c60e0eb0e2a7683020dffa342ab3fd15e28f035ba897cf" +version = "1.0.0" +source = "git+https://github.com/neon-bindings/neon.git#d6db6ed51008d358e9de9933080793325029d5a4" dependencies = [ "quote", - "syn", + "syn 2.0.48", "syn-mid", ] -[[package]] -name = "neon-runtime" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4676720fa8bb32c64c3d9f49c47a47289239ec46b4bdb66d0913cc512cb0daca" -dependencies = [ - "cfg-if", - "libloading", - "smallvec", -] - [[package]] name = "num_cpus" version = "1.13.1" @@ -563,9 +546,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "openssl" @@ -590,7 +573,7 @@ checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.98", ] [[package]] @@ -638,18 +621,18 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -737,7 +720,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", - "windows-sys", + "windows-sys 0.36.1", ] [[package]] @@ -765,18 +748,15 @@ dependencies = [ [[package]] name = "semver" -version = "0.9.0" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] +checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0" [[package]] -name = "semver-parser" -version = "0.7.0" +name = "send_wrapper" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +checksum = "cd0b0ec5f1c1ca621c432a25813d8d60c88abe6d3e08a3eb9cf37d97a0fe3d73" [[package]] name = "serde" @@ -795,7 +775,7 @@ checksum = "023e9b1467aef8a10fb88f25611870ada9800ef7e22afce356bb0d2387b6f27c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.98", ] [[package]] @@ -829,9 +809,9 @@ checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32" [[package]] name = "smallvec" -version = "1.9.0" +version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "e6ecd384b10a64542d77071bd64bd7b231f4ed5940fba55e98c3de13824cf3d7" [[package]] name = "socket2" @@ -854,15 +834,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn-mid" -version = "0.5.3" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baa8e7560a164edb1621a55d18a0c59abf49d360f47aa7b821061dd7eea7fac9" +checksum = "b5dc35bb08dd1ca3dfb09dce91fd2d13294d6711c88897d9a9d60acf39bce049" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.48", ] [[package]] @@ -1060,7 +1051,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn", + "syn 1.0.98", "wasm-bindgen-shared", ] @@ -1094,7 +1085,7 @@ checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.98", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1143,43 +1134,109 @@ version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_msvc", + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "winreg" version = "0.10.1" diff --git a/Cargo.toml b/Cargo.toml index ef78aec..972500d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,3 +9,6 @@ members = [ [profile.release] lto = true + +[patch.crates-io] +neon = { git = "https://github.com/neon-bindings/neon.git" } diff --git a/examples/async-sqlite/Cargo.toml b/examples/async-sqlite/Cargo.toml index adfceb8..ebc9cb3 100644 --- a/examples/async-sqlite/Cargo.toml +++ b/examples/async-sqlite/Cargo.toml @@ -10,9 +10,5 @@ exclude = ["index.node"] crate-type = ["cdylib"] [dependencies] +neon = "1" rusqlite = "0.25" - -[dependencies.neon] -version = "0.10.1" -default-features = false -features = ["napi-6", "channel-api", "promise-api", "try-catch-api"] diff --git a/examples/async-sqlite/src/lib.rs b/examples/async-sqlite/src/lib.rs index 44bc3fe..5a7293e 100644 --- a/examples/async-sqlite/src/lib.rs +++ b/examples/async-sqlite/src/lib.rs @@ -120,8 +120,7 @@ impl Database { // immediately instead of waiting on garbage collection. This is useful in tests. fn js_close(mut cx: FunctionContext) -> JsResult { // Get the `this` value as a `JsBox` - cx.this() - .downcast_or_throw::, _>(&mut cx)? + cx.this::>()? .close() .or_else(|err| cx.throw_error(err.to_string()))?; @@ -135,7 +134,7 @@ impl Database { let name = cx.argument::(0)?.value(&mut cx); // Get the `this` value as a `JsBox` - let db = cx.this().downcast_or_throw::, _>(&mut cx)?; + let db = cx.this::>()?; let (deferred, promise) = cx.promise(); db.send(deferred, move |conn, channel, deferred| { @@ -154,7 +153,6 @@ impl Database { }) .into_rejection(&mut cx)?; - // This function does not have a return value Ok(promise) } @@ -165,7 +163,7 @@ impl Database { let id = cx.argument::(0)?.value(&mut cx); // Get the `this` value as a `JsBox` - let db = cx.this().downcast_or_throw::, _>(&mut cx)?; + let db = cx.this::>()?; let (deferred, promise) = cx.promise(); db.send(deferred, move |conn, channel, deferred| { @@ -187,7 +185,6 @@ impl Database { }) .into_rejection(&mut cx)?; - // This function does not have a return value Ok(promise) } } diff --git a/examples/cpu-count/Cargo.toml b/examples/cpu-count/Cargo.toml index 384bb31..e32f9ef 100644 --- a/examples/cpu-count/Cargo.toml +++ b/examples/cpu-count/Cargo.toml @@ -10,9 +10,5 @@ exclude = ["index.node"] crate-type = ["cdylib"] [dependencies] +neon = "1" num_cpus = "1" - -[dependencies.neon] -version = "0.10.1" -default-features = false -features = ["napi-6"] diff --git a/examples/gzip-stream/Cargo.toml b/examples/gzip-stream/Cargo.toml index 36707f1..1c63c44 100644 --- a/examples/gzip-stream/Cargo.toml +++ b/examples/gzip-stream/Cargo.toml @@ -11,8 +11,4 @@ crate-type = ["cdylib"] [dependencies] flate2 = "1" - -[dependencies.neon] -version = "0.10.1" -default-features = false -features = ["napi-6", "promise-api", "task-api"] +neon = "1" diff --git a/examples/gzip-stream/src/lib.rs b/examples/gzip-stream/src/lib.rs index 7953f26..910f9f9 100644 --- a/examples/gzip-stream/src/lib.rs +++ b/examples/gzip-stream/src/lib.rs @@ -5,7 +5,7 @@ use std::sync::{Arc, Mutex, MutexGuard, TryLockError}; use flate2::{write::GzEncoder, Compression}; use neon::prelude::*; -use neon::types::buffer::TypedArray; +use neon::types::{buffer::TypedArray, JsUint8Array}; use std::fmt::Debug; #[derive(Clone)] @@ -54,35 +54,21 @@ impl CompressStream { // After each call to `write` or `finish`, data may be written to the internal // buffer. This function copies the written data out and resets the buffer // to empty. - fn output(self) -> Result, CompressError> { - let mut guard = self.lock()?; + fn and_buffer( + mut cx: TaskContext, + // Return value from `cx.task(..)` closure + result: Result, + ) -> JsResult { + let stream = result.or_else(|err| cx.throw_error(err))?; + let mut guard = stream.lock().or_else(|err| cx.throw_error(err))?; + let data = guard.get_mut(); - let output = data.clone(); + let output = JsUint8Array::from_slice(&mut cx, data)?; data.truncate(0); Ok(output) } - - // This is a small helper that is used as the callback to `TaskBuilder::promise` - // in both `compress_chunk` and `compress_finish`. It grabs any written bytes - // with `CompressStream::output` and puts the data into an `ArrayBuffer`, throwing - // a JavaScript exception if any Rust error occurred. - fn and_buffer( - mut cx: TaskContext, - // Return value from `cx.task(..)` closure - result: Result, - ) -> JsResult { - let output = result - // An error may have occurred while compressing; conditionally grab the - // written data - .and_then(|stream| stream.output()) - // Convert a Rust error to a JavaScript exception - .or_else(|err| cx.throw_error(err.to_string()))?; - - // Create a `Buffer` backed by a `Vec` containing the written data - Ok(JsBuffer::external(&mut cx, output)) - } } // Types placed in a `JsBox`, an opaque pointer for passing Rust data from Rust to @@ -117,6 +103,12 @@ impl fmt::Display for CompressError { impl Error for CompressError {} +impl AsRef for CompressError { + fn as_ref(&self) -> &str { + &self.0 + } +} + // Create a boxed `CompressStream` that can be passed to JavaScript and back fn compress_new(mut cx: FunctionContext) -> JsResult> { // Best compression because why not? @@ -142,7 +134,7 @@ fn compress_chunk(mut cx: FunctionContext) -> JsResult { // types, giving a `CompressStream`. However, it's impossible to move out of a // `JsBox`, so a reference is immediately taken with `&`. Finally, we can call the // `clone` implementation on `CompressStream`. - let stream = (&**cx.argument::>(0)?).clone(); + let stream = (**cx.argument::>(0)?).clone(); // The 2nd argument is `encoding`. However, gzip is encoding agnostic and we do not need it. // let encoding = cx.argument::(1)?; @@ -164,9 +156,9 @@ fn compress_chunk(mut cx: FunctionContext) -> JsResult { // Complete compressing the data and get the remaining output fn compress_finish(mut cx: FunctionContext) -> JsResult { // Get a shallow clone of `CompressStream`; same as in `compress_chunk` - // This is an alternative to the `&**` syntax used earlier. Instead, it uses auto-deref + // This is an alternative to the `**` syntax used earlier. Instead, it uses auto-deref // and universal call syntax for the `clone` call to coerce to proper type. - let stream = CompressStream::clone(&&cx.argument::>(0)?); + let stream = CompressStream::clone(&*cx.argument::>(0)?); let promise = cx // Finish the stream on the Node worker pool diff --git a/examples/hello-world/Cargo.toml b/examples/hello-world/Cargo.toml index 614784b..a28786a 100644 --- a/examples/hello-world/Cargo.toml +++ b/examples/hello-world/Cargo.toml @@ -9,7 +9,5 @@ exclude = ["index.node"] [lib] crate-type = ["cdylib"] -[dependencies.neon] -version = "0.10.1" -default-features = false -features = ["napi-6"] +[dependencies] +neon = "1" diff --git a/examples/tokio-fetch/Cargo.toml b/examples/tokio-fetch/Cargo.toml index ba0fb89..5cbbfcc 100644 --- a/examples/tokio-fetch/Cargo.toml +++ b/examples/tokio-fetch/Cargo.toml @@ -10,12 +10,8 @@ exclude = ["index.node"] crate-type = ["cdylib"] [dependencies] +neon = "1" once_cell = "1" reqwest = { version = "0.11", features = ["json"] } tokio = { version = "1", features = ["rt-multi-thread"] } serde = { version = "1", features = ["derive"] } - -[dependencies.neon] -version = "0.10.1" -default-features = false -features = ["channel-api", "napi-6", "promise-api"] diff --git a/examples/tokio-fetch/src/lib.rs b/examples/tokio-fetch/src/lib.rs index cb72c7b..672249b 100644 --- a/examples/tokio-fetch/src/lib.rs +++ b/examples/tokio-fetch/src/lib.rs @@ -17,11 +17,12 @@ fn runtime<'a, C: Context<'a>>(cx: &mut C) -> NeonResult<&'static Runtime> { RUNTIME.get_or_try_init(|| Runtime::new().or_else(|err| cx.throw_error(err.to_string()))) } -// Get the verson of the currently running node process from [`process.version`](https://nodejs.org/api/process.html#processversion) +// Get the version of the currently running node process from [`process.version`](https://nodejs.org/api/process.html#processversion) fn node_version<'a, C: Context<'a>>(cx: &mut C) -> NeonResult { - let global = cx.global(); - let process = global.get::(cx, "process")?; - let version = process.get::(cx, "version")?.value(cx); + let version = cx + .global::("process")? + .get::(cx, "version")? + .value(cx); Ok(version) }