diff --git a/Cargo.lock b/Cargo.lock index a31ddb6f..94e2eda7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -393,6 +393,21 @@ version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -639,6 +654,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cooked-waker" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147be55d677052dabc6b22252d5dd0fd4c29c8c27aa4f2fbef0f94aa003b406f" + [[package]] name = "core-foundation" version = "0.9.4" @@ -838,26 +859,31 @@ dependencies = [ [[package]] name = "deno_console" -version = "0.127.0" +version = "0.136.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deed4ab844857520058dab8f8f07d6c0be0e5a525e424a13c047f3756b18ca45" +checksum = "598ab6c4aeb4bd4e3e31d90b8f6dd772f25ed92fc979ff12c641074ef4553030" dependencies = [ "deno_core", ] [[package]] name = "deno_core" -version = "0.232.0" +version = "0.256.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229ffd108e028b148a1a5a6122f771bc7c37094170226f44b8b93b3a9b79d114" +checksum = "cd5997286bcc46199bbae727f43ee65cf4bd073ac2d240a36a6ceae3bfab14ac" dependencies = [ "anyhow", + "bit-set", + "bit-vec", "bytes", + "cooked-waker", + "deno_core_icudata", "deno_ops", "deno_unsync", "futures", "libc", "log", + "memoffset", "parking_lot 0.12.1", "pin-project", "serde", @@ -865,16 +891,23 @@ dependencies = [ "serde_v8", "smallvec", "sourcemap", + "static_assertions", "tokio", "url", "v8", ] +[[package]] +name = "deno_core_icudata" +version = "0.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13951ea98c0a4c372f162d669193b4c9d991512de9f2381dd161027f34b26b1" + [[package]] name = "deno_crypto" -version = "0.141.0" +version = "0.150.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c491190b39ba91cff55ca2c285a11a885ac3bb2ed11a4dbc54cdc02fa31411b9" +checksum = "fe3cc83b7fe945183ef27be203c54276abef9fbda4844722f10e0af341a316fd" dependencies = [ "aes", "aes-gcm", @@ -891,6 +924,7 @@ dependencies = [ "once_cell", "p256", "p384", + "p521", "rand", "ring 0.17.7", "rsa", @@ -907,9 +941,9 @@ dependencies = [ [[package]] name = "deno_fetch" -version = "0.151.0" +version = "0.160.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf39d15b9e0f8f1b66a856f57a91ae3dec7e501bc5800cd9122f3cb16e85c9f5" +checksum = "5860515fb73057028018761e937edc4c910207d40d9d9721bb0bb1dfc355fb54" dependencies = [ "bytes", "data-url", @@ -917,8 +951,10 @@ dependencies = [ "deno_tls", "dyn-clone", "http", + "pin-project", "reqwest", "serde", + "serde_json", "tokio", "tokio-util", ] @@ -938,9 +974,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.108.0" +version = "0.132.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7dde627916f8539f3f0d2e754dda40810c8ca4d655f2eaac1ef54785a12fd27" +checksum = "02163d08afdd6fcf21e37c399c7425987c7170203a853052a800e80c91c2e87b" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -953,9 +989,9 @@ dependencies = [ [[package]] name = "deno_tls" -version = "0.114.0" +version = "0.123.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97205b229f51eb037c2ca9a827d78b2cdfa9d28065e35c6d3014353ada6e4594" +checksum = "334380ef454db2148df9aba7541bc8250bb4e6fb183ece9fdb293be0462eb7ad" dependencies = [ "deno_core", "deno_native_certs", @@ -969,18 +1005,18 @@ dependencies = [ [[package]] name = "deno_unsync" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a8f3722afd50e566ecfc783cc8a3a046bc4dd5eb45007431dfb2776aeb8993" +checksum = "30dff7e03584dbae188dae96a0f1876740054809b2ad0cf7c9fc5d361f20e739" dependencies = [ "tokio", ] [[package]] name = "deno_url" -version = "0.127.0" +version = "0.136.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1539aae8dc4e9566b4534da29aa7606c634f32a75585e1fdd6bb0010f527e639" +checksum = "7978221ce33221ac7a18b649a5a18fe7983fbe2fddf5a6959fc672089c10f9a9" dependencies = [ "deno_core", "serde", @@ -989,9 +1025,9 @@ dependencies = [ [[package]] name = "deno_web" -version = "0.158.0" +version = "0.167.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b926030905590d563f6b194458cc0956aa9ca4774bdbb201c11956772c5c665" +checksum = "67d78f50e55155b77abbf8fa6bdc24f68442c91742e03b67b66cc258f4b31cd1" dependencies = [ "async-trait", "base64-simd", @@ -1008,9 +1044,9 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.127.0" +version = "0.136.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff2678fcf30a2bd019e25ed611d7d895172b1208424c2423d4f681e30ce44e8" +checksum = "41eff4e69896e0f7fc432271c369052efd1d0b57a3d352688e2df800d1aa8dd9" dependencies = [ "deno_core", ] @@ -1333,9 +1369,9 @@ dependencies = [ [[package]] name = "fslock" -version = "0.1.8" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57eafdd0c16f57161105ae1b98a1238f97645f2f588438b2949c99a2af9616bf" +checksum = "04412b8935272e3a9bae6f48c7bfff74c2911f60525404edfdd28e49884c3bfb" dependencies = [ "libc", "winapi", @@ -2744,6 +2780,20 @@ dependencies = [ "sha2", ] +[[package]] +name = "p521" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc9e2161f1f215afdfce23677034ae137bbd45016a880c2eb3ba8eb95f085b2" +dependencies = [ + "base16ct", + "ecdsa", + "elliptic-curve", + "primeorder", + "rand_core 0.6.4", + "sha2", +] + [[package]] name = "parking" version = "2.2.0" @@ -3227,9 +3277,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "reqwest" -version = "0.11.22" +version = "0.11.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +checksum = "3e9ad3fe7488d7e34558a2033d45a0c90b72d97b4f80705666fea71472e2e6a1" dependencies = [ "async-compression", "base64 0.21.5", @@ -3254,7 +3304,6 @@ dependencies = [ "serde", "serde_json", "serde_urlencoded", - "system-configuration", "tokio", "tokio-rustls", "tokio-socks", @@ -3650,9 +3699,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.141.0" +version = "0.165.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc689cb316d67b200e9f7449ce76cceb7e483e0f828d1a9c3d057c4367b6c26e" +checksum = "88862d513bcbc04a7f93b0f454dffd0b01a5c0d8e1964c7532ec55f52b9a6351" dependencies = [ "bytes", "derive_more", @@ -4318,11 +4367,11 @@ dependencies = [ [[package]] name = "v8" -version = "0.81.0" +version = "0.83.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75f5f378b9b54aff3b10da8170d26af4cfd217f644cf671badcd13af5db4beb" +checksum = "546dcbb978f58aea3ad9286bd1df553f4ab7bbdc2e191cd4ae6c9a98fa95d1cd" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.1", "fslock", "once_cell", "which", @@ -4529,14 +4578,15 @@ checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" [[package]] name = "which" -version = "4.4.2" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +checksum = "9bf3ea8596f3a0dd5980b46430f2058dfe2c36a27ccfbb1845d6fbfcd9ba6e14" dependencies = [ "either", "home", "once_cell", "rustix", + "windows-sys 0.48.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e035785f..d0a0a79c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ repository = "https://github.com/filecoin-station/zinnia" assert_cmd = "2.0.13" assert_fs = "1.1.1" console_static_text = "=0.8.1" -deno_core = "0.232.0" +deno_core = "0.256.0" log = "0.4.20" pretty_assertions = "1.4.0" env_logger = "0.10.2" diff --git a/cli/tests/cli_tests.rs b/cli/tests/cli_tests.rs index 6580cc25..96e6ad83 100644 --- a/cli/tests/cli_tests.rs +++ b/cli/tests/cli_tests.rs @@ -72,7 +72,7 @@ function fail() { let expected_stderr = format!( r#" - error: Uncaught Error: boom! + error: Uncaught (in promise) Error: boom! throw new Error("boom!"); ^ at fail ({mod_url}:5:9) diff --git a/ext/libp2p/js/01_peer.js b/ext/libp2p/js/01_peer.js index 54e32f4b..a7fb361e 100644 --- a/ext/libp2p/js/01_peer.js +++ b/ext/libp2p/js/01_peer.js @@ -1,5 +1,6 @@ const core = globalThis.Deno.core; -const { ops, opAsync } = core; +const { ops } = core; +const { op_p2p_request_protocol } = core.ensureFastOps(); async function requestProtocol(remoteAddress, protocolName, requestPayload) { if (typeof remoteAddress !== "string") @@ -11,8 +12,7 @@ async function requestProtocol(remoteAddress, protocolName, requestPayload) { throw new TypeError(`requestPayload must be Uint8Array (found: ${actualType})`); } - const responsePayload = await opAsync( - "op_p2p_request_protocol", + const responsePayload = await op_p2p_request_protocol( remoteAddress, protocolName, requestPayload, diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index db19854e..a1d816df 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -14,13 +14,13 @@ path = "lib.rs" [dependencies] console_static_text.workspace = true chrono = { version= "0.4.33", default-features = false, features = [ "clock", "std" ] } -deno_console = "0.127.0" +deno_console = "0.136.0" deno_core.workspace = true -deno_crypto = "0.141.0" -deno_fetch = "0.151.0" -deno_url = "0.127.0" -deno_web = "0.158.0" -deno_webidl = "0.127.0" +deno_crypto = "0.150.0" +deno_fetch = "0.160.0" +deno_url = "0.136.0" +deno_web = "0.167.0" +deno_webidl = "0.136.0" lassie = "0.9.0" # lassie = { git = "https://github.com/filecoin-station/rusty-lassie.git" } log.workspace = true diff --git a/runtime/js/98_global_scope.js b/runtime/js/98_global_scope.js index 1fd93c71..9f9a5b0f 100644 --- a/runtime/js/98_global_scope.js +++ b/runtime/js/98_global_scope.js @@ -27,7 +27,7 @@ import * as eventSource from "ext:deno_fetch/27_eventsource.js"; import * as fetch from "ext:zinnia_runtime/fetch.js"; import * as messagePort from "ext:deno_web/13_message_port.js"; import * as webidl from "ext:deno_webidl/00_webidl.js"; -import DOMException from "ext:deno_web/01_dom_exception.js"; +import { DOMException } from "ext:deno_web/01_dom_exception.js"; import * as abortSignal from "ext:deno_web/03_abort_signal.js"; import * as globalInterfaces from "ext:deno_web/04_global_interfaces.js"; import { zinniaNs, log } from "ext:zinnia_runtime/90_zinnia_apis.js"; diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index d83467bf..2589e8f4 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -29,7 +29,6 @@ import { inspectArgs, quoteString, setNoColorFn, - wrapConsole, } from "ext:deno_console/01_console.js"; import * as performance from "ext:deno_web/15_performance.js"; import { @@ -94,7 +93,7 @@ function bootstrapMainRuntime(runtimeOptions) { if (runtimeOptions.inspectFlag) { const consoleFromV8 = core.console; const consoleFromDeno = globalThis.console; - wrapConsole(consoleFromDeno, consoleFromV8); + core.wrapConsole(consoleFromDeno, consoleFromV8); } event.setEventTargetData(globalThis); diff --git a/runtime/module_loader.rs b/runtime/module_loader.rs index cd31e0ed..8ded81c4 100644 --- a/runtime/module_loader.rs +++ b/runtime/module_loader.rs @@ -4,8 +4,8 @@ use deno_core::anyhow::anyhow; use deno_core::error::type_error; use deno_core::futures::FutureExt; use deno_core::{ - resolve_import, ModuleLoader, ModuleSource, ModuleSourceFuture, ModuleSpecifier, ModuleType, - ResolutionKind, + resolve_import, ModuleLoader, ModuleSource, ModuleSourceCode, ModuleSpecifier, ModuleType, + RequestedModuleType, ResolutionKind, }; use tokio::fs::File; @@ -65,11 +65,14 @@ impl ModuleLoader for ZinniaModuleLoader { module_specifier: &ModuleSpecifier, maybe_referrer: Option<&ModuleSpecifier>, _is_dyn_import: bool, - ) -> std::pin::Pin> { + // TODO(bajtos): support loading JSON files as ES modules. See + // https://github.com/denoland/deno/commit/bc8d00c880756a46b0ce4c8bf0c89407a2de669c + _requested_module_type: RequestedModuleType, + ) -> deno_core::ModuleLoadResponse { let module_specifier = module_specifier.clone(); let module_root = self.module_root.clone(); let maybe_referrer = maybe_referrer.cloned(); - async move { + deno_core::ModuleLoadResponse::Async(async move { let spec_str = module_specifier.as_str(); let code = { @@ -85,18 +88,23 @@ impl ModuleLoader for ZinniaModuleLoader { .map(|p| p.starts_with(root)) .unwrap_or(false), } - }, + } }; if is_module_local { read_file_to_string(module_specifier.to_file_path().unwrap()).await? - } else if spec_str == "https://deno.land/std@0.177.0/testing/asserts.ts" || spec_str == "https://deno.land/std@0.181.0/testing/asserts.ts" { + } else if spec_str == "https://deno.land/std@0.177.0/testing/asserts.ts" + || spec_str == "https://deno.land/std@0.181.0/testing/asserts.ts" + { return Err(anyhow!( "Zinnia bundles Deno asserts as 'zinnia:assert`. Please update your imports accordingly.\nModule URL: {spec_str}\nImported from: {}", maybe_referrer.map(|u| u.to_string()).unwrap_or("(none)".into()) )); } else { let mut msg = if module_specifier.scheme() == "file" && module_root.is_some() { - format!("Cannot import files outside of module root directory {}. ", module_root.unwrap().display()) + format!( + "Cannot import files outside of module root directory {}. ", + module_root.unwrap().display() + ) } else { "Zinnia supports importing from relative paths only. ".to_string() }; @@ -109,9 +117,13 @@ impl ModuleLoader for ZinniaModuleLoader { } }; - let module = ModuleSource::new(ModuleType::JavaScript, code.into(), &module_specifier); + let module = ModuleSource::new( + ModuleType::JavaScript, + ModuleSourceCode::String(code.into()), + &module_specifier + ); Ok(module) - }.boxed_local() + }.boxed_local()) } } @@ -134,7 +146,7 @@ async fn read_file_to_string(path: impl AsRef) -> Result #[cfg(test)] mod tests { use super::*; - use deno_core::anyhow::Context; + use deno_core::{anyhow::Context, ModuleLoadResponse}; use pretty_assertions::assert_eq; #[tokio::test] @@ -143,13 +155,17 @@ mod tests { imported_file.push("99_main.js"); let loader = ZinniaModuleLoader::build(Some(get_js_dir())).unwrap(); - let result = loader - .load( - &ModuleSpecifier::from_file_path(&imported_file).unwrap(), - None, - false, - ) - .await + let result = loader.load( + &ModuleSpecifier::from_file_path(&imported_file).unwrap(), + None, + false, + RequestedModuleType::None, + ); + let result = match result { + ModuleLoadResponse::Async(result) => result.await, + ModuleLoadResponse::Sync(result) => result, + }; + let result = result .with_context(|| format!("cannot import {}", imported_file.display())) .unwrap(); @@ -168,13 +184,16 @@ mod tests { imported_file.push("99_main.js"); let loader = ZinniaModuleLoader::build(Some(project_root)).unwrap(); - let result = loader - .load( - &ModuleSpecifier::from_file_path(&imported_file).unwrap(), - None, - false, - ) - .await; + let result = loader.load( + &ModuleSpecifier::from_file_path(&imported_file).unwrap(), + None, + false, + RequestedModuleType::None, + ); + let result = match result { + ModuleLoadResponse::Async(result) => result.await, + ModuleLoadResponse::Sync(result) => result, + }; match result { Ok(_) => { diff --git a/runtime/runtime.rs b/runtime/runtime.rs index 0babab2d..10ed6ed5 100644 --- a/runtime/runtime.rs +++ b/runtime/runtime.rs @@ -128,8 +128,8 @@ pub async fn run_js_module( // Load and run the module let main_module_id = runtime.load_main_module(module_specifier, None).await?; let res = runtime.mod_evaluate(main_module_id); - runtime.run_event_loop(false).await?; - res.await??; + runtime.run_event_loop(Default::default()).await?; + res.await?; // TODO: it would be nicer to have this exposed as another Deno op // and call it from the JavaScript side as part of the regular runtime shutdown