Skip to main content

Module bounds

Module bounds 

Source
Expand description

Bounds-checked array indexing.

arr[i] lowers to a raw array.get/array.set, which traps uncatchably on an out-of-range index. A trap halts the program and can’t be intercepted by user try/catch, turning a user-controlled index into a DoS vector. Instead we range-check the index. A read that finds no element throws a catchable MissingValueError (or gives undefined where the typechecker typed it T | undefined), and a write outside the array throws RangeError, matching how every other runtime fault surfaces (cast mismatch, etc.).

Functions§

stash_array_length
Capture the logical length while leaving the array receiver on the stack.
stash_index_operand
Stashes the f64 index sitting on the stack into a fresh local, ready for [emit_checked_index]. Kept separate from the check because a write must evaluate its RHS between the two — left-to-right evaluation order puts the RHS’s side effects before the check’s throw.