diff --git a/crates/moon/tests/test_cases/moon_run_with_cli_args.in/main/main_js.mbt b/crates/moon/tests/test_cases/moon_run_with_cli_args.in/main/main_js.mbt index 6dfb3a35..d00e7a78 100644 --- a/crates/moon/tests/test_cases/moon_run_with_cli_args.in/main/main_js.mbt +++ b/crates/moon/tests/test_cases/moon_run_with_cli_args.in/main/main_js.mbt @@ -4,7 +4,7 @@ pub fn get_args() -> Array[String] { extern "js" fn get_cli_args_internal() -> Array[String] = #| function() { - #| return process.argv.slice(2); + #| return process.argv; #| } fn main { diff --git a/crates/moonrun/src/sys_api.rs b/crates/moonrun/src/sys_api.rs index 1bd5f61c..4791f185 100644 --- a/crates/moonrun/src/sys_api.rs +++ b/crates/moonrun/src/sys_api.rs @@ -47,13 +47,15 @@ fn construct_args_list<'s>( args: &[String], scope: &mut v8::HandleScope<'s>, ) -> v8::Local<'s, v8::Array> { + // align with node's behavior + // use this concat instead of std::env::args(), to ignore the possible -- let cli_args: Vec = std::env::args() // path of moonrun and the path of the wasm file .take(2) .chain(args.iter().cloned()) .collect(); - let arr = v8::Array::new(scope, args.len() as i32); + let arr = v8::Array::new(scope, cli_args.len() as i32); for (i, arg) in cli_args.iter().enumerate() { let arg = v8::String::new(scope, arg).unwrap(); arr.set_index(scope, i as u32, arg.into());