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

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: using HAS_INDEX even with typedarray, simplifying things 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') | src/harmony-typedarray.js » ('J')
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 bf24d16d11bd7da9fe48cade405f590c96c66243..d683f0b9bfa37dd2a0ffe9678008404f0d1537b8 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() {
@@ -1179,15 +1181,8 @@ 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)
+{
adamk 2015/05/11 22:39:24 I'll re-iterate arv's style nit, please put this o
if (!IS_SPEC_FUNCTION(f)) throw MakeTypeError(kCalledNonCallable, f);
var needs_wrapper = false;
if (IS_NULL(receiver)) {
@@ -1209,6 +1204,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 +1248,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 +1271,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 +1603,7 @@ $arraySlice = ArraySlice;
$arraySplice = ArraySplice;
$arrayUnshift = ArrayUnshift;
+$innerArrayForEach = InnerArrayForEach;
+$innerArrayEvery = InnerArrayEvery;
+
})();
« no previous file with comments | « no previous file | src/harmony-typedarray.js » ('j') | src/harmony-typedarray.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698