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§
Functions§
- emit_
checked_ index - Throws unless
idx >= 0 && idx < len && idx === Math.floor(idx), then returns a freshi32local 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
f64index sitting on the stack into a fresh local, ready foremit_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.