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

Unified Diff: src/array.js

Issue 1238593003: Array.prototype.reverse should call [[HasProperty]] on elements before [[Get]] (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Changes from code review Created 5 years, 5 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 7baabf83610c3c333eb13b9a5463c652ccaa3839..e0cc0695cc600462546ab55f813f3e3b3a2c87f3 100644
--- a/src/array.js
+++ b/src/array.js
@@ -587,14 +587,25 @@ function SparseReverse(array, len) {
}
}
-
-function InnerArrayReverse(array, len) {
+function PackedArrayReverse(array, len) {
var j = len - 1;
for (var i = 0; i < j; i++, j--) {
var current_i = array[i];
- if (!IS_UNDEFINED(current_i) || i in array) {
- var current_j = array[j];
- if (!IS_UNDEFINED(current_j) || j in array) {
+ var current_j = array[j];
+ array[i] = current_j;
+ array[j] = current_i;
+ }
+ return array;
+}
+
+
+function GenericArrayReverse(array, len) {
+ var j = len - 1;
+ for (var i = 0; i < j; i++, j--) {
+ if (i in array) {
+ var current_i = array[i];
+ if (j in array) {
+ var current_j = array[j];
array[i] = current_j;
array[j] = current_i;
} else {
@@ -602,8 +613,8 @@ function InnerArrayReverse(array, len) {
delete array[i];
}
} else {
- var current_j = array[j];
- if (!IS_UNDEFINED(current_j) || j in array) {
+ if (j in array) {
+ var current_j = array[j];
array[i] = current_j;
delete array[j];
}
@@ -618,14 +629,17 @@ function ArrayReverse() {
var array = TO_OBJECT_INLINE(this);
var len = TO_UINT32(array.length);
+ var isArray = IS_ARRAY(array);
- if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
+ if (UseSparseVariant(array, len, isArray, len)) {
%NormalizeElements(array);
SparseReverse(array, len);
return array;
+ } else if (isArray && %_HasFastPackedElements(array)) {
+ return PackedArrayReverse(array, len);
+ } else {
+ return GenericArrayReverse(array, len);
}
-
- return InnerArrayReverse(array, len);
}
@@ -1688,10 +1702,10 @@ utils.Export(function(to) {
to.InnerArrayMap = InnerArrayMap;
to.InnerArrayReduce = InnerArrayReduce;
to.InnerArrayReduceRight = InnerArrayReduceRight;
- to.InnerArrayReverse = InnerArrayReverse;
to.InnerArraySome = InnerArraySome;
to.InnerArraySort = InnerArraySort;
to.InnerArrayToLocaleString = InnerArrayToLocaleString;
+ to.PackedArrayReverse = PackedArrayReverse;
});
$arrayConcat = ArrayConcatJS;
« 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