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

Unified Diff: src/harmony-array.js

Issue 1072193005: Revert of Revert of [es6] implement Array.prototype.copyWithin() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 5 years, 8 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 | test/mjsunit/harmony/array-copywithin.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-array.js
diff --git a/src/harmony-array.js b/src/harmony-array.js
index 18cda170549b5a21b039c5ff2aa9b024ca281272..934d3b77c7f0bb299daeea28c60aa26c4adb4e4a 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -12,6 +12,59 @@
var GlobalSymbol = global.Symbol;
// -------------------------------------------------------------------
+
+// ES6 draft 03-17-15, section 22.1.3.3
+function ArrayCopyWithin(target, start, end) {
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin");
+
+ var array = TO_OBJECT_INLINE(this);
+ var length = ToLength(array.length);
+
+ target = TO_INTEGER(target);
+ var to;
+ if (target < 0) {
+ to = $max(length + target, 0);
+ } else {
+ to = $min(target, length);
+ }
+
+ start = TO_INTEGER(start);
+ var from;
+ if (start < 0) {
+ from = $max(length + start, 0);
+ } else {
+ from = $min(start, length);
+ }
+
+ end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
+ var final;
+ if (end < 0) {
+ final = $max(length + end, 0);
+ } else {
+ final = $min(end, length);
+ }
+
+ var count = $min(final - from, length - to);
+ var direction = 1;
+ if (from < to && to < (from + count)) {
+ direction = -1;
+ from = from + count - 1;
+ to = to + count - 1;
+ }
+
+ while (count > 0) {
+ if (from in array) {
+ array[to] = array[from];
+ } else {
+ delete array[to];
+ }
+ from = from + direction;
+ to = to + direction;
+ count--;
+ }
+
+ return array;
+}
// ES6 draft 07-15-13, section 15.4.3.23
function ArrayFind(predicate /* thisArg */) { // length == 1
@@ -216,6 +269,7 @@
"isConcatSpreadable", symbolIsConcatSpreadable
]);
+%FunctionSetLength(ArrayCopyWithin, 2);
%FunctionSetLength(ArrayFrom, 1);
// Set up non-enumerable functions on the Array object.
@@ -226,6 +280,7 @@
// Set up the non-enumerable functions on the Array prototype object.
InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
+ "copyWithin", ArrayCopyWithin,
"find", ArrayFind,
"findIndex", ArrayFindIndex,
"fill", ArrayFill
« no previous file with comments | « no previous file | test/mjsunit/harmony/array-copywithin.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698