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

Unified Diff: src/harmony-array.js

Issue 240873002: ES6: Add support for Array.prototype.fill() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added additional test cases as suggested Created 6 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-fill.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 261e2aeeb02460464bbf8fa67d7a124d39874c9e..dbcb292a0876842e8d3a6d4c0d21d997cdf6d977 100644
--- a/src/harmony-array.js
+++ b/src/harmony-array.js
@@ -80,6 +80,49 @@ function ArrayFindIndex(predicate /* thisArg */) { // length == 1
}
+// ES6, draft 04-05-14, section 22.1.3.6
+function ArrayFill(value /* [, start [, end ] ] */) { // length == 1
+ CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill");
+
+ var array = ToObject(this);
+ var length = TO_UINT32(array.length);
+
+ var i = 0;
+ var end = length;
+
+ if (%_ArgumentsLength() > 1) {
+ i = %_Arguments(1);
+ i = IS_UNDEFINED(i) ? 0 : TO_INTEGER(i);
+ if (%_ArgumentsLength() > 2) {
+ end = %_Arguments(2);
+ end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
+ }
+ }
+
+ if (i < 0) {
+ i += length;
+ if (i < 0) i = 0;
+ } else {
+ if (i > length) i = length;
+ }
+
+ if (end < 0) {
+ end += length;
+ if (end < 0) end = 0;
+ } else {
+ if (end > length) end = length;
+ }
+
+ if ((end - i) > 0 && ObjectIsFrozen(array)) {
+ throw MakeTypeError("array_functions_on_frozen",
+ ["Array.prototype.fill"]);
+ }
+
+ for (; i < end; i++)
+ array[i] = value;
+ return array;
+}
+
// -------------------------------------------------------------------
function HarmonyArrayExtendArrayPrototype() {
@@ -88,7 +131,8 @@ function HarmonyArrayExtendArrayPrototype() {
// Set up the non-enumerable functions on the Array prototype object.
InstallFunctions($Array.prototype, DONT_ENUM, $Array(
"find", ArrayFind,
- "findIndex", ArrayFindIndex
+ "findIndex", ArrayFindIndex,
+ "fill", ArrayFill
));
}
« no previous file with comments | « no previous file | test/mjsunit/harmony/array-fill.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698