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:
856 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 |
|
---|
| 8 | var callBound = require('call-bind/callBound');
|
---|
| 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.