IsFixedLengthArrayBuffer.js 966 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var callBound = require('call-bind/callBound');
  4. var $arrayBufferResizable = callBound('%ArrayBuffer.prototype.resizable%', true);
  5. var $sharedArrayGrowable = callBound('%SharedArrayBuffer.prototype.growable%', true);
  6. var isArrayBuffer = require('is-array-buffer');
  7. var isSharedArrayBuffer = require('is-shared-array-buffer');
  8. // https://262.ecma-international.org/15.0/#sec-isfixedlengtharraybuffer
  9. module.exports = function IsFixedLengthArrayBuffer(arrayBuffer) {
  10. var isAB = isArrayBuffer(arrayBuffer);
  11. var isSAB = isSharedArrayBuffer(arrayBuffer);
  12. if (!isAB && !isSAB) {
  13. throw new $TypeError('Assertion failed: `arrayBuffer` must be an ArrayBuffer or SharedArrayBuffer');
  14. }
  15. if (isAB && $arrayBufferResizable) {
  16. return !$arrayBufferResizable(arrayBuffer); // step 1
  17. }
  18. if (isSAB && $sharedArrayGrowable) {
  19. return !$sharedArrayGrowable(arrayBuffer); // step 1
  20. }
  21. return true; // step 2
  22. };