| | |
| | | var classof = require('../internals/classof'); |
| | | var tryToString = require('../internals/try-to-string'); |
| | | var createNonEnumerableProperty = require('../internals/create-non-enumerable-property'); |
| | | var redefine = require('../internals/redefine'); |
| | | var defineBuiltIn = require('../internals/define-built-in'); |
| | | var defineProperty = require('../internals/object-define-property').f; |
| | | var isPrototypeOf = require('../internals/object-is-prototype-of'); |
| | | var getPrototypeOf = require('../internals/object-get-prototype-of'); |
| | | var setPrototypeOf = require('../internals/object-set-prototype-of'); |
| | | var wellKnownSymbol = require('../internals/well-known-symbol'); |
| | |
| | | var TypedArray = Int8Array && getPrototypeOf(Int8Array); |
| | | var TypedArrayPrototype = Int8ArrayPrototype && getPrototypeOf(Int8ArrayPrototype); |
| | | var ObjectPrototype = Object.prototype; |
| | | var isPrototypeOf = ObjectPrototype.isPrototypeOf; |
| | | var TypeError = global.TypeError; |
| | | |
| | | var TO_STRING_TAG = wellKnownSymbol('toStringTag'); |
| | | var TYPED_ARRAY_TAG = uid('TYPED_ARRAY_TAG'); |
| | | var TYPED_ARRAY_CONSTRUCTOR = uid('TYPED_ARRAY_CONSTRUCTOR'); |
| | | // Fixing native typed arrays in Opera Presto crashes the browser, see #595 |
| | | var NATIVE_ARRAY_BUFFER_VIEWS = NATIVE_ARRAY_BUFFER && !!setPrototypeOf && classof(global.opera) !== 'Opera'; |
| | | var TYPED_ARRAY_TAG_REQIRED = false; |
| | | var TYPED_ARRAY_TAG_REQUIRED = false; |
| | | var NAME, Constructor, Prototype; |
| | | |
| | | var TypedArrayConstructorsList = { |
| | |
| | | }; |
| | | |
| | | var aTypedArrayConstructor = function (C) { |
| | | if (isCallable(C) && (!setPrototypeOf || isPrototypeOf.call(TypedArray, C))) return C; |
| | | if (isCallable(C) && (!setPrototypeOf || isPrototypeOf(TypedArray, C))) return C; |
| | | throw TypeError(tryToString(C) + ' is not a typed array constructor'); |
| | | }; |
| | | |
| | | var exportTypedArrayMethod = function (KEY, property, forced) { |
| | | var exportTypedArrayMethod = function (KEY, property, forced, options) { |
| | | if (!DESCRIPTORS) return; |
| | | if (forced) for (var ARRAY in TypedArrayConstructorsList) { |
| | | var TypedArrayConstructor = global[ARRAY]; |
| | | if (TypedArrayConstructor && hasOwn(TypedArrayConstructor.prototype, KEY)) try { |
| | | delete TypedArrayConstructor.prototype[KEY]; |
| | | } catch (error) { /* empty */ } |
| | | } catch (error) { |
| | | // old WebKit bug - some methods are non-configurable |
| | | try { |
| | | TypedArrayConstructor.prototype[KEY] = property; |
| | | } catch (error2) { /* empty */ } |
| | | } |
| | | } |
| | | if (!TypedArrayPrototype[KEY] || forced) { |
| | | redefine(TypedArrayPrototype, KEY, forced ? property |
| | | : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property); |
| | | defineBuiltIn(TypedArrayPrototype, KEY, forced ? property |
| | | : NATIVE_ARRAY_BUFFER_VIEWS && Int8ArrayPrototype[KEY] || property, options); |
| | | } |
| | | }; |
| | | |
| | |
| | | if (!TypedArray[KEY] || forced) { |
| | | // V8 ~ Chrome 49-50 `%TypedArray%` methods are non-writable non-configurable |
| | | try { |
| | | return redefine(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && TypedArray[KEY] || property); |
| | | return defineBuiltIn(TypedArray, KEY, forced ? property : NATIVE_ARRAY_BUFFER_VIEWS && TypedArray[KEY] || property); |
| | | } catch (error) { /* empty */ } |
| | | } else return; |
| | | } |
| | | for (ARRAY in TypedArrayConstructorsList) { |
| | | TypedArrayConstructor = global[ARRAY]; |
| | | if (TypedArrayConstructor && (!TypedArrayConstructor[KEY] || forced)) { |
| | | redefine(TypedArrayConstructor, KEY, property); |
| | | defineBuiltIn(TypedArrayConstructor, KEY, property); |
| | | } |
| | | } |
| | | }; |
| | |
| | | } |
| | | |
| | | if (DESCRIPTORS && !hasOwn(TypedArrayPrototype, TO_STRING_TAG)) { |
| | | TYPED_ARRAY_TAG_REQIRED = true; |
| | | TYPED_ARRAY_TAG_REQUIRED = true; |
| | | defineProperty(TypedArrayPrototype, TO_STRING_TAG, { get: function () { |
| | | return isObject(this) ? this[TYPED_ARRAY_TAG] : undefined; |
| | | } }); |
| | |
| | | module.exports = { |
| | | NATIVE_ARRAY_BUFFER_VIEWS: NATIVE_ARRAY_BUFFER_VIEWS, |
| | | TYPED_ARRAY_CONSTRUCTOR: TYPED_ARRAY_CONSTRUCTOR, |
| | | TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQIRED && TYPED_ARRAY_TAG, |
| | | TYPED_ARRAY_TAG: TYPED_ARRAY_TAG_REQUIRED && TYPED_ARRAY_TAG, |
| | | aTypedArray: aTypedArray, |
| | | aTypedArrayConstructor: aTypedArrayConstructor, |
| | | exportTypedArrayMethod: exportTypedArrayMethod, |