private static int ValidateArrayAndIndex(TypedArray array, EcmaValue index) { switch (array.ArrayKind) { case TypedArrayKind.Int8Array: case TypedArrayKind.Int16Array: case TypedArrayKind.Int32Array: case TypedArrayKind.Uint8Array: case TypedArrayKind.Uint16Array: case TypedArrayKind.Uint32Array: break; default: throw new EcmaTypeErrorException(InternalString.Error.TypedArrayNotAtomic); } if (!array.Buffer.IsShared) { throw new EcmaTypeErrorException(InternalString.Error.TypedArrayNotAtomic); } long i = index.ToIndex(); if (i < 0 || i >= array.Length) { throw new EcmaRangeErrorException(InternalString.Error.BufferOffsetOutOfBound, i); } return((int)i); }
private static int ValidateWaitableArrayAndIndex(TypedArray array, EcmaValue index) { if (array.ArrayKind != TypedArrayKind.Int32Array && array.ArrayKind != TypedArrayKind.BigInt64Array) { throw new EcmaTypeErrorException(InternalString.Error.TypedArrayNotWaitable); } if (!array.Buffer.IsShared) { throw new EcmaTypeErrorException(InternalString.Error.TypedArrayNotWaitable); } long i = index.ToIndex(); if (i < 0 || i >= array.Length) { throw new EcmaRangeErrorException(InternalString.Error.BufferOffsetOutOfBound, i); } return((int)i); }