dc8220b88809af499fa15b09f782554a0ec26b7bbb3204913888e93d8b61b50e5fbc285c6bb5deeac9062adc8c6217387f16b94e99b03a53c879aa49cc2c54 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsTypedArrayOutOfBounds = require('./IsTypedArrayOutOfBounds');
  4. var MakeTypedArrayWithBufferWitnessRecord = require('./MakeTypedArrayWithBufferWitnessRecord');
  5. var isObject = require('../helpers/isObject');
  6. var isTypedArray = require('is-typed-array');
  7. // https://262.ecma-international.org/15.0/#sec-validatetypedarray
  8. module.exports = function ValidateTypedArray(O, order) {
  9. if (order !== 'SEQ-CST' && order !== 'UNORDERED') {
  10. throw new $TypeError('Assertion failed: `order` must be ~SEQ-CST~ or ~UNORDERED~');
  11. }
  12. if (!isObject(O)) {
  13. throw new $TypeError('Assertion failed: `O` must be an Object'); // step 1
  14. }
  15. if (!isTypedArray(O)) {
  16. throw new $TypeError('Assertion failed: `O` must be a Typed Array'); // steps 1 - 2
  17. }
  18. var taRecord = MakeTypedArrayWithBufferWitnessRecord(O, order); // step 3
  19. if (IsTypedArrayOutOfBounds(taRecord)) {
  20. throw new $TypeError('`O` must be in-bounds and backed by a non-detached buffer'); // step 4
  21. }
  22. return taRecord; // step 5
  23. };