main
Last change
on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
998 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var $byteLength = require('array-buffer-byte-length');
|
---|
| 6 | var availableTypedArrays = require('available-typed-arrays')();
|
---|
[79a0317] | 7 | var callBound = require('call-bound');
|
---|
[d565449] | 8 | var isArrayBuffer = require('is-array-buffer');
|
---|
| 9 | var isSharedArrayBuffer = require('is-shared-array-buffer');
|
---|
| 10 |
|
---|
| 11 | var $sabByteLength = callBound('SharedArrayBuffer.prototype.byteLength', true);
|
---|
| 12 |
|
---|
| 13 | // https://262.ecma-international.org/8.0/#sec-isdetachedbuffer
|
---|
| 14 |
|
---|
| 15 | module.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.