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

Unified Diff: src/js/typedarray.js

Issue 1560763002: Add Array support for @@species and subclassing (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Some fixes Created 4 years, 11 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
Index: src/js/typedarray.js
diff --git a/src/js/typedarray.js b/src/js/typedarray.js
index ef978c9cd9d60edf777093420b8b46c7ce5d92c9..cbd9b5ace077c87a8dffac0a23d2ee040b2570fc 100644
--- a/src/js/typedarray.js
+++ b/src/js/typedarray.js
@@ -493,12 +493,19 @@ function TypedArrayFill(value, start, end) {
// ES6 draft 07-15-13, section 22.2.3.9
-function TypedArrayFilter(predicate, thisArg) {
+function TypedArrayFilter(f, thisArg) {
if (!%_IsTypedArray(this)) throw MakeTypeError(kNotTypedArray);
var length = %_TypedArrayGetLength(this);
- var array = InnerArrayFilter(predicate, thisArg, this, length);
- return ConstructTypedArrayLike(this, array);
+ if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
+ var result = new InternalArray();
+ InnerArrayFilter(f, thisArg, this, length, result);
+ var captured = result.length;
+ var output = ConstructTypedArrayLike(this, captured);
+ for (var n = 0; n < captured; n++) {
adamk 2016/01/06 00:10:12 Can you use 'i' instead of 'n' for the name here?
Dan Ehrenberg 2016/01/07 00:42:57 Done
+ output[n] = result[n];
adamk 2016/01/06 00:10:12 Nit: indentation (need another space)
Dan Ehrenberg 2016/01/07 00:42:57 Done
+ }
+ return output;
}
%FunctionSetLength(TypedArrayFilter, 1);
@@ -592,14 +599,17 @@ function TypedArrayLastIndexOf(element, index) {
// ES6 draft 07-15-13, section 22.2.3.18
-function TypedArrayMap(predicate, thisArg) {
+function TypedArrayMap(f, 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);
+ var result = ConstructTypedArrayLike(this, length);
+ if (!IS_CALLABLE(f)) throw MakeTypeError(kCalledNonCallable, f);
+ for (var i = 0; i < length; i++) {
+ var element = this[i];
+ result[i] = %_Call(f, thisArg, element, i, this);
+ }
+ return result;
}
%FunctionSetLength(TypedArrayMap, 1);

Powered by Google App Engine
This is Rietveld 408576698