2952bc673a4122aa4c9dc2fe791db6db86b0ef2a
[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 isView = function isView(it) {
45   var klass = classof(it);
46   return klass === 'DataView' || has(TypedArrayConstructorsList, klass);
47 };
48
49 var isTypedArray = function (it) {
50   return isObject(it) && has(TypedArrayConstructorsList, classof(it));
51 };
52
53 var aTypedArray = function (it) {
54   if (isTypedArray(it)) return it;
55   throw TypeError('Target is not a typed array');
56 };
57
58 var aTypedArrayConstructor = function (C) {
59   if (setPrototypeOf) {
60     if (isPrototypeOf.call(TypedArray, C)) return C;
61   } else for (var ARRAY in TypedArrayConstructorsList) if (has(TypedArrayConstructorsList, NAME)) {
62     var TypedArrayConstructor = global[ARRAY];
63     if (TypedArrayConstructor && (C === TypedArrayConstructor || isPrototypeOf.call(TypedArrayConstructor, C))) {
64       return C;
65     }
66   } throw TypeError('Target is not a typed array constructor');
67 };
68
69 var exportTypedArrayMethod = function (KEY, property, forced) {
70   if (!DESCRIPTORS) return;
71   if (forced) for (var ARRAY in TypedArrayConstructorsList) {
72     var TypedArrayConstructor = global[ARRAY];
73     if (TypedArrayConstructor && has(TypedArrayConstructor.prototype, KEY)) {
74       delete TypedArrayConstructor.prototype[KEY];
75     }
76   }
77   if (!TypedArrayPrototype[KEY] || forced) {
78     redefine(TypedArrayPrototype, KEY, forced ? property
79       : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property);
80   }
81 };
82
83 var exportTypedArrayStaticMethod = function (KEY, property, forced) {
84   var ARRAY, TypedArrayConstructor;
85   if (!DESCRIPTORS) return;
86   if (setPrototypeOf) {
87     if (forced) for (ARRAY in TypedArrayConstructorsList) {
88       TypedArrayConstructor = global[ARRAY];
89       if (TypedArrayConstructor && has(TypedArrayConstructor, KEY)) {
90         delete TypedArrayConstructor[KEY];
91       }
92     }
93     if (!TypedArray[KEY] || forced) {
94       // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable
95       try {
96         return redefine(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && Int8Array[KEY] || property);
97       } catch (error) { /* empty */ }
98     } else return;
99   }
100   for (ARRAY in TypedArrayConstructorsList) {
101     TypedArrayConstructor = global[ARRAY];
102     if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) {
103       redefine(TypedArrayConstructor, KEY, property);
104     }
105   }
106 };
107
108 for (NAME in TypedArrayConstructorsList) {
109   if (!global[NAME]) NATIVE_ARRAY_BUFFER_VIEWS = false;
110 }
111
112 // WebKit bug - typed arrays constructors prototype is Object.prototype
113 if (!NATIVE_ARRAY_BUFFER_VIEWS || typeof TypedArray != 'function' || TypedArray === Function.prototype) {
114   // eslint-disable-next-line no-shadow
115   TypedArray = function TypedArray() {
116     throw TypeError('Incorrect invocation');
117   };
118   if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
119     if (global[NAME]) setPrototypeOf(global[NAME], TypedArray);
120   }
121 }
122
123 if (!NATIVE_ARRAY_BUFFER_VIEWS || !TypedArrayPrototype || TypedArrayPrototype === ObjectPrototype) {
124   TypedArrayPrototype = TypedArray.prototype;
125   if (NATIVE_ARRAY_BUFFER_VIEWS) for (NAME in TypedArrayConstructorsList) {
126     if (global[NAME]) setPrototypeOf(global[NAME].prototype, TypedArrayPrototype);
127   }
128 }
129
130 // WebKit bug - one more object in Uint8ClampedArray prototype chain
131 if (NATIVE_ARRAY_BUFFER_VIEWS && getPrototypeOf(Uint8ClampedArrayPrototype) !== TypedArrayPrototype) {
132   setPrototypeOf(Uint8ClampedArrayPrototype, TypedArrayPrototype);
133 }
134
135 if (DESCRIPTORS && !has(TypedArrayPrototype, TO_STRING_TAG)) {
136   TYPED_ARRAY_TAG_REQIRED = true;
137   defineProperty(TypedArrayPrototype, TO_STRING_TAG, { get: function () {
138     return isObject(this) ? this[TYPED_ARRAY_TAG] : undefined;
139   } });
140   for (NAME in TypedArrayConstructorsList) if (global[NAME]) {
141     createNonEnumerableProperty(global[NAME], TYPED_ARRAY_TAG, NAME);
142   }
143 }
144
145 module.exports = {
146   NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS,
147   TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQIRED && TYPED_ARRAY_TAG,
148   aTypedArray: aTypedArray,
149   aTypedArrayConstructor: aTypedArrayConstructor,
150   exportTypedArrayMethod: exportTypedArrayMethod,
151   exportTypedArrayStaticMethod: exportTypedArrayStaticMethod,
152   isView: isView,
153   isTypedArray: isTypedArray,
154   TypedArray: TypedArray,
155   TypedArrayPrototype: TypedArrayPrototype
156 };