mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-23 18:21:13 +08:00
fix: 修复 array_push 返回值错误问题
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user