index.js 671 B

123456789101112131415161718192021222324
  1. 'use strict';
  2. var callBound = require('call-bound');
  3. /** @type {undefined | ((thisArg: SharedArrayBuffer) => number)} */
  4. var $byteLength = callBound('SharedArrayBuffer.prototype.byteLength', true);
  5. /** @type {import('.')} */
  6. module.exports = $byteLength
  7. ? function isSharedArrayBuffer(obj) {
  8. if (!obj || typeof obj !== 'object') {
  9. return false;
  10. }
  11. try {
  12. // @ts-expect-error TS can't figure out this closed-over variable is non-nullable, and it's fine that `obj` might not be a SAB
  13. $byteLength(obj);
  14. return true;
  15. } catch (e) {
  16. return false;
  17. }
  18. }
  19. : function isSharedArrayBuffer(_obj) { // eslint-disable-line no-unused-vars
  20. return false;
  21. };