Index: src/harmony-typedarray.js |
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js |
index 2e8499573bc5930cc0e7cb69fdc1c62323c576c4..9850a1d4d0e0ed65fa226e75b8b96cb37707f0d5 100644 |
--- a/src/harmony-typedarray.js |
+++ b/src/harmony-typedarray.js |
@@ -30,6 +30,28 @@ DECLARE_GLOBALS(Array) |
// ------------------------------------------------------------------- |
+function ConstructTypedArray(constructor, array) { |
+ // TODO(littledan): This is an approximation of the spec, which requires |
+ // that only real TypedArray classes should be accepted (22.2.2.1.1) |
+ if (!%IsConstructor(constructor) || IS_UNDEFINED(constructor.prototype) || |
+ !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) { |
+ throw MakeTypeError(kNotTypedArray); |
+ } |
+ |
+ // TODO(littledan): The spec requires that, rather than directly calling |
+ // the constructor, a TypedArray is created with the proper proto and |
+ // underlying size and element size, and elements are put in one by one. |
+ // By contrast, this would allow subclasses to make a radically different |
+ // constructor with different semantics. |
+ return new constructor(array); |
+} |
+ |
+function ConstructTypedArrayLike(typedArray, arrayContents) { |
+ // TODO(littledan): The spec requires that we actuallly use |
+ // typedArray.constructor[Symbol.species] (bug v8:4093) |
+ return ConstructTypedArray(typedArray.constructor, arrayContents); |
+} |
+ |
function TypedArrayCopyWithin(target, start, end) { |
if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
@@ -61,7 +83,7 @@ function TypedArrayForEach(f, receiver) { |
%FunctionSetLength(TypedArrayForEach, 1); |
// ES6 draft 04-05-14 section 22.2.3.8 |
-function TypedArrayFill(value, start , end) { |
+function TypedArrayFill(value, start, end) { |
if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
var length = %_TypedArrayGetLength(this); |
@@ -70,6 +92,16 @@ function TypedArrayFill(value, start , end) { |
} |
%FunctionSetLength(TypedArrayFill, 1); |
+// ES6 draft 07-15-13, section 22.2.3.9 |
+function TypedArrayFilter(predicate, thisArg) { |
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
+ |
+ var length = %_TypedArrayGetLength(this); |
+ var array = $innerArrayFilter(predicate, thisArg, this, length); |
+ return ConstructTypedArrayLike(this, array); |
+} |
+%FunctionSetLength(TypedArrayFilter, 1); |
+ |
// ES6 draft 07-15-13, section 22.2.3.10 |
function TypedArrayFind(predicate, thisArg) { |
if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
@@ -157,6 +189,30 @@ function TypedArrayLastIndexOf(element, index) { |
%FunctionSetLength(TypedArrayLastIndexOf, 1); |
+// ES6 draft 07-15-13, section 22.2.3.18 |
+function TypedArrayMap(predicate, thisArg) { |
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
+ |
+ // TODO(littledan): Preallocate rather than making an intermediate |
+ // InternalArray, for better performance. |
+ var length = %_TypedArrayGetLength(this); |
+ var array = $innerArrayMap(predicate, thisArg, this, length); |
+ return ConstructTypedArrayLike(this, array); |
+} |
+%FunctionSetLength(TypedArrayMap, 1); |
+ |
+ |
+// ES6 draft 05-05-15, section 22.2.3.24 |
+function TypedArraySome(f, receiver) { |
+ if (!%IsTypedArray(this)) throw MakeTypeError(kNotTypedArray); |
+ |
+ var length = %_TypedArrayGetLength(this); |
+ |
+ return $innerArraySome(f, receiver, this, length); |
+} |
+%FunctionSetLength(TypedArraySome, 1); |
+ |
+ |
// ES6 draft 08-24-14, section 22.2.2.2 |
function TypedArrayOf() { |
var length = %_ArgumentsLength(); |
@@ -167,21 +223,6 @@ function TypedArrayOf() { |
return array; |
} |
-function ConstructTypedArray(constructor, array) { |
- // TODO(littledan): This is an approximation of the spec, which requires |
- // that only real TypedArray classes should be accepted (22.2.2.1.1) |
- if (!IS_SPEC_OBJECT(constructor) || IS_UNDEFINED(constructor.prototype) || |
- !%HasOwnProperty(constructor.prototype, "BYTES_PER_ELEMENT")) { |
- throw MakeTypeError(kNotTypedArray); |
- } |
- |
- // TODO(littledan): The spec requires that, rather than directly calling |
- // the constructor, a TypedArray is created with the proper proto and |
- // underlying size and element size, and elements are put in one by one. |
- // By contrast, this would allow subclasses to make a radically different |
- // constructor with different semantics. |
- return new constructor(array); |
-} |
function TypedArrayFrom(source, mapfn, thisArg) { |
// TODO(littledan): Investigate if there is a receiver which could be |
@@ -203,13 +244,16 @@ macro EXTEND_TYPED_ARRAY(NAME) |
$installFunctions(GlobalNAME.prototype, DONT_ENUM, [ |
"copyWithin", TypedArrayCopyWithin, |
"every", TypedArrayEvery, |
- "forEach", TypedArrayForEach, |
+ "fill", TypedArrayFill, |
+ "filter", TypedArrayFilter, |
"find", TypedArrayFind, |
"findIndex", TypedArrayFindIndex, |
- "fill", TypedArrayFill, |
"indexOf", TypedArrayIndexOf, |
"lastIndexOf", TypedArrayLastIndexOf, |
+ "forEach", TypedArrayForEach, |
+ "map", TypedArrayMap, |
"reverse", TypedArrayReverse, |
+ "some", TypedArraySome, |
"sort", TypedArraySort |
]); |
endmacro |