IsArrayBufferViewOutOfBounds.js 1.0 KB

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var IsTypedArrayOutOfBounds = require('./IsTypedArrayOutOfBounds');
  4. var IsViewOutOfBounds = require('./IsViewOutOfBounds');
  5. var MakeDataViewWithBufferWitnessRecord = require('./MakeDataViewWithBufferWitnessRecord');
  6. var MakeTypedArrayWithBufferWitnessRecord = require('./MakeTypedArrayWithBufferWitnessRecord');
  7. var isDataView = require('is-data-view');
  8. var isTypedArray = require('is-typed-array');
  9. // https://262.ecma-international.org/15.0/#sec-isarraybufferviewoutofbounds
  10. module.exports = function IsArrayBufferViewOutOfBounds(O) {
  11. var isDV = isDataView(O);
  12. if (!isTypedArray(O) && !isDV) {
  13. throw new $TypeError('Assertion failed: `O` must be a TypedArray or DataView');
  14. }
  15. if (isDV) { // step 1
  16. var viewRecord = MakeDataViewWithBufferWitnessRecord(O, 'SEQ-CST'); // step 1.a
  17. return IsViewOutOfBounds(viewRecord); // step 1.b
  18. }
  19. var taRecord = MakeTypedArrayWithBufferWitnessRecord(O, 'SEQ-CST'); // step 2
  20. return IsTypedArrayOutOfBounds(taRecord); // step 3
  21. };