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

Unified Diff: src/array.js

Issue 1133503003: Factor out core of Array.forEach and .every, for use in TypedArrays (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase 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 | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/array.js
diff --git a/src/array.js b/src/array.js
index dc0b65fc1d0c2d91898322bfde92f9c58e60fbe5..3f9bd68bbf483bd0c8b42472905ebf9237af13e5 100644
--- a/src/array.js
+++ b/src/array.js
@@ -10,6 +10,8 @@ var $arrayShift;
var $arraySlice;
var $arraySplice;
var $arrayUnshift;
+var $innerArrayForEach;
+var $innerArrayEvery;
(function(global, shared, exports) {
@@ -1179,15 +1181,7 @@ function ArrayFilter(f, receiver) {
return result;
}
-
-function ArrayForEach(f, receiver) {
- CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
-
- // Pull out the length so that modifications to the length in the
- // loop will not affect the looping and side effects are visible.
- var array = $toObject(this);
- var length = TO_UINT32(array.length);
-
+function InnerArrayForEach(f, receiver, array, length) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL(receiver)) {
@@ -1209,6 +1203,16 @@ function ArrayForEach(f, receiver) {
}
}
+function ArrayForEach(f, receiver) {
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.forEach");
+
+ // Pull out the length so that modifications to the length in the
+ // loop will not affect the looping and side effects are visible.
+ var array = $toObject(this);
+ var length = TO_UINT32(array.length);
+ InnerArrayForEach(f, receiver, array, length);
+}
+
// Executes the function once for each element present in the
// array until it finds one where callback returns true.
@@ -1243,14 +1247,7 @@ function ArraySome(f, receiver) {
}
-function ArrayEvery(f, receiver) {
- CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
-
- // Pull out the length so that modifications to the length in the
- // loop will not affect the looping and side effects are visible.
- var array = $toObject(this);
- var length = TO_UINT32(array.length);
-
+function InnerArrayEvery(f, receiver, array, length) {
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL(receiver)) {
@@ -1273,6 +1270,16 @@ function ArrayEvery(f, receiver) {
return true;
}
+function ArrayEvery(f, receiver) {
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.every");
+
+ // Pull out the length so that modifications to the length in the
+ // loop will not affect the looping and side effects are visible.
+ var array = $toObject(this);
+ var length = TO_UINT32(array.length);
+ return InnerArrayEvery(f, receiver, array, length);
+}
+
function ArrayMap(f, receiver) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.map");
@@ -1595,4 +1602,7 @@ $arraySlice = ArraySlice;
$arraySplice = ArraySplice;
$arrayUnshift = ArrayUnshift;
-})
+$innerArrayForEach = InnerArrayForEach;
+$innerArrayEvery = InnerArrayEvery;
+
+});
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698