Giant blob of minor changes
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / core-js / internals / array-buffer-view-core.js
1 'use strict';
2 var NATIVE_ARRAY_BUFFER = require('../internals/array-buffer-native');
3 var DESCRIPTORS = require('../internals/descriptors');
4 var global = require('../internals/global');
5 var isObject = require('../internals/is-object');
6 var has = require('../internals/has');
7 var classof = require('../internals/classof');
8 var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
9 var redefine = require('../internals/redefine');
10 var defineProperty = require('../internals/object-define-property').f;
11 var getPrototypeOf = require('../internals/object-get-prototype-of');
12 var setPrototypeOf = require('../internals/object-set-prototype-of');
13 var wellKnownSymbol = require('../internals/well-known-symbol');
14 var uid = require('../internals/uid');
15
16 var Int8Array = global.Int8Array;
17 var Int8ArrayPrototype = Int8Array && Int8Array.prototype;
18 var Uint8ClampedArray = global.Uint8ClampedArray;
19 var Uint8ClampedArrayPrototype = Uint8ClampedArray && Uint8ClampedArray.prototype;
20 var TypedArray = Int8Array && getPrototypeOf(Int8Array);
21 var TypedArrayPrototype = Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype);
22 var ObjectPrototype = Object.prototype;
23 var isPrototypeOf = ObjectPrototype.isPrototypeOf;
24
25 var TO_STRING_TAG = wellKnownSymbol('toStringTag');
26 var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG');
27 // Fixing native typed arrays in Opera Presto crashes the browser, see #595
28 var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof(global.opera) !== 'Opera';
29 var TYPED_ARRAY_TAG_REQIRED = false;
30 var NAME;
31
32 var TypedArrayConstructorsList = {
33   Int8Array: 1,
34   Uint8Array: 1,
35   Uint8ClampedArray: 1,
36   Int16Array: 2,
37   Uint16Array: 2,
38   Int32Array: 4,
39   Uint32Array: 4,
40   Float32Array: 4,
41   Float64Array: 8
42 };
43
44 var BigIntArrayConstructorsList = {
45   BigInt64Array: 8,
46   BigUint64Array: 8
47 };
48
49 var isView = function isView(it) {
50   if (!isObject(it)) return false;
51   var klass = classof(it);
52   return klass === 'DataView'
53     || has(TypedArrayConstructorsList, klass)
54     || has(BigIntArrayConstructorsList, klass);
55 };
56
57 var isTypedArray = function (it) {
58   if (!isObject(it)) return false;
59   var klass = classof(it);
60   return has(TypedArrayConstructorsList, klass)
61     || has(BigIntArrayConstructorsList, klass);
62 };
63
64 var aTypedArray = function (it) {
65   if (isTypedArray(it)) return it;
66   throw TypeError('Target is not a typed array');
67 };
68
69 var aTypedArrayConstructor = function (C) {
70   if (setPrototypeOf) {
71     if (isPrototypeOf.call(TypedArray, C)) return C;
72   } else for (var ARRAY in TypedArrayConstructorsList) if (has(TypedArrayConstructorsList, NAME)) {
73     var TypedArrayConstructor = global[ARRAY];
74     if (TypedArrayConstructor && (C === TypedArrayConstructor || isPrototypeOf.call(TypedArrayConstructor, C))) {
75       return C;
76     }
77   } throw TypeError('Target is not a typed array constructor');
78 };
79
80 var exportTypedArrayMethod = function (KEY, property, forced) {
81   if (!DESCRIPTORS) return;
82   if (forced) for (var ARRAY in TypedArrayConstructorsList) {
83     var TypedArrayConstructor = global[ARRAY];
84     if (TypedArrayConstructor && has(TypedArrayConstructor.prototype, KEY)) {
85       delete TypedArrayConstructor.prototype[KEY];
86     }
87   }
88   if (!TypedArrayPrototype[KEY] || forced) {
89     redefine(TypedArrayPrototype, KEY, forced ? property
90       : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property);
91   }
92 };
93
94 var exportTypedArrayStaticMethod = function (KEY, property, forced) {
95   var ARRAY, TypedArrayConstructor;
96   if (!DESCRIPTORS) return;
97   if (setPrototypeOf) {
98     if (forced) for (ARRAY in TypedArrayConstructorsList) {
99       TypedArrayConstructor = global[ARRAY];
100       if (TypedArrayConstructor && has(TypedArrayConstructor, KEY)) {
101         delete TypedArrayConstructor[KEY];
102       }
103     }
104     if (!TypedArray[KEY] || forced) {
105       // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable
106       try {
107         return redefine(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && Int8Array[KEY] || property);
108       } catch (error) { /* empty */ }
109     } else return;
110   }
111   for (ARRAY in TypedArrayConstructorsList) {
112     TypedArrayConstructor = global[ARRAY];
113     if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) {
114       redefine(TypedArrayConstructor, KEY, property);
115     }
116   }
117 };
118
119 for (NAME in TypedArrayConstructorsList) {
120   if (!global[NAME]) NATIVE_ARRAY_BUFFER_VIEWS = false;
121 }
122
123 // WebKit bug - typed arrays constructors prototype is Object.prototype
124 if (!NATIVE_ARRAY_BUFFER_VIEWS || typeof TypedArray != 'function' || TypedArray === Function.prototype) {
125   // eslint-disable-next-line no-shadow
126   TypedArray = function TypedArray() {
127     throw TypeError('Incorrect invocation');
128   };
129   if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
130     if (global[NAME]) setPrototypeOf(global[NAME], TypedArray);
131   }
132 }
133
134 if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) {
135   TypedArrayPrototype = TypedArray.prototype;
136   if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
137     if (global[NAME]) setPrototypeOf(global[NAME].prototype, TypedArrayPrototype);
138   }
139 }
140
141 // WebKit bug - one more object in Uint8ClampedArray prototype chain
142 if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) {
143   setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype);
144 }
145
146 if (DESCRIPTORS && !has(TypedArrayPrototype, TO_STRING_TAG)) {
147   TYPED_ARRAY_TAG_REQIRED = true;
148   defineProperty(TypedArrayPrototype, TO_STRING_TAG, { get: function () {
149     return isObject(this) ? this[TYPED_ARRAY_TAG] : undefined;
150   } });
151   for (NAME in TypedArrayConstructorsList) if (global[NAME]) {
152     createNonEnumerableProperty(global[NAME], TYPED_ARRAY_TAG, NAME);
153   }
154 }
155
156 module.exports = {
157   NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS,
158   TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQIRED && TYPED_ARRAY_TAG,
159   aTypedArray: aTypedArray,
160   aTypedArrayConstructor: aTypedArrayConstructor,
161   exportTypedArrayMethod: exportTypedArrayMethod,
162   exportTypedArrayStaticMethod: exportTypedArrayStaticMethod,
163   isView: isView,
164   isTypedArray: isTypedArray,
165   TypedArray: TypedArray,
166   TypedArrayPrototype: TypedArrayPrototype
167 };