main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.4 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBind = require('call-bind');
|
---|
4 | var callBound = require('call-bind/callBound');
|
---|
5 | var GetIntrinsic = require('get-intrinsic');
|
---|
6 |
|
---|
7 | var $ArrayBuffer = GetIntrinsic('%ArrayBuffer%', true);
|
---|
8 | /** @type {undefined | ((receiver: ArrayBuffer) => number) | ((receiver: unknown) => never)} */
|
---|
9 | var $byteLength = callBound('ArrayBuffer.prototype.byteLength', true);
|
---|
10 | var $toString = callBound('Object.prototype.toString');
|
---|
11 |
|
---|
12 | // in node 0.10, ArrayBuffers have no prototype methods, but have an own slot-checking `slice` method
|
---|
13 | var abSlice = !!$ArrayBuffer && !$byteLength && new $ArrayBuffer(0).slice;
|
---|
14 | var $abSlice = !!abSlice && callBind(abSlice);
|
---|
15 |
|
---|
16 | /** @type {import('.')} */
|
---|
17 | module.exports = $byteLength || $abSlice
|
---|
18 | ? function isArrayBuffer(obj) {
|
---|
19 | if (!obj || typeof obj !== 'object') {
|
---|
20 | return false;
|
---|
21 | }
|
---|
22 | try {
|
---|
23 | if ($byteLength) {
|
---|
24 | // @ts-expect-error no idea why TS can't handle the overload
|
---|
25 | $byteLength(obj);
|
---|
26 | } else {
|
---|
27 | // @ts-expect-error TS chooses not to type-narrow inside a closure
|
---|
28 | $abSlice(obj, 0);
|
---|
29 | }
|
---|
30 | return true;
|
---|
31 | } catch (e) {
|
---|
32 | return false;
|
---|
33 | }
|
---|
34 | }
|
---|
35 | : $ArrayBuffer
|
---|
36 | // in node 0.8, ArrayBuffers have no prototype or own methods, but also no Symbol.toStringTag
|
---|
37 | ? function isArrayBuffer(obj) {
|
---|
38 | return $toString(obj) === '[object ArrayBuffer]';
|
---|
39 | }
|
---|
40 | : function isArrayBuffer(obj) { // eslint-disable-line no-unused-vars
|
---|
41 | return false;
|
---|
42 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.