fix: 修复 array_push 返回值错误问题

This commit is contained in:
2026-06-08 21:50:49 +08:00
parent 997e64ff61
commit 7a46e32f04
2 changed files with 15 additions and 3 deletions
@@ -1,4 +1,5 @@
use oxide_compiler::compiler::Compiler;
use oxide_vm::builtins::array::{array_constructor, array_push};
use oxide_vm::vm::Vm;
fn eval(source: &str) -> Result<oxide_types::value::JsValue, String> {
@@ -26,6 +27,17 @@ fn array_push_returns_length() {
assert_eq!(result.as_int(), 4);
}
#[test]
fn array_push_returns_true_length_beyond_31() {
let mut vm = Vm::new();
vm.set_reg(1, oxide_types::value::JsValue::int(31));
let array = array_constructor(&mut vm, &[0, 1]).unwrap();
vm.set_reg(0, array);
vm.set_reg(1, oxide_types::value::JsValue::int(99));
let result = array_push(&mut vm, &[0, 1]).unwrap();
assert_eq!(result.as_int(), 32);
}
#[test]
fn array_pop_returns_last() {
let result = eval("[1,2,3].pop()").unwrap();