From 6310e8c671ddaed5d71736f206242963066ef021 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sat, 26 Sep 2026 12:40:47 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20eval=20=E6=95=B0=E7=BB=84=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=94=B9=E8=AF=BB=E5=85=83=E7=B4=A0=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_cli/src/main.rs | 3 ++- crates/oxide_cli/tests/cli_smoke.rs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/oxide_cli/src/main.rs b/crates/oxide_cli/src/main.rs index 9aa5f62d..1d90f65d 100644 --- a/crates/oxide_cli/src/main.rs +++ b/crates/oxide_cli/src/main.rs @@ -286,7 +286,8 @@ fn format_object( fn format_array( vm: &oxide_vm::vm::Vm, string_forge: &PermInterner, shape_forge: &ShapeForge, obj: &JsObject, ) -> String { - let len = obj.prop_vec_len(); + // 数组元素在独立元素区,命名属性区长度恒 0;元素区未分配时 get_prop_at 自然返回 undefined。 + let len = obj.array_prop_count as usize; let mut items = Vec::new(); for i in 0..len { let val = obj.get_prop_at(i); diff --git a/crates/oxide_cli/tests/cli_smoke.rs b/crates/oxide_cli/tests/cli_smoke.rs index 8878573b..537612b7 100644 --- a/crates/oxide_cli/tests/cli_smoke.rs +++ b/crates/oxide_cli/tests/cli_smoke.rs @@ -51,6 +51,18 @@ fn run_throw_script() { assert!(!stderr.is_empty(), "run 失败应输出 stderr: {stderr}"); } +#[test] +fn eval_array_output() { + let output = Command::new(env!("CARGO_BIN_EXE_oxide")) + .args(["eval", "var a = [1, 2, 3]; a"]) + .output() + .expect("failed to run oxide eval array"); + + assert!(output.status.success(), "eval array should exit 0"); + let stdout = String::from_utf8_lossy(&output.stdout); + assert!(stdout.trim() == "[1, 2, 3]", "eval 数组应打印元素区内容: {stdout}"); +} + #[test] fn bench_help() { let output = Command::new(env!("CARGO_BIN_EXE_oxide"))