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 and throw a catchable RangeError on a miss, matching how every other runtime fault surfaces (cast mismatch, etc.).

Constants§

INDEX_OOB_MESSAGE

Functions§

emit_checked_index
Throws unless idx >= 0 && idx < len && idx === Math.floor(idx), then returns a fresh i32 local holding the index truncated.
emit_checked_index_with_length
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.