checkValidIndex method
Check that a value is a valid index into an indexable object.
Throws if index is not a valid index into indexable.
An indexable object is one that has a length and a and index-operator
[] that accepts an index if 0 <= index < length.
If length is provided, it is used as the length of the indexable object,
otherwise the length is found as indexable.length.
Implementation
static void checkValidIndex(int index, dynamic indexable,
[String name, int length, String message]) {
length ??= indexable.length;
// Comparing with `0` as receiver produces better dart2js type inference.
if (0 > index || index >= length) {
name ??= "index";
throw RangeError.index(index, indexable, name, message, length);
}
}