'use strict';
var $ = require('../internals/export');
var global = require('../internals/global');
+var call = require('../internals/function-call');
var DESCRIPTORS = require('../internals/descriptors');
var TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS = require('../internals/typed-array-constructors-require-wrappers');
var ArrayBufferViewCore = require('../internals/array-buffer-view-core');
var anInstance = require('../internals/an-instance');
var createPropertyDescriptor = require('../internals/create-property-descriptor');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
+var isIntegralNumber = require('../internals/is-integral-number');
var toLength = require('../internals/to-length');
var toIndex = require('../internals/to-index');
var toOffset = require('../internals/to-offset');
-var toPrimitive = require('../internals/to-primitive');
-var has = require('../internals/has');
+var toPropertyKey = require('../internals/to-property-key');
+var hasOwn = require('../internals/has-own-property');
var classof = require('../internals/classof');
var isObject = require('../internals/is-object');
+var isSymbol = require('../internals/is-symbol');
var create = require('../internals/object-create');
+var isPrototypeOf = require('../internals/object-is-prototype-of');
var setPrototypeOf = require('../internals/object-set-prototype-of');
var getOwnPropertyNames = require('../internals/object-get-own-property-names').f;
var typedArrayFrom = require('../internals/typed-array-from');
var round = Math.round;
var RangeError = global.RangeError;
var ArrayBuffer = ArrayBufferModule.ArrayBuffer;
+var ArrayBufferPrototype = ArrayBuffer.prototype;
var DataView = ArrayBufferModule.DataView;
var NATIVE_ARRAY_BUFFER_VIEWS = ArrayBufferViewCore.NATIVE_ARRAY_BUFFER_VIEWS;
+var TYPED_ARRAY_CONSTRUCTOR = ArrayBufferViewCore.TYPED_ARRAY_CONSTRUCTOR;
var TYPED_ARRAY_TAG = ArrayBufferViewCore.TYPED_ARRAY_TAG;
var TypedArray = ArrayBufferViewCore.TypedArray;
var TypedArrayPrototype = ArrayBufferViewCore.TypedArrayPrototype;
var WRONG_LENGTH = 'Wrong length';
var fromList = function (C, list) {
+ aTypedArrayConstructor(C);
var index = 0;
var length = list.length;
- var result = new (aTypedArrayConstructor(C))(length);
+ var result = new C(length);
while (length > index) result[index] = list[index++];
return result;
};
var isArrayBuffer = function (it) {
var klass;
- return it instanceof ArrayBuffer || (klass = classof(it)) == 'ArrayBuffer' || klass == 'SharedArrayBuffer';
+ return isPrototypeOf(ArrayBufferPrototype, it) || (klass = classof(it)) == 'ArrayBuffer' || klass == 'SharedArrayBuffer';
};
var isTypedArrayIndex = function (target, key) {
return isTypedArray(target)
- && typeof key != 'symbol'
+ && !isSymbol(key)
&& key in target
- && String(+key) == String(key);
+ && isIntegralNumber(+key)
+ && key >= 0;
};
var wrappedGetOwnPropertyDescriptor = function getOwnPropertyDescriptor(target, key) {
- return isTypedArrayIndex(target, key = toPrimitive(key, true))
+ key = toPropertyKey(key);
+ return isTypedArrayIndex(target, key)
? createPropertyDescriptor(2, target[key])
: nativeGetOwnPropertyDescriptor(target, key);
};
var wrappedDefineProperty = function defineProperty(target, key, descriptor) {
- if (isTypedArrayIndex(target, key = toPrimitive(key, true))
+ key = toPropertyKey(key);
+ if (isTypedArrayIndex(target, key)
&& isObject(descriptor)
- && has(descriptor, 'value')
- && !has(descriptor, 'get')
- && !has(descriptor, 'set')
+ && hasOwn(descriptor, 'value')
+ && !hasOwn(descriptor, 'get')
+ && !hasOwn(descriptor, 'set')
// TODO: add validation descriptor w/o calling accessors
&& !descriptor.configurable
- && (!has(descriptor, 'writable') || descriptor.writable)
- && (!has(descriptor, 'enumerable') || descriptor.enumerable)
+ && (!hasOwn(descriptor, 'writable') || descriptor.writable)
+ && (!hasOwn(descriptor, 'enumerable') || descriptor.enumerable)
) {
target[key] = descriptor.value;
return target;
if (!NATIVE_ARRAY_BUFFER_VIEWS) {
TypedArrayConstructor = wrapper(function (that, data, offset, $length) {
- anInstance(that, TypedArrayConstructor, CONSTRUCTOR_NAME);
+ anInstance(that, TypedArrayConstructorPrototype);
var index = 0;
var byteOffset = 0;
var buffer, byteLength, length;
} else if (isTypedArray(data)) {
return fromList(TypedArrayConstructor, data);
} else {
- return typedArrayFrom.call(TypedArrayConstructor, data);
+ return call(typedArrayFrom, TypedArrayConstructor, data);
}
setInternalState(that, {
buffer: buffer,
TypedArrayConstructorPrototype = TypedArrayConstructor.prototype = create(TypedArrayPrototype);
} else if (TYPED_ARRAYS_CONSTRUCTORS_REQUIRES_WRAPPERS) {
TypedArrayConstructor = wrapper(function (dummy, data, typedArrayOffset, $length) {
- anInstance(dummy, TypedArrayConstructor, CONSTRUCTOR_NAME);
+ anInstance(dummy, TypedArrayConstructorPrototype);
return inheritIfRequired(function () {
if (!isObject(data)) return new NativeTypedArrayConstructor(toIndex(data));
if (isArrayBuffer(data)) return $length !== undefined
? new NativeTypedArrayConstructor(data, toOffset(typedArrayOffset, BYTES))
: new NativeTypedArrayConstructor(data);
if (isTypedArray(data)) return fromList(TypedArrayConstructor, data);
- return typedArrayFrom.call(TypedArrayConstructor, data);
+ return call(typedArrayFrom, TypedArrayConstructor, data);
}(), dummy, TypedArrayConstructor);
});
createNonEnumerableProperty(TypedArrayConstructorPrototype, 'constructor', TypedArrayConstructor);
}
+ createNonEnumerableProperty(TypedArrayConstructorPrototype, TYPED_ARRAY_CONSTRUCTOR, TypedArrayConstructor);
+
if (TYPED_ARRAY_TAG) {
createNonEnumerableProperty(TypedArrayConstructorPrototype, TYPED_ARRAY_TAG, CONSTRUCTOR_NAME);
}