| Index: src/js/typedarray.js
|
| diff --git a/src/js/typedarray.js b/src/js/typedarray.js
|
| index ab387d4234f438b944e851e2228152760fdc2f14..117148dc5e8e685110d62f764fe67c86149ea745 100644
|
| --- a/src/js/typedarray.js
|
| +++ b/src/js/typedarray.js
|
| @@ -13,6 +13,7 @@
|
|
|
| // 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;
|
| @@ -55,6 +56,7 @@
|
| var GlobalTypedArray = %object_get_prototype_of(GlobalUint8Array);
|
|
|
| utils.Import(function(from) {
|
| + ArrayValues = from.ArrayValues;
|
| GetIterator = from.GetIterator;
|
| GetMethod = from.GetMethod;
|
| InnerArrayFilter = from.InnerArrayFilter;
|
| @@ -72,14 +74,6 @@
|
|
|
| // --------------- 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)
|
| @@ -100,16 +94,20 @@
|
| } else {
|
| var newTypedArray = new constructor(arg0, arg1, arg2);
|
| }
|
| - ValidateTypedArray(newTypedArray, "TypedArrayCreate");
|
| + 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.
|
| if (IS_NUMBER(arg0) && %_TypedArrayGetLength(newTypedArray) < arg0) {
|
| throw %make_type_error(kTypedArrayTooShort);
|
| }
|
| return newTypedArray;
|
| }
|
|
|
| -function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2) {
|
| +function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) {
|
| var defaultConstructor = TypedArrayDefaultConstructor(exemplar);
|
| - var constructor = SpeciesConstructor(exemplar, defaultConstructor);
|
| + var constructor = SpeciesConstructor(exemplar, defaultConstructor,
|
| + conservative);
|
| return TypedArrayCreate(constructor, arg0, arg1, arg2);
|
| }
|
|
|
| @@ -209,8 +207,10 @@
|
| var newLength = endInt - beginInt;
|
| var beginByteOffset =
|
| %_ArrayBufferViewGetByteOffset(this) + beginInt * ELEMENT_SIZE;
|
| - return TypedArraySpeciesCreate(this, %TypedArrayGetBuffer(this),
|
| - beginByteOffset, newLength);
|
| + // 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);
|
| }
|
| endmacro
|
|
|
| @@ -225,7 +225,7 @@
|
| 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 @@
|
|
|
| // ES6 draft 05-05-15, section 22.2.3.7
|
| function TypedArrayEvery(f, receiver) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.every");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -390,7 +390,7 @@
|
|
|
| // ES6 draft 08-24-14, section 22.2.3.12
|
| function TypedArrayForEach(f, receiver) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.forEach");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -401,7 +401,7 @@
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.9
|
| function TypedArrayFilter(f, thisArg) {
|
| - ValidateTypedArray(this, "%TypeArray%.prototype.filter");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| if (!IS_CALLABLE(f)) throw %make_type_error(kCalledNonCallable, f);
|
| @@ -419,7 +419,7 @@
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.10
|
| function TypedArrayFind(predicate, thisArg) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.find");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -430,7 +430,7 @@
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.11
|
| function TypedArrayFindIndex(predicate, thisArg) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.findIndex");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -441,7 +441,7 @@
|
|
|
| // ES6 draft 05-18-15, section 22.2.3.25
|
| function TypedArraySort(comparefn) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.sort");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -455,7 +455,7 @@
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.18
|
| function TypedArrayMap(f, thisArg) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.map");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| var result = TypedArraySpeciesCreate(this, length);
|
| @@ -482,7 +482,7 @@
|
|
|
| // ES6 draft 05-05-15, section 22.2.3.24
|
| function TypedArraySome(f, receiver) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.some");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -493,7 +493,7 @@
|
|
|
| // ES6 section 22.2.3.27
|
| function TypedArrayToLocaleString() {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.toLocaleString");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -503,7 +503,7 @@
|
|
|
| // ES6 section 22.2.3.14
|
| function TypedArrayJoin(separator) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.join");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
|
|
| @@ -538,7 +538,7 @@
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.19
|
| function TypedArrayReduce(callback, current) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.reduce");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| return InnerTypedArrayReduce(
|
| @@ -574,7 +574,7 @@
|
|
|
| // ES6 draft 07-15-13, section 22.2.3.19
|
| function TypedArrayReduceRight(callback, current) {
|
| - ValidateTypedArray(this, "%TypedArray%.prototype.reduceRight");
|
| + if (!IS_TYPEDARRAY(this)) throw %make_type_error(kNotTypedArray);
|
|
|
| var length = %_TypedArrayGetLength(this);
|
| return InnerArrayReduceRight(callback, current, this, length,
|
|
|