Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Unified Diff: src/harmony-typedarray.js

Issue 1145013002: Re-land %TypedArray%.prototype.{map,filter,some} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/array.js ('k') | test/mjsunit/harmony/typedarray-iteration.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 2e8499573bc5930cc0e7cb69fdc1c62323c576c4..dd3efe38625f7855631b61f74c07463c21feaed6 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -30,6 +30,28 @@ DECLARE_GLOBALS(Array)
// -------------------------------------------------------------------
+function ConstructTypedArray(constructor, array) {
adamk 2015/05/20 18:50:07 Where is this called?
arv (Not doing code reviews) 2015/05/20 19:22:31 Also, this function is defined twice... was there
dehrenberg 2015/05/20 23:39:01 Yes. OK, I learned my lesson, not to do git confli
+ // 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) ||
adamk 2015/05/20 18:50:07 Can you use %IsConstructor here? These checks look
dehrenberg 2015/05/20 23:39:01 The check is supposed to be an approximation of ch
+ !%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 new 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);
@@ -154,7 +186,30 @@ function TypedArrayLastIndexOf(element, index) {
return %_CallFunction(this, element, index, length,
%_ArgumentsLength(), $innerArrayLastIndexOf);
}
-%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
+ // array, 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
@@ -203,13 +258,17 @@ 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,
adamk 2015/05/20 18:50:07 This is a dup of the sorted line above.
dehrenberg 2015/05/20 23:39:01 Done.
"indexOf", TypedArrayIndexOf,
"lastIndexOf", TypedArrayLastIndexOf,
+ "forEach", TypedArrayForEach,
+ "map", TypedArrayMap,
"reverse", TypedArrayReverse,
+ "some", TypedArraySome
"sort", TypedArraySort
]);
endmacro
« no previous file with comments | « src/array.js ('k') | test/mjsunit/harmony/typedarray-iteration.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698