diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-03-20 00:40:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-20 00:40:21 -0400 |
commit | aba5329aec06a92b591ef92ddc40ac0d25c870fa (patch) | |
tree | fc6ef43dac484b2a50a983c937c9c25f379d0cc8 /ext/node/lib.rs | |
parent | 090169cfbc6699486765b729d532b5b837210b12 (diff) |
refactor(ext/node): make initialization functions sync (#18282)
These functions don't need to be async, as they are only calling
synchronous JavaScript code. As a follow up, all 3 functions
should be merge together - this will reduce roundtrips for
calling V8 from Rust, which is somewhat expensive
Diffstat (limited to 'ext/node/lib.rs')
-rw-r--r-- | ext/node/lib.rs | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs index d2d6b15c9..e9ac8c060 100644 --- a/ext/node/lib.rs +++ b/ext/node/lib.rs @@ -383,12 +383,12 @@ deno_core::extension!(deno_node_loading, }, ); -pub async fn initialize_runtime( +pub fn initialize_runtime( js_runtime: &mut JsRuntime, uses_local_node_modules_dir: bool, ) -> Result<(), AnyError> { let source_code = &format!( - r#"(async function loadBuiltinNodeModules(nodeGlobalThisName, usesLocalNodeModulesDir) {{ + r#"(function loadBuiltinNodeModules(nodeGlobalThisName, usesLocalNodeModulesDir) {{ Deno[Deno.internal].node.initialize(Deno[Deno.internal].nodeModuleAll, nodeGlobalThisName); if (usesLocalNodeModulesDir) {{ Deno[Deno.internal].require.setUsesLocalNodeModulesDir(); @@ -398,9 +398,7 @@ pub async fn initialize_runtime( uses_local_node_modules_dir, ); - let value = - js_runtime.execute_script(&located_script_name!(), source_code)?; - js_runtime.resolve_value(value).await?; + js_runtime.execute_script(&located_script_name!(), source_code)?; Ok(()) } @@ -430,13 +428,13 @@ pub fn load_cjs_module( Ok(()) } -pub async fn initialize_binary_command( +pub fn initialize_binary_command( js_runtime: &mut JsRuntime, binary_name: &str, ) -> Result<(), AnyError> { // overwrite what's done in deno_std in order to set the binary arg name let source_code = &format!( - r#"(async function initializeBinaryCommand(binaryName) {{ + r#"(function initializeBinaryCommand(binaryName) {{ const process = Deno[Deno.internal].node.globalThis.process; Object.defineProperty(process.argv, "0", {{ get: () => binaryName, @@ -444,8 +442,6 @@ pub async fn initialize_binary_command( }})('{binary_name}');"#, ); - let value = - js_runtime.execute_script(&located_script_name!(), source_code)?; - js_runtime.resolve_value(value).await?; + js_runtime.execute_script(&located_script_name!(), source_code)?; Ok(()) } |