| Index: src/js/typedarray.js
|
| diff --git a/src/js/typedarray.js b/src/js/typedarray.js
|
| index 117148dc5e8e685110d62f764fe67c86149ea745..ab387d4234f438b944e851e2228152760fdc2f14 100644
|
| --- a/src/js/typedarray.js
|
| +++ b/src/js/typedarray.js
|
| @@ -13,7 +13,6 @@
|
|
|
| // array.js has to come before typedarray.js for this to work
|
| var ArrayToString = utils.ImportNow("ArrayToString");
|
| -var ArrayValues;
|
| var GetIterator;
|
| var GetMethod;
|
| var GlobalArray = global.Array;
|
| @@ -56,7 +55,6 @@ TYPED_ARRAYS(DECLARE_GLOBALS)
|
| var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
|
|
|
| utils.Import(function(from) {
|
| - ArrayValues = from.ArrayValues;
|
| GetIterator = from.GetIterator;
|
| GetMethod = from.GetMethod;
|
| InnerArrayFilter = from.InnerArrayFilter;
|
| @@ -74,6 +72,14 @@ utils.Import(function(from) {
|
|
|
| // --------------- Typed Arrays ---------------------
|
|
|
| +// ES6 section 22.2.3.5.1 ValidateTypedArray ( O )
|
| +function ValidateTypedArray(array, methodName) {
|
| + if (!IS_TYPEDARRAY(array)) throw %make_type_error(kNotTypedArray);
|
| +
|
| + if (%_ArrayBufferViewWasNeutered(array))
|
| + throw %make_type_error(kDetachedOperation, methodName);
|
| +}
|
| +
|
| function TypedArrayDefaultConstructor(typedArray) {
|
| switch (%_ClassOf(typedArray)) {
|
| macro TYPED_ARRAY_CONSTRUCTOR_CASE(NAME, ELEMENT_SIZE)
|
| @@ -94,20 +100,16 @@ function TypedArrayCreate(constructor, arg0, arg1, arg2) {
|
| } else {
|
| var newTypedArray = new constructor(arg0, arg1, arg2);
|
| }
|
| - if (!IS_TYPEDARRAY(newTypedArray)) throw %make_type_error(kNotTypedArray);
|
| - // TODO(littledan): Check for being detached, here and elsewhere
|
| - // All callers where the first argument is a Number have no additional
|
| - // arguments.
|
| + ValidateTypedArray(newTypedArray, "TypedArrayCreate");
|
| if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) {
|
| throw %make_type_error(kTypedArrayTooShort);
|
| }
|
| return newTypedArray;
|
| }
|
|
|
| -function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) {
|
| +function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) {
|
| var defaultConstructor = TypedArrayDefaultConstructor(exemplar);
|
| - var constructor = SpeciesConstructor(exemplar, defaultConstructor,
|
| - conservative);
|
| + var constructor = SpeciesConstructor(exemplar, defaultConstructor);
|
| return TypedArrayCreate(constructor, arg0, arg1, arg2);
|
| }
|
|
|
| @@ -207,10 +209,8 @@ function NAMESubArray(begin, end) {
|
| var newLength = endInt - beginInt;
|
| var beginByteOffset =
|
| %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
|
| - // BUG(v8:4665): For web compatibility, subarray needs to always build an
|
| - // instance of the default constructor.
|
| - // TODO(littledan): Switch to the standard or standardize the fix
|
| - return new GlobalNAME(%TypedArrayGetBuffer(this), beginByteOffset, newLength);
|
| + return TypedArraySpeciesCreate(this, %TypedArrayGetBuffer(this),
|
| + beginByteOffset, newLength);
|
| }
|
| endmacro
|
|
|
| @@ -225,7 +225,7 @@ endmacro
|
| TYPED_ARRAYS(TYPED_ARRAY_SUBARRAY_CASE)
|
| }
|
| throw %make_type_error(kIncompatibleMethodReceiver,
|
| - "get TypedArray.prototype.subarray", this);
|
| + "get %TypedArray%.prototype.subarray", this);
|
| }
|
| %SetForceInlineFlag(TypedArraySubArray);
|
|
|
| @@ -360,7 +360,7 @@ function InnerTypedArrayEvery(f, receiver, array, length) {
|
|
|
| // ES6 draft 05-05-15, section 22.2.3.7
|
| function TypedArrayEvery(f, receiver) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.every");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -390,7 +390,7 @@ function InnerTypedArrayForEach(f, receiver, array, length) {
|
|
|
| // ES6 draft 08-24-14, section 22.2.3.12
|
| function TypedArrayForEach(f, receiver) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.forEach");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -401,7 +401,7 @@ function TypedArrayForEach(f, receiver) {
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.9
|
| function TypedArrayFilter(f, thisArg) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypeArray%.prototype.filter");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
|
| @@ -419,7 +419,7 @@ function TypedArrayFilter(f, thisArg) {
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.10
|
| function TypedArrayFind(predicate, thisArg) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.find");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -430,7 +430,7 @@ function TypedArrayFind(predicate, thisArg) {
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.11
|
| function TypedArrayFindIndex(predicate, thisArg) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.findIndex");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -441,7 +441,7 @@ function TypedArrayFindIndex(predicate, thisArg) {
|
|
|
| // ES6 draft 05-18-15, section 22.2.3.25
|
| function TypedArraySort(comparefn) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.sort");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -455,7 +455,7 @@ function TypedArraySort(comparefn) {
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.18
|
| function TypedArrayMap(f, thisArg) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.map");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| var result = TypedArraySpeciesCreate(this, length);
|
| @@ -482,7 +482,7 @@ function InnerTypedArraySome(f, receiver, array, length) {
|
|
|
| // ES6 draft 05-05-15, section 22.2.3.24
|
| function TypedArraySome(f, receiver) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.some");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -493,7 +493,7 @@ function TypedArraySome(f, receiver) {
|
|
|
| // ES6 section 22.2.3.27
|
| function TypedArrayToLocaleString() {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -503,7 +503,7 @@ function TypedArrayToLocaleString() {
|
|
|
| // ES6 section 22.2.3.14
|
| function TypedArrayJoin(separator) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.join");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -538,7 +538,7 @@ function InnerTypedArrayReduce(
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.19
|
| function TypedArrayReduce(callback, current) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.reduce");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| return InnerTypedArrayReduce(
|
| @@ -574,7 +574,7 @@ function InnerArrayReduceRight(callback, current, array, length,
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.19
|
| function TypedArrayReduceRight(callback, current) {
|
| - if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
| + ValidateTypedArray(this, "%TypedArray%.prototype.reduceRight");
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| return InnerArrayReduceRight(callback, current, this, length,
|
|
|