source: imaps-frontend/node_modules/es-abstract/2020/IsDetachedBuffer.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1007 bytes
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var $byteLength = require('array-buffer-byte-length');
6var availableTypedArrays = require('available-typed-arrays')();
7var callBound = require('call-bind/callBound');
8var isArrayBuffer = require('is-array-buffer');
9var isSharedArrayBuffer = require('is-shared-array-buffer');
10
11var $sabByteLength = callBound('SharedArrayBuffer.prototype.byteLength', true);
12
13// https://262.ecma-international.org/8.0/#sec-isdetachedbuffer
14
15module.exports = function IsDetachedBuffer(arrayBuffer) {
16 var isSAB = isSharedArrayBuffer(arrayBuffer);
17 if (!isArrayBuffer(arrayBuffer) && !isSAB) {
18 throw new $TypeError('Assertion failed: `arrayBuffer` must be an Object with an [[ArrayBufferData]] internal slot');
19 }
20 if ((isSAB ? $sabByteLength : $byteLength)(arrayBuffer) === 0) {
21 try {
22 new global[availableTypedArrays[0]](arrayBuffer); // eslint-disable-line no-new
23 } catch (error) {
24 return !!error && error.name === 'TypeError';
25 }
26 }
27 return false;
28};
Note: See TracBrowser for help on using the repository browser.