source: trip-planner-front/node_modules/core-js/internals/typed-array-constructor.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 9.8 KB
Line 
1'use strict';
2var $ = require('../internals/export');
3var global = require('../internals/global');
4var DESCRIPTORS = require('../internals/descriptors');
5var TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS = require('../internals/typed-array-constructors-require-wrappers');
6var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
7var ArrayBufferModule = require('../internals/array-buffer');
8var anInstance = require('../internals/an-instance');
9var createPropertyDescriptor = require('../internals/create-property-descriptor');
10var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
11var isInteger = require('../internals/is-integer');
12var toLength = require('../internals/to-length');
13var toIndex = require('../internals/to-index');
14var toOffset = require('../internals/to-offset');
15var toPropertyKey = require('../internals/to-property-key');
16var has = require('../internals/has');
17var classof = require('../internals/classof');
18var isObject = require('../internals/is-object');
19var isSymbol = require('../internals/is-symbol');
20var create = require('../internals/object-create');
21var setPrototypeOf = require('../internals/object-set-prototype-of');
22var getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
23var typedArrayFrom = require('../internals/typed-array-from');
24var forEach = require('../internals/array-iteration').forEach;
25var setSpecies = require('../internals/set-species');
26var definePropertyModule = require('../internals/object-define-property');
27var getOwnPropertyDescriptorModule = require('../internals/object-get-own-property-descriptor');
28var InternalStateModule = require('../internals/internal-state');
29var inheritIfRequired = require('../internals/inherit-if-required');
30
31var getInternalState = InternalStateModule.get;
32var setInternalState = InternalStateModule.set;
33var nativeDefineProperty = definePropertyModule.f;
34var nativeGetOwnPropertyDescriptor = getOwnPropertyDescriptorModule.f;
35var round = Math.round;
36var RangeError = global.RangeError;
37var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
38var DataView = ArrayBufferModule.DataView;
39var NATIVE_ARRAY_BUFFER_VIEWS = ArrayBufferViewCore.NATIVE_ARRAY_BUFFER_VIEWS;
40var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR;
41var TYPED_ARRAY_TAG = ArrayBufferViewCore.TYPED_ARRAY_TAG;
42var TypedArray = ArrayBufferViewCore.TypedArray;
43var TypedArrayPrototype = ArrayBufferViewCore.TypedArrayPrototype;
44var aTypedArrayConstructor = ArrayBufferViewCore.aTypedArrayConstructor;
45var isTypedArray = ArrayBufferViewCore.isTypedArray;
46var BYTES_PER_ELEMENT = 'BYTES_PER_ELEMENT';
47var WRONG_LENGTH = 'Wrong length';
48
49var fromList = function (C, list) {
50 var index = 0;
51 var length = list.length;
52 var result = new (aTypedArrayConstructor(C))(length);
53 while (length > index) result[index] = list[index++];
54 return result;
55};
56
57var addGetter = function (it, key) {
58 nativeDefineProperty(it, key, { get: function () {
59 return getInternalState(this)[key];
60 } });
61};
62
63var isArrayBuffer = function (it) {
64 var klass;
65 return it instanceof ArrayBuffer || (klass = classof(it)) == 'ArrayBuffer' || klass == 'SharedArrayBuffer';
66};
67
68var isTypedArrayIndex = function (target, key) {
69 return isTypedArray(target)
70 && !isSymbol(key)
71 && key in target
72 && isInteger(+key)
73 && key >= 0;
74};
75
76var wrappedGetOwnPropertyDescriptor = function getOwnPropertyDescriptor(target, key) {
77 key = toPropertyKey(key);
78 return isTypedArrayIndex(target, key)
79 ? createPropertyDescriptor(2, target[key])
80 : nativeGetOwnPropertyDescriptor(target, key);
81};
82
83var wrappedDefineProperty = function defineProperty(target, key, descriptor) {
84 key = toPropertyKey(key);
85 if (isTypedArrayIndex(target, key)
86 && isObject(descriptor)
87 && has(descriptor, 'value')
88 && !has(descriptor, 'get')
89 && !has(descriptor, 'set')
90 // TODO: add validation descriptor w/o calling accessors
91 && !descriptor.configurable
92 && (!has(descriptor, 'writable') || descriptor.writable)
93 && (!has(descriptor, 'enumerable') || descriptor.enumerable)
94 ) {
95 target[key] = descriptor.value;
96 return target;
97 } return nativeDefineProperty(target, key, descriptor);
98};
99
100if (DESCRIPTORS) {
101 if (!NATIVE_ARRAY_BUFFER_VIEWS) {
102 getOwnPropertyDescriptorModule.f = wrappedGetOwnPropertyDescriptor;
103 definePropertyModule.f = wrappedDefineProperty;
104 addGetter(TypedArrayPrototype, 'buffer');
105 addGetter(TypedArrayPrototype, 'byteOffset');
106 addGetter(TypedArrayPrototype, 'byteLength');
107 addGetter(TypedArrayPrototype, 'length');
108 }
109
110 $({ target: 'Object', stat: true, forced: !NATIVE_ARRAY_BUFFER_VIEWS }, {
111 getOwnPropertyDescriptor: wrappedGetOwnPropertyDescriptor,
112 defineProperty: wrappedDefineProperty
113 });
114
115 module.exports = function (TYPE, wrapper, CLAMPED) {
116 var BYTES = TYPE.match(/\d+$/)[0] / 8;
117 var CONSTRUCTOR_NAME = TYPE + (CLAMPED ? 'Clamped' : '') + 'Array';
118 var GETTER = 'get' + TYPE;
119 var SETTER = 'set' + TYPE;
120 var NativeTypedArrayConstructor = global[CONSTRUCTOR_NAME];
121 var TypedArrayConstructor = NativeTypedArrayConstructor;
122 var TypedArrayConstructorPrototype = TypedArrayConstructor && TypedArrayConstructor.prototype;
123 var exported = {};
124
125 var getter = function (that, index) {
126 var data = getInternalState(that);
127 return data.view[GETTER](index * BYTES + data.byteOffset, true);
128 };
129
130 var setter = function (that, index, value) {
131 var data = getInternalState(that);
132 if (CLAMPED) value = (value = round(value)) < 0 ? 0 : value > 0xFF ? 0xFF : value & 0xFF;
133 data.view[SETTER](index * BYTES + data.byteOffset, value, true);
134 };
135
136 var addElement = function (that, index) {
137 nativeDefineProperty(that, index, {
138 get: function () {
139 return getter(this, index);
140 },
141 set: function (value) {
142 return setter(this, index, value);
143 },
144 enumerable: true
145 });
146 };
147
148 if (!NATIVE_ARRAY_BUFFER_VIEWS) {
149 TypedArrayConstructor = wrapper(function (that, data, offset, $length) {
150 anInstance(that, TypedArrayConstructor, CONSTRUCTOR_NAME);
151 var index = 0;
152 var byteOffset = 0;
153 var buffer, byteLength, length;
154 if (!isObject(data)) {
155 length = toIndex(data);
156 byteLength = length * BYTES;
157 buffer = new ArrayBuffer(byteLength);
158 } else if (isArrayBuffer(data)) {
159 buffer = data;
160 byteOffset = toOffset(offset, BYTES);
161 var $len = data.byteLength;
162 if ($length === undefined) {
163 if ($len % BYTES) throw RangeError(WRONG_LENGTH);
164 byteLength = $len - byteOffset;
165 if (byteLength < 0) throw RangeError(WRONG_LENGTH);
166 } else {
167 byteLength = toLength($length) * BYTES;
168 if (byteLength + byteOffset > $len) throw RangeError(WRONG_LENGTH);
169 }
170 length = byteLength / BYTES;
171 } else if (isTypedArray(data)) {
172 return fromList(TypedArrayConstructor, data);
173 } else {
174 return typedArrayFrom.call(TypedArrayConstructor, data);
175 }
176 setInternalState(that, {
177 buffer: buffer,
178 byteOffset: byteOffset,
179 byteLength: byteLength,
180 length: length,
181 view: new DataView(buffer)
182 });
183 while (index < length) addElement(that, index++);
184 });
185
186 if (setPrototypeOf) setPrototypeOf(TypedArrayConstructor, TypedArray);
187 TypedArrayConstructorPrototype = TypedArrayConstructor.prototype = create(TypedArrayPrototype);
188 } else if (TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS) {
189 TypedArrayConstructor = wrapper(function (dummy, data, typedArrayOffset, $length) {
190 anInstance(dummy, TypedArrayConstructor, CONSTRUCTOR_NAME);
191 return inheritIfRequired(function () {
192 if (!isObject(data)) return new NativeTypedArrayConstructor(toIndex(data));
193 if (isArrayBuffer(data)) return $length !== undefined
194 ? new NativeTypedArrayConstructor(data, toOffset(typedArrayOffset, BYTES), $length)
195 : typedArrayOffset !== undefined
196 ? new NativeTypedArrayConstructor(data, toOffset(typedArrayOffset, BYTES))
197 : new NativeTypedArrayConstructor(data);
198 if (isTypedArray(data)) return fromList(TypedArrayConstructor, data);
199 return typedArrayFrom.call(TypedArrayConstructor, data);
200 }(), dummy, TypedArrayConstructor);
201 });
202
203 if (setPrototypeOf) setPrototypeOf(TypedArrayConstructor, TypedArray);
204 forEach(getOwnPropertyNames(NativeTypedArrayConstructor), function (key) {
205 if (!(key in TypedArrayConstructor)) {
206 createNonEnumerableProperty(TypedArrayConstructor, key, NativeTypedArrayConstructor[key]);
207 }
208 });
209 TypedArrayConstructor.prototype = TypedArrayConstructorPrototype;
210 }
211
212 if (TypedArrayConstructorPrototype.constructor !== TypedArrayConstructor) {
213 createNonEnumerableProperty(TypedArrayConstructorPrototype, 'constructor', TypedArrayConstructor);
214 }
215
216 createNonEnumerableProperty(TypedArrayConstructorPrototype, TYPED_ARRAY_CONSTRUCTOR, TypedArrayConstructor);
217
218 if (TYPED_ARRAY_TAG) {
219 createNonEnumerableProperty(TypedArrayConstructorPrototype, TYPED_ARRAY_TAG, CONSTRUCTOR_NAME);
220 }
221
222 exported[CONSTRUCTOR_NAME] = TypedArrayConstructor;
223
224 $({
225 global: true, forced: TypedArrayConstructor != NativeTypedArrayConstructor, sham: !NATIVE_ARRAY_BUFFER_VIEWS
226 }, exported);
227
228 if (!(BYTES_PER_ELEMENT in TypedArrayConstructor)) {
229 createNonEnumerableProperty(TypedArrayConstructor, BYTES_PER_ELEMENT, BYTES);
230 }
231
232 if (!(BYTES_PER_ELEMENT in TypedArrayConstructorPrototype)) {
233 createNonEnumerableProperty(TypedArrayConstructorPrototype, BYTES_PER_ELEMENT, BYTES);
234 }
235
236 setSpecies(CONSTRUCTOR_NAME);
237 };
238} else module.exports = function () { /* empty */ };
Note: See TracBrowser for help on using the repository browser.