diff --git a/cli/factory.rs b/cli/factory.rs index fb429704543db4..a2755c1290e6d6 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -83,20 +83,17 @@ impl CliFactoryBuilder { } } - pub async fn build_from_flags( - self, - flags: Flags, - ) -> Result { + pub fn build_from_flags(self, flags: Flags) -> Result { Ok(self.build_from_cli_options(Arc::new(CliOptions::from_flags(flags)?))) } - pub async fn build_from_flags_for_watcher( + pub fn build_from_flags_for_watcher( mut self, flags: Flags, watcher_communicator: Arc, ) -> Result { self.watcher_communicator = Some(watcher_communicator); - self.build_from_flags(flags).await + self.build_from_flags(flags) } pub fn build_from_cli_options(self, options: Arc) -> CliFactory { @@ -190,8 +187,8 @@ pub struct CliFactory { } impl CliFactory { - pub async fn from_flags(flags: Flags) -> Result { - CliFactoryBuilder::new().build_from_flags(flags).await + pub fn from_flags(flags: Flags) -> Result { + CliFactoryBuilder::new().build_from_flags(flags) } pub fn from_cli_options(options: Arc) -> Self { diff --git a/cli/lsp/code_lens.rs b/cli/lsp/code_lens.rs index 59787dd84e14ac..8300546b431640 100644 --- a/cli/lsp/code_lens.rs +++ b/cli/lsp/code_lens.rs @@ -415,7 +415,7 @@ pub fn collect_test( } /// Return tsc navigation tree code lenses. -pub async fn collect_tsc( +pub fn collect_tsc( specifier: &ModuleSpecifier, code_lens_settings: &CodeLensSettings, line_index: Arc, diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 3555a0545285df..08bb37c7c6abbf 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -786,7 +786,7 @@ impl Inner { }) } - pub async fn update_cache(&mut self) -> Result<(), AnyError> { + pub fn update_cache(&mut self) -> Result<(), AnyError> { let mark = self.performance.mark("lsp.update_cache"); self.performance.measure(mark); let maybe_cache = &self.config.workspace_settings().cache; @@ -816,23 +816,17 @@ impl Inner { None }; if self.maybe_global_cache_path != maybe_global_cache_path { - self - .set_new_global_cache_path(maybe_global_cache_path) - .await?; + self.set_new_global_cache_path(maybe_global_cache_path)?; } Ok(()) } - async fn recreate_http_client_and_dependents( - &mut self, - ) -> Result<(), AnyError> { - self - .set_new_global_cache_path(self.maybe_global_cache_path.clone()) - .await + fn recreate_http_client_and_dependents(&mut self) -> Result<(), AnyError> { + self.set_new_global_cache_path(self.maybe_global_cache_path.clone()) } /// Recreates the http client and all dependent structs. - async fn set_new_global_cache_path( + fn set_new_global_cache_path( &mut self, new_cache_path: Option, ) -> Result<(), AnyError> { @@ -1025,21 +1019,21 @@ impl Inner { async fn update_registries(&mut self) -> Result<(), AnyError> { let mark = self.performance.mark("lsp.update_registries"); - self.recreate_http_client_and_dependents().await?; + self.recreate_http_client_and_dependents()?; let workspace_settings = self.config.workspace_settings(); for (registry, enabled) in workspace_settings.suggest.imports.hosts.iter() { if *enabled { lsp_log!("Enabling import suggestions for: {}", registry); self.module_registries.enable(registry).await?; } else { - self.module_registries.disable(registry).await?; + self.module_registries.disable(registry)?; } } self.performance.measure(mark); Ok(()) } - async fn update_config_file(&mut self) -> Result<(), AnyError> { + fn update_config_file(&mut self) -> Result<(), AnyError> { self.config.clear_config_file(); self.fmt_options = FmtOptions::new_with_base(self.initial_cwd.clone()); self.lint_options = LintOptions::new_with_base(self.initial_cwd.clone()); @@ -1064,7 +1058,7 @@ impl Inner { self.config.set_config_file(config_file); self.lint_options = lint_options; self.fmt_options = fmt_options; - self.recreate_http_client_and_dependents().await?; + self.recreate_http_client_and_dependents()?; if let Some(config_file) = self.config.maybe_config_file() { if let Ok((compiler_options, _)) = config_file.to_compiler_options() { if let Some(compiler_options_obj) = compiler_options.as_object() { @@ -1278,11 +1272,11 @@ impl Inner { self.update_debug_flag(); // Check to see if we need to change the cache path - if let Err(err) = self.update_cache().await { + if let Err(err) = self.update_cache() { lsp_warn!("Error updating cache: {:#}", err); self.client.show_message(MessageType::WARNING, err); } - if let Err(err) = self.update_config_file().await { + if let Err(err) = self.update_config_file() { lsp_warn!("Error updating config file: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -1349,11 +1343,11 @@ impl Inner { self.refresh_npm_specifiers().await; } - async fn shutdown(&self) -> LspResult<()> { + fn shutdown(&self) -> LspResult<()> { Ok(()) } - async fn did_open( + fn did_open( &mut self, specifier: &ModuleSpecifier, params: DidOpenTextDocumentParams, @@ -1475,7 +1469,7 @@ impl Inner { }; self.update_debug_flag(); - if let Err(err) = self.update_cache().await { + if let Err(err) = self.update_cache() { lsp_warn!("Error updating cache: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -1483,7 +1477,7 @@ impl Inner { lsp_warn!("Error updating registries: {:#}", err); self.client.show_message(MessageType::WARNING, err); } - if let Err(err) = self.update_config_file().await { + if let Err(err) = self.update_config_file() { lsp_warn!("Error updating config file: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -1601,7 +1595,7 @@ impl Inner { files_to_check.insert(url.clone()); } // Update config. - if let Err(err) = self.update_config_file().await { + if let Err(err) = self.update_config_file() { lsp_warn!("Error updating config file: {:#}", err); self.client.show_message(MessageType::WARNING, err); } @@ -2246,7 +2240,7 @@ impl Inner { )), ) .await?; - code_action.edit = refactor_edit_info.to_workspace_edit(self).await?; + code_action.edit = refactor_edit_info.to_workspace_edit(self)?; code_action } else { // The code action doesn't need to be resolved @@ -2314,7 +2308,6 @@ impl Inner { line_index, &navigation_tree, ) - .await .map_err(|err| { error!( "Error getting ts code lenses for \"{:#}\": {:#}", @@ -2483,7 +2476,7 @@ impl Inner { .await?; if let Some(definition) = maybe_definition { - let results = definition.to_definition(line_index, self).await; + let results = definition.to_definition(line_index, self); self.performance.measure(mark); Ok(results) } else { @@ -2978,7 +2971,6 @@ impl Inner { let rename_locations = tsc::RenameLocations { locations }; let workspace_edits = rename_locations .into_workspace_edit(¶ms.new_name, self) - .await .map_err(|err| { error!("Failed to get workspace edits: {:#}", err); LspError::internal_error() @@ -3426,7 +3418,7 @@ impl tower_lsp::LanguageServer for LanguageServer { async fn shutdown(&self) -> LspResult<()> { self.1.cancel(); - self.0.write().await.shutdown().await + self.0.write().await.shutdown() } async fn did_open(&self, params: DidOpenTextDocumentParams) { @@ -3441,7 +3433,7 @@ impl tower_lsp::LanguageServer for LanguageServer { let specifier = inner .url_map .normalize_url(¶ms.text_document.uri, LspUrlKind::File); - let document = inner.did_open(&specifier, params).await; + let document = inner.did_open(&specifier, params); if document.is_diagnosable() { inner.refresh_npm_specifiers().await; let specifiers = inner.documents.dependents(&specifier); diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index 2b0cae7d27248c..b0eeb9df04ef74 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -488,7 +488,7 @@ impl ModuleRegistry { } /// Disable a registry, removing its configuration, if any, from memory. - pub async fn disable(&mut self, origin: &str) -> Result<(), AnyError> { + pub fn disable(&mut self, origin: &str) -> Result<(), AnyError> { let origin = base_url(&Url::parse(origin)?); self.origins.remove(&origin); Ok(()) diff --git a/cli/lsp/testing/execution.rs b/cli/lsp/testing/execution.rs index 02d03799622179..6b89f0e43e36bc 100644 --- a/cli/lsp/testing/execution.rs +++ b/cli/lsp/testing/execution.rs @@ -213,7 +213,7 @@ impl TestRun { let args = self.get_args(); lsp_log!("Executing test run with arguments: {}", args.join(" ")); let flags = flags_from_vec(args.into_iter().map(String::from).collect())?; - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; // Various test files should not share the same permissions in terms of // `PermissionsContainer` - otherwise granting/revoking permissions in one // file would have impact on other files, which is undesirable. diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index 10402416722baf..3fc78a20f2742f 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -2106,7 +2106,7 @@ pub struct RenameLocations { } impl RenameLocations { - pub async fn into_workspace_edit( + pub fn into_workspace_edit( self, new_name: &str, language_server: &language_server::Inner, @@ -2226,7 +2226,7 @@ impl DefinitionInfoAndBoundSpan { Ok(()) } - pub async fn to_definition( + pub fn to_definition( &self, line_index: Arc, language_server: &language_server::Inner, @@ -2609,7 +2609,7 @@ impl RefactorEditInfo { Ok(()) } - pub async fn to_workspace_edit( + pub fn to_workspace_edit( &self, language_server: &language_server::Inner, ) -> LspResult> { diff --git a/cli/main.rs b/cli/main.rs index 3d72a3334324d0..729559d9a11931 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -109,7 +109,7 @@ async fn run_subcommand(flags: Flags) -> Result { tools::run::eval_command(flags, eval_flags).await }), DenoSubcommand::Cache(cache_flags) => spawn_subcommand(async move { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let module_load_preparer = factory.module_load_preparer().await?; let emitter = factory.emitter()?; let graph_container = factory.graph_container(); @@ -119,7 +119,7 @@ async fn run_subcommand(flags: Flags) -> Result { emitter.cache_module_emits(&graph_container.graph()) }), DenoSubcommand::Check(check_flags) => spawn_subcommand(async move { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let module_load_preparer = factory.module_load_preparer().await?; module_load_preparer .load_and_type_check_files(&check_flags.files) @@ -137,7 +137,11 @@ async fn run_subcommand(flags: Flags) -> Result { ) } DenoSubcommand::Init(init_flags) => { - spawn_subcommand(async { tools::init::init_project(init_flags).await }) + spawn_subcommand(async { + // make compiler happy since init_project is sync + tokio::task::yield_now().await; + tools::init::init_project(init_flags) + }) } DenoSubcommand::Info(info_flags) => { spawn_subcommand(async { tools::info::info(flags, info_flags).await }) diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs index b554f73495c8eb..c640bea40b5913 100644 --- a/cli/tools/bench/mod.rs +++ b/cli/tools/bench/mod.rs @@ -487,8 +487,7 @@ pub async fn run_benchmarks_with_watch( let bench_flags = bench_flags.clone(); Ok(async move { let factory = CliFactoryBuilder::new() - .build_from_flags_for_watcher(flags, watcher_communicator.clone()) - .await?; + .build_from_flags_for_watcher(flags, watcher_communicator.clone())?; let cli_options = factory.cli_options(); let bench_options = cli_options.resolve_bench_options(bench_flags)?; diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs index 0a992fcb04f47f..23d5aacb12603c 100644 --- a/cli/tools/bundle.rs +++ b/cli/tools/bundle.rs @@ -35,9 +35,10 @@ pub async fn bundle( move |flags, watcher_communicator, _changed_paths| { let bundle_flags = bundle_flags.clone(); Ok(async move { - let factory = CliFactoryBuilder::new() - .build_from_flags_for_watcher(flags, watcher_communicator.clone()) - .await?; + let factory = CliFactoryBuilder::new().build_from_flags_for_watcher( + flags, + watcher_communicator.clone(), + )?; let cli_options = factory.cli_options(); let _ = watcher_communicator.watch_paths(cli_options.watch_paths()); bundle_action(factory, &bundle_flags).await?; @@ -48,7 +49,7 @@ pub async fn bundle( ) .await?; } else { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; bundle_action(factory, &bundle_flags).await?; } diff --git a/cli/tools/compile.rs b/cli/tools/compile.rs index 0e8df295294528..ed8f07542a9e6b 100644 --- a/cli/tools/compile.rs +++ b/cli/tools/compile.rs @@ -22,7 +22,7 @@ pub async fn compile( flags: Flags, compile_flags: CompileFlags, ) -> Result<(), AnyError> { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let module_graph_creator = factory.module_graph_creator().await?; let parsed_source_cache = factory.parsed_source_cache(); diff --git a/cli/tools/coverage/mod.rs b/cli/tools/coverage/mod.rs index 66c0923de4317d..e5bd3ae2e25599 100644 --- a/cli/tools/coverage/mod.rs +++ b/cli/tools/coverage/mod.rs @@ -462,7 +462,7 @@ pub async fn cover_files( return Err(generic_error("No matching coverage profiles found")); } - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let npm_resolver = factory.npm_resolver().await?; let file_fetcher = factory.file_fetcher()?; let cli_options = factory.cli_options(); diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 013a407aa0128b..b3240dd370e721 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -17,7 +17,6 @@ use deno_config::glob::PathOrPatternSet; use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::AnyError; -use deno_core::futures::FutureExt; use deno_doc as doc; use deno_graph::GraphKind; use deno_graph::ModuleAnalyzer; @@ -73,7 +72,7 @@ async fn generate_doc_nodes_for_builtin_types( } pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let module_info_cache = factory.module_info_cache()?; let parsed_source_cache = factory.parsed_source_cache(); @@ -156,8 +155,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { }; generate_docs_directory(&doc_nodes_by_url, html_options, deno_ns) - .boxed_local() - .await } else { let modules_len = doc_nodes_by_url.len(); let doc_nodes = @@ -224,7 +221,7 @@ impl deno_doc::html::HrefResolver for DocResolver { } } -async fn generate_docs_directory( +fn generate_docs_directory( doc_nodes_by_url: &IndexMap>, html_options: &DocHtmlFlag, deno_ns: std::collections::HashSet>, diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 0f6afb232b750e..241648d9816de6 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -68,7 +68,7 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> { move |flags, watcher_communicator, changed_paths| { let fmt_flags = fmt_flags.clone(); Ok(async move { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let fmt_options = cli_options.resolve_fmt_options(fmt_flags)?; let files = @@ -113,7 +113,7 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> { ) .await?; } else { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let fmt_options = cli_options.resolve_fmt_options(fmt_flags)?; let files = diff --git a/cli/tools/info.rs b/cli/tools/info.rs index ca08003ad98bc3..7c1d6761a2907f 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -36,7 +36,7 @@ use crate::npm::ManagedCliNpmResolver; use crate::util::checksum; pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); if let Some(specifier) = info_flags.file { let module_graph_builder = factory.module_graph_builder().await?; diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index d0e1990854de23..7222a762f6309f 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -32,7 +32,7 @@ fn create_file( } } -pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { +pub fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { let cwd = std::env::current_dir().context("Can't read current working directory.")?; let dir = if let Some(dir) = &init_flags.dir { diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index a48599adab605a..1b1b6f30c1aa50 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -242,8 +242,7 @@ pub async fn install_command( install_flags: InstallFlags, ) -> Result<(), AnyError> { // ensure the module is cached - CliFactory::from_flags(flags.clone()) - .await? + CliFactory::from_flags(flags.clone())? .module_load_preparer() .await? .load_and_type_check_files(&[install_flags.module_url.clone()]) diff --git a/cli/tools/jupyter/mod.rs b/cli/tools/jupyter/mod.rs index cf1a44ea5cf2da..cfed1c3991d637 100644 --- a/cli/tools/jupyter/mod.rs +++ b/cli/tools/jupyter/mod.rs @@ -54,7 +54,7 @@ pub async fn kernel( logger::init(Some(log::Level::Debug)); } - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let main_module = resolve_url_or_path("./$deno$jupyter.ts", cli_options.initial_cwd()) diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 1b81fca5a64b7e..251efd9412a222 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -74,7 +74,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { move |flags, watcher_communicator, changed_paths| { let lint_flags = lint_flags.clone(); Ok(async move { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let lint_options = cli_options.resolve_lint_options(lint_flags)?; let files = collect_lint_files(lint_options.files.clone()).and_then( @@ -110,7 +110,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> { ) .await?; } else { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let is_stdin = lint_flags.is_stdin(); let lint_options = cli_options.resolve_lint_options(lint_flags)?; diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index 8b1b505a0cdec9..cb3428b602d99e 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -912,7 +912,7 @@ pub async fn publish( flags: Flags, publish_flags: PublishFlags, ) -> Result<(), AnyError> { - let cli_factory = CliFactory::from_flags(flags).await?; + let cli_factory = CliFactory::from_flags(flags)?; let auth_method = get_auth_method(publish_flags.token, publish_flags.dry_run)?; diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index e9044a5d11d711..8a0a53c9af2fd2 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -26,7 +26,7 @@ use crate::jsr::JsrFetchResolver; use crate::npm::NpmFetchResolver; pub async fn add(flags: Flags, add_flags: AddFlags) -> Result<(), AnyError> { - let cli_factory = CliFactory::from_flags(flags.clone()).await?; + let cli_factory = CliFactory::from_flags(flags.clone())?; let cli_options = cli_factory.cli_options(); let Some(config_file) = cli_options.maybe_config_file() else { diff --git a/cli/tools/repl/mod.rs b/cli/tools/repl/mod.rs index 98519b60dcd1c8..698abb691912b3 100644 --- a/cli/tools/repl/mod.rs +++ b/cli/tools/repl/mod.rs @@ -152,7 +152,7 @@ async fn read_eval_file( } pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let main_module = cli_options.resolve_main_module()?; let permissions = PermissionsContainer::new(Permissions::from_options( diff --git a/cli/tools/repl/session.rs b/cli/tools/repl/session.rs index 65e27136f00612..039dc0d7152ea1 100644 --- a/cli/tools/repl/session.rs +++ b/cli/tools/repl/session.rs @@ -200,7 +200,7 @@ impl ReplSession { test_event_receiver: TestEventReceiver, ) -> Result { let language_server = ReplLanguageServer::new_initialized().await?; - let mut session = worker.create_inspector_session().await; + let mut session = worker.create_inspector_session(); worker .js_runtime diff --git a/cli/tools/run/mod.rs b/cli/tools/run/mod.rs index 0de852fc222cfa..793b55a8acfa46 100644 --- a/cli/tools/run/mod.rs +++ b/cli/tools/run/mod.rs @@ -39,7 +39,7 @@ To grant permissions, set them before the script argument. For example: // TODO(bartlomieju): actually I think it will also fail if there's an import // map specified and bare specifier is used on the command line - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let deno_dir = factory.deno_dir()?; let http_client = factory.http_client(); let cli_options = factory.cli_options(); @@ -76,7 +76,7 @@ To grant permissions, set them before the script argument. For example: } pub async fn run_from_stdin(flags: Flags) -> Result { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let main_module = cli_options.resolve_main_module()?; @@ -121,8 +121,7 @@ async fn run_with_watch( move |flags, watcher_communicator, _changed_paths| { Ok(async move { let factory = CliFactoryBuilder::new() - .build_from_flags_for_watcher(flags, watcher_communicator.clone()) - .await?; + .build_from_flags_for_watcher(flags, watcher_communicator.clone())?; let cli_options = factory.cli_options(); let main_module = cli_options.resolve_main_module()?; @@ -158,7 +157,7 @@ pub async fn eval_command( flags: Flags, eval_flags: EvalFlags, ) -> Result { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let file_fetcher = factory.file_fetcher()?; let main_module = cli_options.resolve_main_module()?; diff --git a/cli/tools/task.rs b/cli/tools/task.rs index dfb0c585e0c383..124d760dbd6efe 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -32,7 +32,7 @@ pub async fn execute_script( flags: Flags, task_flags: TaskFlags, ) -> Result { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let tasks_config = cli_options.resolve_tasks_config()?; let maybe_package_json = cli_options.maybe_package_json(); diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index ec6c362551031a..a95590433ca1ad 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -1479,7 +1479,7 @@ pub async fn run_tests( flags: Flags, test_flags: TestFlags, ) -> Result<(), AnyError> { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let cli_options = factory.cli_options(); let test_options = cli_options.resolve_test_options(test_flags)?; let file_fetcher = factory.file_fetcher()?; @@ -1577,8 +1577,7 @@ pub async fn run_tests_with_watch( let test_flags = test_flags.clone(); Ok(async move { let factory = CliFactoryBuilder::new() - .build_from_flags_for_watcher(flags, watcher_communicator.clone()) - .await?; + .build_from_flags_for_watcher(flags, watcher_communicator.clone())?; let cli_options = factory.cli_options(); let test_options = cli_options.resolve_test_options(test_flags)?; diff --git a/cli/tools/upgrade.rs b/cli/tools/upgrade.rs index c66fa0b3e19c78..86a271c1fc22fc 100644 --- a/cli/tools/upgrade.rs +++ b/cli/tools/upgrade.rs @@ -376,7 +376,7 @@ pub async fn upgrade( flags: Flags, upgrade_flags: UpgradeFlags, ) -> Result<(), AnyError> { - let factory = CliFactory::from_flags(flags).await?; + let factory = CliFactory::from_flags(flags)?; let client = factory.http_client(); let current_exe_path = std::env::current_exe()?; let output_exe_path = diff --git a/cli/worker.rs b/cli/worker.rs index 69751447788851..f0c7bfabc45149 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -355,7 +355,7 @@ impl CliMainWorker { return Ok(None); }; - let session = self.worker.create_inspector_session().await; + let session = self.worker.create_inspector_session(); let mut hmr_runner = setup_hmr_runner(session); @@ -379,7 +379,7 @@ impl CliMainWorker { return Ok(None); }; - let session = self.worker.create_inspector_session().await; + let session = self.worker.create_inspector_session(); let mut coverage_collector = create_coverage_collector(session); self .worker diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index 5e99e99dfe8249..8a526bb40ab7be 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -198,104 +198,106 @@ pub async fn op_crypto_sign_key( #[serde] args: SignArg, #[buffer] zero_copy: JsBuffer, ) -> Result { - let data = &*zero_copy; - let algorithm = args.algorithm; - - let signature = match algorithm { - Algorithm::RsassaPkcs1v15 => { - use rsa::pkcs1v15::SigningKey; - let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?; - match args - .hash - .ok_or_else(|| type_error("Missing argument hash".to_string()))? - { - CryptoHash::Sha1 => { - let signing_key = SigningKey::::new(private_key); - signing_key.sign(data) - } - CryptoHash::Sha256 => { - let signing_key = SigningKey::::new(private_key); - signing_key.sign(data) - } - CryptoHash::Sha384 => { - let signing_key = SigningKey::::new(private_key); - signing_key.sign(data) - } - CryptoHash::Sha512 => { - let signing_key = SigningKey::::new(private_key); - signing_key.sign(data) + deno_core::unsync::spawn_blocking(move || { + let data = &*zero_copy; + let algorithm = args.algorithm; + + let signature = match algorithm { + Algorithm::RsassaPkcs1v15 => { + use rsa::pkcs1v15::SigningKey; + let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?; + match args + .hash + .ok_or_else(|| type_error("Missing argument hash".to_string()))? + { + CryptoHash::Sha1 => { + let signing_key = SigningKey::::new(private_key); + signing_key.sign(data) + } + CryptoHash::Sha256 => { + let signing_key = SigningKey::::new(private_key); + signing_key.sign(data) + } + CryptoHash::Sha384 => { + let signing_key = SigningKey::::new(private_key); + signing_key.sign(data) + } + CryptoHash::Sha512 => { + let signing_key = SigningKey::::new(private_key); + signing_key.sign(data) + } } + .to_vec() } - .to_vec() - } - Algorithm::RsaPss => { - let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?; - - let salt_len = args - .salt_length - .ok_or_else(|| type_error("Missing argument saltLength".to_string()))? - as usize; - - let mut rng = OsRng; - match args - .hash - .ok_or_else(|| type_error("Missing argument hash".to_string()))? - { - CryptoHash::Sha1 => { - let signing_key = Pss::new_with_salt::(salt_len); - let hashed = Sha1::digest(data); - signing_key.sign(Some(&mut rng), &private_key, &hashed)? - } - CryptoHash::Sha256 => { - let signing_key = Pss::new_with_salt::(salt_len); - let hashed = Sha256::digest(data); - signing_key.sign(Some(&mut rng), &private_key, &hashed)? - } - CryptoHash::Sha384 => { - let signing_key = Pss::new_with_salt::(salt_len); - let hashed = Sha384::digest(data); - signing_key.sign(Some(&mut rng), &private_key, &hashed)? - } - CryptoHash::Sha512 => { - let signing_key = Pss::new_with_salt::(salt_len); - let hashed = Sha512::digest(data); - signing_key.sign(Some(&mut rng), &private_key, &hashed)? + Algorithm::RsaPss => { + let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?; + + let salt_len = args.salt_length.ok_or_else(|| { + type_error("Missing argument saltLength".to_string()) + })? as usize; + + let mut rng = OsRng; + match args + .hash + .ok_or_else(|| type_error("Missing argument hash".to_string()))? + { + CryptoHash::Sha1 => { + let signing_key = Pss::new_with_salt::(salt_len); + let hashed = Sha1::digest(data); + signing_key.sign(Some(&mut rng), &private_key, &hashed)? + } + CryptoHash::Sha256 => { + let signing_key = Pss::new_with_salt::(salt_len); + let hashed = Sha256::digest(data); + signing_key.sign(Some(&mut rng), &private_key, &hashed)? + } + CryptoHash::Sha384 => { + let signing_key = Pss::new_with_salt::(salt_len); + let hashed = Sha384::digest(data); + signing_key.sign(Some(&mut rng), &private_key, &hashed)? + } + CryptoHash::Sha512 => { + let signing_key = Pss::new_with_salt::(salt_len); + let hashed = Sha512::digest(data); + signing_key.sign(Some(&mut rng), &private_key, &hashed)? + } } + .to_vec() } - .to_vec() - } - Algorithm::Ecdsa => { - let curve: &EcdsaSigningAlgorithm = - args.named_curve.ok_or_else(not_supported)?.into(); - - let rng = RingRand::SystemRandom::new(); - let key_pair = EcdsaKeyPair::from_pkcs8(curve, &args.key.data, &rng)?; - // We only support P256-SHA256 & P384-SHA384. These are recommended signature pairs. - // https://briansmith.org/rustdoc/ring/signature/index.html#statics - if let Some(hash) = args.hash { - match hash { - CryptoHash::Sha256 | CryptoHash::Sha384 => (), - _ => return Err(type_error("Unsupported algorithm")), - } - }; - - let signature = key_pair.sign(&rng, data)?; - - // Signature data as buffer. - signature.as_ref().to_vec() - } - Algorithm::Hmac => { - let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into(); + Algorithm::Ecdsa => { + let curve: &EcdsaSigningAlgorithm = + args.named_curve.ok_or_else(not_supported)?.into(); + + let rng = RingRand::SystemRandom::new(); + let key_pair = EcdsaKeyPair::from_pkcs8(curve, &args.key.data, &rng)?; + // We only support P256-SHA256 & P384-SHA384. These are recommended signature pairs. + // https://briansmith.org/rustdoc/ring/signature/index.html#statics + if let Some(hash) = args.hash { + match hash { + CryptoHash::Sha256 | CryptoHash::Sha384 => (), + _ => return Err(type_error("Unsupported algorithm")), + } + }; + + let signature = key_pair.sign(&rng, data)?; + + // Signature data as buffer. + signature.as_ref().to_vec() + } + Algorithm::Hmac => { + let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into(); - let key = HmacKey::new(hash, &args.key.data); + let key = HmacKey::new(hash, &args.key.data); - let signature = ring::hmac::sign(&key, data); - signature.as_ref().to_vec() - } - _ => return Err(type_error("Unsupported algorithm".to_string())), - }; + let signature = ring::hmac::sign(&key, data); + signature.as_ref().to_vec() + } + _ => return Err(type_error("Unsupported algorithm".to_string())), + }; - Ok(signature.into()) + Ok(signature.into()) + }) + .await? } #[derive(Deserialize)] @@ -314,106 +316,108 @@ pub async fn op_crypto_verify_key( #[serde] args: VerifyArg, #[buffer] zero_copy: JsBuffer, ) -> Result { - let data = &*zero_copy; - let algorithm = args.algorithm; - - let verification = match algorithm { - Algorithm::RsassaPkcs1v15 => { - use rsa::pkcs1v15::Signature; - use rsa::pkcs1v15::VerifyingKey; - let public_key = read_rsa_public_key(args.key)?; - let signature: Signature = args.signature.as_ref().try_into()?; - match args - .hash - .ok_or_else(|| type_error("Missing argument hash".to_string()))? - { - CryptoHash::Sha1 => { - let verifying_key = VerifyingKey::::new(public_key); - verifying_key.verify(data, &signature).is_ok() - } - CryptoHash::Sha256 => { - let verifying_key = VerifyingKey::::new(public_key); - verifying_key.verify(data, &signature).is_ok() - } - CryptoHash::Sha384 => { - let verifying_key = VerifyingKey::::new(public_key); - verifying_key.verify(data, &signature).is_ok() - } - CryptoHash::Sha512 => { - let verifying_key = VerifyingKey::::new(public_key); - verifying_key.verify(data, &signature).is_ok() + deno_core::unsync::spawn_blocking(move || { + let data = &*zero_copy; + let algorithm = args.algorithm; + + let verification = match algorithm { + Algorithm::RsassaPkcs1v15 => { + use rsa::pkcs1v15::Signature; + use rsa::pkcs1v15::VerifyingKey; + let public_key = read_rsa_public_key(args.key)?; + let signature: Signature = args.signature.as_ref().try_into()?; + match args + .hash + .ok_or_else(|| type_error("Missing argument hash".to_string()))? + { + CryptoHash::Sha1 => { + let verifying_key = VerifyingKey::::new(public_key); + verifying_key.verify(data, &signature).is_ok() + } + CryptoHash::Sha256 => { + let verifying_key = VerifyingKey::::new(public_key); + verifying_key.verify(data, &signature).is_ok() + } + CryptoHash::Sha384 => { + let verifying_key = VerifyingKey::::new(public_key); + verifying_key.verify(data, &signature).is_ok() + } + CryptoHash::Sha512 => { + let verifying_key = VerifyingKey::::new(public_key); + verifying_key.verify(data, &signature).is_ok() + } } } - } - Algorithm::RsaPss => { - let public_key = read_rsa_public_key(args.key)?; - let signature = args.signature.as_ref(); - - let salt_len = args - .salt_length - .ok_or_else(|| type_error("Missing argument saltLength".to_string()))? - as usize; - - match args - .hash - .ok_or_else(|| type_error("Missing argument hash".to_string()))? - { - CryptoHash::Sha1 => { - let pss = Pss::new_with_salt::(salt_len); - let hashed = Sha1::digest(data); - pss.verify(&public_key, &hashed, signature).is_ok() - } - CryptoHash::Sha256 => { - let pss = Pss::new_with_salt::(salt_len); - let hashed = Sha256::digest(data); - pss.verify(&public_key, &hashed, signature).is_ok() - } - CryptoHash::Sha384 => { - let pss = Pss::new_with_salt::(salt_len); - let hashed = Sha384::digest(data); - pss.verify(&public_key, &hashed, signature).is_ok() - } - CryptoHash::Sha512 => { - let pss = Pss::new_with_salt::(salt_len); - let hashed = Sha512::digest(data); - pss.verify(&public_key, &hashed, signature).is_ok() + Algorithm::RsaPss => { + let public_key = read_rsa_public_key(args.key)?; + let signature = args.signature.as_ref(); + + let salt_len = args.salt_length.ok_or_else(|| { + type_error("Missing argument saltLength".to_string()) + })? as usize; + + match args + .hash + .ok_or_else(|| type_error("Missing argument hash".to_string()))? + { + CryptoHash::Sha1 => { + let pss = Pss::new_with_salt::(salt_len); + let hashed = Sha1::digest(data); + pss.verify(&public_key, &hashed, signature).is_ok() + } + CryptoHash::Sha256 => { + let pss = Pss::new_with_salt::(salt_len); + let hashed = Sha256::digest(data); + pss.verify(&public_key, &hashed, signature).is_ok() + } + CryptoHash::Sha384 => { + let pss = Pss::new_with_salt::(salt_len); + let hashed = Sha384::digest(data); + pss.verify(&public_key, &hashed, signature).is_ok() + } + CryptoHash::Sha512 => { + let pss = Pss::new_with_salt::(salt_len); + let hashed = Sha512::digest(data); + pss.verify(&public_key, &hashed, signature).is_ok() + } } } - } - Algorithm::Hmac => { - let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into(); - let key = HmacKey::new(hash, &args.key.data); - ring::hmac::verify(&key, data, &args.signature).is_ok() - } - Algorithm::Ecdsa => { - let signing_alg: &EcdsaSigningAlgorithm = - args.named_curve.ok_or_else(not_supported)?.into(); - let verify_alg: &EcdsaVerificationAlgorithm = - args.named_curve.ok_or_else(not_supported)?.into(); - - let private_key; - - let public_key_bytes = match args.key.r#type { - KeyType::Private => { - let rng = RingRand::SystemRandom::new(); - private_key = - EcdsaKeyPair::from_pkcs8(signing_alg, &args.key.data, &rng)?; - - private_key.public_key().as_ref() - } - KeyType::Public => &*args.key.data, - _ => return Err(type_error("Invalid Key format".to_string())), - }; - - let public_key = - ring::signature::UnparsedPublicKey::new(verify_alg, public_key_bytes); - - public_key.verify(data, &args.signature).is_ok() - } - _ => return Err(type_error("Unsupported algorithm".to_string())), - }; + Algorithm::Hmac => { + let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into(); + let key = HmacKey::new(hash, &args.key.data); + ring::hmac::verify(&key, data, &args.signature).is_ok() + } + Algorithm::Ecdsa => { + let signing_alg: &EcdsaSigningAlgorithm = + args.named_curve.ok_or_else(not_supported)?.into(); + let verify_alg: &EcdsaVerificationAlgorithm = + args.named_curve.ok_or_else(not_supported)?.into(); + + let private_key; + + let public_key_bytes = match args.key.r#type { + KeyType::Private => { + let rng = RingRand::SystemRandom::new(); + private_key = + EcdsaKeyPair::from_pkcs8(signing_alg, &args.key.data, &rng)?; + + private_key.public_key().as_ref() + } + KeyType::Public => &*args.key.data, + _ => return Err(type_error("Invalid Key format".to_string())), + }; + + let public_key = + ring::signature::UnparsedPublicKey::new(verify_alg, public_key_bytes); + + public_key.verify(data, &args.signature).is_ok() + } + _ => return Err(type_error("Unsupported algorithm".to_string())), + }; - Ok(verification) + Ok(verification) + }) + .await? } #[derive(Deserialize)] @@ -437,153 +441,160 @@ pub async fn op_crypto_derive_bits( #[serde] args: DeriveKeyArg, #[buffer] zero_copy: Option, ) -> Result { - let algorithm = args.algorithm; - match algorithm { - Algorithm::Pbkdf2 => { - let zero_copy = zero_copy.ok_or_else(not_supported)?; - let salt = &*zero_copy; - // The caller must validate these cases. - assert!(args.length > 0); - assert!(args.length % 8 == 0); - - let algorithm = match args.hash.ok_or_else(not_supported)? { - CryptoHash::Sha1 => pbkdf2::PBKDF2_HMAC_SHA1, - CryptoHash::Sha256 => pbkdf2::PBKDF2_HMAC_SHA256, - CryptoHash::Sha384 => pbkdf2::PBKDF2_HMAC_SHA384, - CryptoHash::Sha512 => pbkdf2::PBKDF2_HMAC_SHA512, - }; - - // This will never panic. We have already checked length earlier. - let iterations = - NonZeroU32::new(args.iterations.ok_or_else(not_supported)?).unwrap(); - let secret = args.key.data; - let mut out = vec![0; args.length / 8]; - pbkdf2::derive(algorithm, iterations, salt, &secret, &mut out); - Ok(out.into()) - } - Algorithm::Ecdh => { - let named_curve = args - .named_curve - .ok_or_else(|| type_error("Missing argument namedCurve".to_string()))?; - - let public_key = args - .public_key - .ok_or_else(|| type_error("Missing argument publicKey"))?; - - match named_curve { - CryptoNamedCurve::P256 => { - let secret_key = p256::SecretKey::from_pkcs8_der(&args.key.data) - .map_err(|_| type_error("Unexpected error decoding private key"))?; - - let public_key = match public_key.r#type { - KeyType::Private => { - p256::SecretKey::from_pkcs8_der(&public_key.data) - .map_err(|_| { - type_error("Unexpected error decoding private key") - })? - .public_key() - } - KeyType::Public => { - let point = p256::EncodedPoint::from_bytes(public_key.data) - .map_err(|_| { - type_error("Unexpected error decoding private key") - })?; - - let pk = p256::PublicKey::from_encoded_point(&point); - // pk is a constant time Option. - if pk.is_some().into() { - pk.unwrap() - } else { - return Err(type_error( - "Unexpected error decoding private key", - )); + deno_core::unsync::spawn_blocking(move || { + let algorithm = args.algorithm; + match algorithm { + Algorithm::Pbkdf2 => { + let zero_copy = zero_copy.ok_or_else(not_supported)?; + let salt = &*zero_copy; + // The caller must validate these cases. + assert!(args.length > 0); + assert!(args.length % 8 == 0); + + let algorithm = match args.hash.ok_or_else(not_supported)? { + CryptoHash::Sha1 => pbkdf2::PBKDF2_HMAC_SHA1, + CryptoHash::Sha256 => pbkdf2::PBKDF2_HMAC_SHA256, + CryptoHash::Sha384 => pbkdf2::PBKDF2_HMAC_SHA384, + CryptoHash::Sha512 => pbkdf2::PBKDF2_HMAC_SHA512, + }; + + // This will never panic. We have already checked length earlier. + let iterations = + NonZeroU32::new(args.iterations.ok_or_else(not_supported)?).unwrap(); + let secret = args.key.data; + let mut out = vec![0; args.length / 8]; + pbkdf2::derive(algorithm, iterations, salt, &secret, &mut out); + Ok(out.into()) + } + Algorithm::Ecdh => { + let named_curve = args.named_curve.ok_or_else(|| { + type_error("Missing argument namedCurve".to_string()) + })?; + + let public_key = args + .public_key + .ok_or_else(|| type_error("Missing argument publicKey"))?; + + match named_curve { + CryptoNamedCurve::P256 => { + let secret_key = p256::SecretKey::from_pkcs8_der(&args.key.data) + .map_err(|_| { + type_error("Unexpected error decoding private key") + })?; + + let public_key = match public_key.r#type { + KeyType::Private => { + p256::SecretKey::from_pkcs8_der(&public_key.data) + .map_err(|_| { + type_error("Unexpected error decoding private key") + })? + .public_key() } - } - _ => unreachable!(), - }; - - let shared_secret = p256::elliptic_curve::ecdh::diffie_hellman( - secret_key.to_nonzero_scalar(), - public_key.as_affine(), - ); - - // raw serialized x-coordinate of the computed point - Ok(shared_secret.raw_secret_bytes().to_vec().into()) - } - CryptoNamedCurve::P384 => { - let secret_key = p384::SecretKey::from_pkcs8_der(&args.key.data) - .map_err(|_| type_error("Unexpected error decoding private key"))?; - - let public_key = match public_key.r#type { - KeyType::Private => { - p384::SecretKey::from_pkcs8_der(&public_key.data) - .map_err(|_| { - type_error("Unexpected error decoding private key") - })? - .public_key() - } - KeyType::Public => { - let point = p384::EncodedPoint::from_bytes(public_key.data) - .map_err(|_| { - type_error("Unexpected error decoding private key") - })?; - - let pk = p384::PublicKey::from_encoded_point(&point); - // pk is a constant time Option. - if pk.is_some().into() { - pk.unwrap() - } else { - return Err(type_error( - "Unexpected error decoding private key", - )); + KeyType::Public => { + let point = p256::EncodedPoint::from_bytes(public_key.data) + .map_err(|_| { + type_error("Unexpected error decoding private key") + })?; + + let pk = p256::PublicKey::from_encoded_point(&point); + // pk is a constant time Option. + if pk.is_some().into() { + pk.unwrap() + } else { + return Err(type_error( + "Unexpected error decoding private key", + )); + } } - } - _ => unreachable!(), - }; + _ => unreachable!(), + }; + + let shared_secret = p256::elliptic_curve::ecdh::diffie_hellman( + secret_key.to_nonzero_scalar(), + public_key.as_affine(), + ); + + // raw serialized x-coordinate of the computed point + Ok(shared_secret.raw_secret_bytes().to_vec().into()) + } + CryptoNamedCurve::P384 => { + let secret_key = p384::SecretKey::from_pkcs8_der(&args.key.data) + .map_err(|_| { + type_error("Unexpected error decoding private key") + })?; + + let public_key = match public_key.r#type { + KeyType::Private => { + p384::SecretKey::from_pkcs8_der(&public_key.data) + .map_err(|_| { + type_error("Unexpected error decoding private key") + })? + .public_key() + } + KeyType::Public => { + let point = p384::EncodedPoint::from_bytes(public_key.data) + .map_err(|_| { + type_error("Unexpected error decoding private key") + })?; + + let pk = p384::PublicKey::from_encoded_point(&point); + // pk is a constant time Option. + if pk.is_some().into() { + pk.unwrap() + } else { + return Err(type_error( + "Unexpected error decoding private key", + )); + } + } + _ => unreachable!(), + }; - let shared_secret = p384::elliptic_curve::ecdh::diffie_hellman( - secret_key.to_nonzero_scalar(), - public_key.as_affine(), - ); + let shared_secret = p384::elliptic_curve::ecdh::diffie_hellman( + secret_key.to_nonzero_scalar(), + public_key.as_affine(), + ); - // raw serialized x-coordinate of the computed point - Ok(shared_secret.raw_secret_bytes().to_vec().into()) + // raw serialized x-coordinate of the computed point + Ok(shared_secret.raw_secret_bytes().to_vec().into()) + } } } + Algorithm::Hkdf => { + let zero_copy = zero_copy.ok_or_else(not_supported)?; + let salt = &*zero_copy; + let algorithm = match args.hash.ok_or_else(not_supported)? { + CryptoHash::Sha1 => hkdf::HKDF_SHA1_FOR_LEGACY_USE_ONLY, + CryptoHash::Sha256 => hkdf::HKDF_SHA256, + CryptoHash::Sha384 => hkdf::HKDF_SHA384, + CryptoHash::Sha512 => hkdf::HKDF_SHA512, + }; + + let info = args + .info + .ok_or_else(|| type_error("Missing argument info".to_string()))?; + // IKM + let secret = args.key.data; + // L + let length = args.length / 8; + + let salt = hkdf::Salt::new(algorithm, salt); + let prk = salt.extract(&secret); + let info = &[&*info]; + let okm = prk.expand(info, HkdfOutput(length)).map_err(|_e| { + custom_error( + "DOMExceptionOperationError", + "The length provided for HKDF is too large", + ) + })?; + let mut r = vec![0u8; length]; + okm.fill(&mut r)?; + Ok(r.into()) + } + _ => Err(type_error("Unsupported algorithm".to_string())), } - Algorithm::Hkdf => { - let zero_copy = zero_copy.ok_or_else(not_supported)?; - let salt = &*zero_copy; - let algorithm = match args.hash.ok_or_else(not_supported)? { - CryptoHash::Sha1 => hkdf::HKDF_SHA1_FOR_LEGACY_USE_ONLY, - CryptoHash::Sha256 => hkdf::HKDF_SHA256, - CryptoHash::Sha384 => hkdf::HKDF_SHA384, - CryptoHash::Sha512 => hkdf::HKDF_SHA512, - }; - - let info = args - .info - .ok_or_else(|| type_error("Missing argument info".to_string()))?; - // IKM - let secret = args.key.data; - // L - let length = args.length / 8; - - let salt = hkdf::Salt::new(algorithm, salt); - let prk = salt.extract(&secret); - let info = &[&*info]; - let okm = prk.expand(info, HkdfOutput(length)).map_err(|_e| { - custom_error( - "DOMExceptionOperationError", - "The length provided for HKDF is too large", - ) - })?; - let mut r = vec![0u8; length]; - okm.fill(&mut r)?; - Ok(r.into()) - } - _ => Err(type_error("Unsupported algorithm".to_string())), - } + }) + .await? } fn read_rsa_public_key(key_data: KeyData) -> Result { diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index 7fde7d12b6578c..04b0a58508c8c5 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -166,6 +166,7 @@ function listenTls({ return new TlsListener(rid, localAddr); } +// deno-lint-ignore require-await async function startTls( conn, { @@ -174,7 +175,7 @@ async function startTls( alpnProtocols = undefined, } = {}, ) { - const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_tls_start({ + const { 0: rid, 1: localAddr, 2: remoteAddr } = op_tls_start({ rid: conn[internalRidSymbol], hostname, caCerts, diff --git a/ext/net/io.rs b/ext/net/io.rs index 9254fce081acf7..f3aed3fcbdc0dd 100644 --- a/ext/net/io.rs +++ b/ext/net/io.rs @@ -152,6 +152,7 @@ impl UnixStreamResource { fn write(self: Rc, _data: &[u8]) -> AsyncResult { unreachable!() } + #[allow(clippy::unused_async)] pub async fn shutdown(self: Rc) -> Result<(), AnyError> { unreachable!() } diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index b16dafa7117498..e83173e909516a 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -159,9 +159,9 @@ pub struct StartTlsArgs { alpn_protocols: Option>, } -#[op2(async)] +#[op2] #[serde] -pub async fn op_tls_start( +pub fn op_tls_start( state: Rc>, #[serde] args: StartTlsArgs, ) -> Result<(ResourceId, IpAddr, IpAddr), AnyError> diff --git a/ext/node/ops/ipc.rs b/ext/node/ops/ipc.rs index 3cdb569abc02f4..dc0c086c1230c6 100644 --- a/ext/node/ops/ipc.rs +++ b/ext/node/ops/ipc.rs @@ -408,6 +408,7 @@ mod impl_ { use deno_core::RcRef; use std::rc::Rc; + #[allow(clippy::unused_async)] #[cfg(unix)] pub async fn pair() -> (Rc, tokio::net::UnixStream) { let (a, b) = tokio::net::UnixStream::pair().unwrap(); diff --git a/ext/node/ops/zlib/brotli.rs b/ext/node/ops/zlib/brotli.rs index f906e8827c77f1..dc3a4044111a5e 100644 --- a/ext/node/ops/zlib/brotli.rs +++ b/ext/node/ops/zlib/brotli.rs @@ -314,13 +314,15 @@ pub fn op_brotli_decompress_stream_end( unsafe { let mut available_out = output.len(); let mut next_out = output.as_mut_ptr(); + let mut available_in = 0; + let mut next_in = []; let mut total_out = 0; if matches!( CBrotliDecoderDecompressStream( ctx.inst, - &mut 0, - std::ptr::null_mut(), + &mut available_in, + next_in.as_mut_ptr(), &mut available_out, &mut next_out, &mut total_out, diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js index b019836cf793b5..8b1f530125ce1a 100644 --- a/ext/node/polyfills/_brotli.js +++ b/ext/node/polyfills/_brotli.js @@ -12,6 +12,7 @@ import { op_brotli_decompress, op_brotli_decompress_async, op_brotli_decompress_stream, + op_brotli_decompress_stream_end, op_create_brotli_compress, op_create_brotli_decompress, } from "ext:core/ops"; @@ -57,6 +58,11 @@ export class BrotliDecompress extends Transform { callback(); }, flush(callback) { + const output = new Uint8Array(1024); + let avail; + while ((avail = op_brotli_decompress_stream_end(context, output)) > 0) { + this.push(output.slice(0, avail)); + } core.close(context); callback(); }, diff --git a/ext/web/timers.rs b/ext/web/timers.rs index 8e2f94338e452f..b3060a46fd1a8c 100644 --- a/ext/web/timers.rs +++ b/ext/web/timers.rs @@ -43,5 +43,6 @@ where buf[1] = subsec_nanos; } +#[allow(clippy::unused_async)] #[op2(async(lazy), fast)] pub async fn op_defer() {} diff --git a/ext/webgpu/01_webgpu.js b/ext/webgpu/01_webgpu.js index 55ca9c3822203b..31b0a75f65cac8 100644 --- a/ext/webgpu/01_webgpu.js +++ b/ext/webgpu/01_webgpu.js @@ -324,6 +324,7 @@ class GPU { /** * @param {GPURequestAdapterOptions} options */ + // deno-lint-ignore require-await async requestAdapter(options = {}) { webidl.assertBranded(this, GPUPrototype); options = webidl.converters.GPURequestAdapterOptions( @@ -332,7 +333,7 @@ class GPU { "Argument 1", ); - const { err, ...data } = await op_webgpu_request_adapter( + const { err, ...data } = op_webgpu_request_adapter( options.powerPreference, options.forceFallbackAdapter, ); @@ -411,6 +412,7 @@ class GPUAdapter { * @param {GPUDeviceDescriptor} descriptor * @returns {Promise} */ + // deno-lint-ignore require-await async requestDevice(descriptor = {}) { webidl.assertBranded(this, GPUAdapterPrototype); const prefix = "Failed to execute 'requestDevice' on 'GPUAdapter'"; @@ -431,7 +433,7 @@ class GPUAdapter { } } - const { rid, features, limits } = await op_webgpu_request_device( + const { rid, features, limits } = op_webgpu_request_device( this[_adapter].rid, descriptor.label, requiredFeatures, @@ -455,7 +457,7 @@ class GPUAdapter { * @param {string[]} unmaskHints * @returns {Promise} */ - async requestAdapterInfo(unmaskHints = []) { + requestAdapterInfo(unmaskHints = []) { webidl.assertBranded(this, GPUAdapterPrototype); const prefix = "Failed to execute 'requestAdapterInfo' on 'GPUAdapter'"; unmaskHints = webidl.converters["sequence"]( @@ -469,9 +471,7 @@ class GPUAdapter { architecture, device, description, - } = await op_webgpu_request_adapter_info( - this[_adapter].rid, - ); + } = op_webgpu_request_adapter_info(this[_adapter].rid); const adapterInfo = webidl.createBranded(GPUAdapterInfo); adapterInfo[_vendor] = ArrayPrototypeIncludes(unmaskHints, "vendor") @@ -484,7 +484,7 @@ class GPUAdapter { : ""; adapterInfo[_description] = ArrayPrototypeIncludes(unmaskHints, "description") ? description : ""; - return adapterInfo; + return PromiseResolve(adapterInfo); } [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { diff --git a/ext/webgpu/lib.rs b/ext/webgpu/lib.rs index 99c8fcf6b27368..5c0dc79c295dd9 100644 --- a/ext/webgpu/lib.rs +++ b/ext/webgpu/lib.rs @@ -381,9 +381,9 @@ pub struct GpuAdapterDevice { is_software: bool, } -#[op2(async)] +#[op2] #[serde] -pub async fn op_webgpu_request_adapter( +pub fn op_webgpu_request_adapter( state: Rc>, #[serde] power_preference: Option, force_fallback_adapter: bool, @@ -645,9 +645,9 @@ impl From for wgpu_types::Features { } } -#[op2(async)] +#[op2] #[serde] -pub async fn op_webgpu_request_device( +pub fn op_webgpu_request_device( state: Rc>, #[smi] adapter_rid: ResourceId, #[string] label: String, @@ -702,9 +702,9 @@ pub struct GPUAdapterInfo { description: String, } -#[op2(async)] +#[op2] #[serde] -pub async fn op_webgpu_request_adapter_info( +pub fn op_webgpu_request_adapter_info( state: Rc>, #[smi] adapter_rid: ResourceId, ) -> Result { diff --git a/runtime/worker.rs b/runtime/worker.rs index ab3e5fa875725e..b9b03a957e9edd 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -662,7 +662,7 @@ impl MainWorker { /// Create new inspector session. This function panics if Worker /// was not configured to create inspector. - pub async fn create_inspector_session(&mut self) -> LocalInspectorSession { + pub fn create_inspector_session(&mut self) -> LocalInspectorSession { self.js_runtime.maybe_init_inspector(); self.js_runtime.inspector().borrow().create_local_session() } diff --git a/tests/unit_node/zlib_test.ts b/tests/unit_node/zlib_test.ts index 94b1c63cacb15c..fa09bd68742edc 100644 --- a/tests/unit_node/zlib_test.ts +++ b/tests/unit_node/zlib_test.ts @@ -171,3 +171,13 @@ Deno.test("brotli large chunk size", async () => { ); assertEquals(output.length, input.length); }); + +Deno.test("brotli decompress flush restore size", async () => { + const input = new Uint8Array(1000000); + const output = await buffer( + Readable.from([input]) + .pipe(createBrotliCompress()) + .pipe(createBrotliDecompress()), + ); + assertEquals(output.length, input.length); +}); diff --git a/tests/util/server/src/https.rs b/tests/util/server/src/https.rs index 576df6d527bbdb..8a2524dca9622d 100644 --- a/tests/util/server/src/https.rs +++ b/tests/util/server/src/https.rs @@ -47,15 +47,14 @@ pub async fn get_tls_listener_stream( let cert_file = "tls/localhost.crt"; let key_file = "tls/localhost.key"; let ca_cert_file = "tls/RootCA.pem"; - let tls_config = get_tls_config(cert_file, key_file, ca_cert_file, http) - .await - .unwrap(); + let tls_config = + get_tls_config(cert_file, key_file, ca_cert_file, http).unwrap(); let tcp = get_tcp_listener_stream(name, port).await; get_tls_listener_stream_from_tcp(tls_config, tcp) } -pub async fn get_tls_config( +pub fn get_tls_config( cert: &str, key: &str, ca: &str, diff --git a/tools/lint.js b/tools/lint.js index 56662fdd8d77a7..6cda0cef064caa 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -156,6 +156,8 @@ async function clippy() { "--", "-D", "warnings", + "--deny", + "clippy::unused_async", ], stdout: "inherit", stderr: "inherit", diff --git a/tools/node_compat/TODO.md b/tools/node_compat/TODO.md index 8321ae1df3aa21..88cadfc1c34af6 100644 --- a/tools/node_compat/TODO.md +++ b/tools/node_compat/TODO.md @@ -3,8 +3,6 @@ NOTE: This file should not be manually edited. Please edit `tests/node_compat/config.json` and run `deno task setup` in `tools/node_compat` dir instead. -Total: 2996 - - [abort/test-abort-backtrace.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-backtrace.js) - [abort/test-abort-fatal-error.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-fatal-error.js) - [abort/test-abort-uncaught-exception.js](https://github.com/nodejs/node/tree/v18.12.1/test/abort/test-abort-uncaught-exception.js) diff --git a/tools/node_compat/setup.ts b/tools/node_compat/setup.ts index 0ead46e250fed8..50dba393c703b8 100755 --- a/tools/node_compat/setup.ts +++ b/tools/node_compat/setup.ts @@ -78,8 +78,6 @@ async function updateToDo() { NOTE: This file should not be manually edited. Please edit \`tests/node_compat/config.json\` and run \`deno task setup\` in \`tools/node_compat\` dir instead. -Total: ${missingTests.length} - `)); for (const test of missingTests) { await file.write(