e6bae6e3269ac51611bf9a2f64b0240b49fe86afa33f158d61723930720d437451b37681908fef62a815f3d2a29abc66b0ce90cce39b0f98264d8330f21c90 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var isObject = require('es-object-atoms/isObject');
  4. var IsTypedArrayOutOfBounds = require('./IsTypedArrayOutOfBounds');
  5. var MakeTypedArrayWithBufferWitnessRecord = require('./MakeTypedArrayWithBufferWitnessRecord');
  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. };