0a72a8c78fd881f0f2289daf46d7ad488a86d1bc5f52e2c87d0cdbcc1915fee325aee7e4fd6f01171715f07babbc12ca024fcc6854bb1ccc7c16416576d4ad 1.3 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsBigIntElementType = require('./IsBigIntElementType');
  4. var IsUnclampedIntegerElementType = require('./IsUnclampedIntegerElementType');
  5. var TypedArrayElementType = require('./TypedArrayElementType');
  6. var ValidateTypedArray = require('./ValidateTypedArray');
  7. // https://262.ecma-international.org/15.0/#sec-validateintegertypedarray
  8. module.exports = function ValidateIntegerTypedArray(typedArray, waitable) {
  9. if (typeof waitable !== 'boolean') {
  10. throw new $TypeError('Assertion failed: `waitable` must be a Boolean');
  11. }
  12. var taRecord = ValidateTypedArray(typedArray, 'UNORDERED'); // step 1
  13. // 2. NOTE: Bounds checking is not a synchronizing operation when typedArray's backing buffer is a growable SharedArrayBuffer.
  14. var type = TypedArrayElementType(typedArray); // step 4.a
  15. if (waitable) { // step 3
  16. if (type !== 'INT32' && type !== 'BIGINT64') {
  17. throw new $TypeError('Assertion failed: `typedArray` must be an Int32Array or BigInt64Array when `waitable` is true'); // step 5.a
  18. }
  19. } else if (!IsUnclampedIntegerElementType(type) && !IsBigIntElementType(type)) { // step 4
  20. throw new $TypeError('Assertion failed: `typedArray` must be an integer TypedArray'); // step 4.b
  21. }
  22. return taRecord; // step 5
  23. };