index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var test = require('tape');
  3. var inspect = require('object-inspect');
  4. var forEach = require('for-each');
  5. var v = require('es-value-fixtures');
  6. var availableTypedArrays = require('available-typed-arrays')();
  7. var isSharedArrayBuffer = require('..');
  8. test('isSharedArrayBuffer', function (t) {
  9. t.equal(typeof isSharedArrayBuffer, 'function', 'is a function');
  10. // @ts-expect-error TS sucks with concat
  11. var nonSABs = [].concat(v.primitives, v.objects);
  12. forEach(nonSABs, function (nonSAB) {
  13. t.equal(isSharedArrayBuffer(nonSAB), false, inspect(nonSAB) + ' is not a SharedArrayBuffer');
  14. });
  15. t.test('actual SharedArrayBuffer instances', { skip: typeof SharedArrayBuffer === 'undefined' }, function (st) {
  16. var sab = new SharedArrayBuffer(0);
  17. st.equal(isSharedArrayBuffer(sab), true, inspect(sab) + ' is a SharedArrayBuffer');
  18. st.end();
  19. });
  20. t.test('Typed Arrays', { skip: availableTypedArrays.length === 0 }, function (st) {
  21. forEach(availableTypedArrays, function (TypedArray) {
  22. var ta = new global[TypedArray](0);
  23. st.equal(isSharedArrayBuffer(ta.buffer), false, inspect(ta.buffer) + ', the TA\'s buffer, is not a SharedArrayBuffer');
  24. st.equal(isSharedArrayBuffer(ta), false, inspect(ta) + ' is not a SharedArrayBuffer');
  25. });
  26. st.end();
  27. });
  28. t.end();
  29. });