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:
847 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $ArrayBuffer = GetIntrinsic('%ArrayBuffer%');
|
---|
| 6 | var $DataView = GetIntrinsic('%DataView%', true);
|
---|
| 7 |
|
---|
[79a0317] | 8 | var callBound = require('call-bound');
|
---|
[d565449] | 9 |
|
---|
| 10 | // node <= 0.10, < 0.11.4 has a nonconfigurable own property instead of a prototype getter
|
---|
| 11 | var $dataViewBuffer = callBound('DataView.prototype.buffer', true);
|
---|
| 12 |
|
---|
| 13 | var isTypedArray = require('is-typed-array');
|
---|
| 14 |
|
---|
| 15 | /** @type {import('.')} */
|
---|
| 16 | module.exports = function isDataView(x) {
|
---|
| 17 | if (!x || typeof x !== 'object' || !$DataView || isTypedArray(x)) {
|
---|
| 18 | return false;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | if ($dataViewBuffer) {
|
---|
| 22 | try {
|
---|
| 23 | $dataViewBuffer(x);
|
---|
| 24 | return true;
|
---|
| 25 | } catch (e) {
|
---|
| 26 | return false;
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | if (
|
---|
| 31 | ('getInt8' in x)
|
---|
| 32 | && typeof x.getInt8 === 'function'
|
---|
| 33 | && x.getInt8 === new $DataView(new $ArrayBuffer(1)).getInt8
|
---|
| 34 | ) {
|
---|
| 35 | return true;
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | return false;
|
---|
| 39 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.