validatedNativeArrayCount function
Validates a native-required element count before allocating the buffer.
Implementation
int validatedNativeArrayCount(int count, String noun) {
if (count < 0) {
throw StateError('Native $noun returned a negative count');
}
return count;
}