mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
fix: peek returns nth element from the top of the stack (#5262)
This commit is contained in:
@ -280,6 +280,7 @@ impl StackObj {
|
|||||||
.length(0)
|
.length(0)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
// peek returns the nth-from-the-top element of the stack.
|
||||||
let peek = FunctionObjectBuilder::new(
|
let peek = FunctionObjectBuilder::new(
|
||||||
context,
|
context,
|
||||||
NativeFunction::from_copy_closure_with_captures(
|
NativeFunction::from_copy_closure_with_captures(
|
||||||
@ -293,6 +294,9 @@ impl StackObj {
|
|||||||
),
|
),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
// idx is from the top of the stack, so we need to reverse it
|
||||||
|
// SAFETY: bounds checked above
|
||||||
|
let idx = len - idx - 1;
|
||||||
stack_arr.get(idx as u64, ctx)
|
stack_arr.get(idx as u64, ctx)
|
||||||
},
|
},
|
||||||
stack_arr,
|
stack_arr,
|
||||||
|
|||||||
Reference in New Issue
Block a user