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

Unified Diff: src/harmony-typedarray.js

Issue 699953003: Implement .fill() on typed arrays Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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/typedarrays-fill.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/harmony-typedarray.js
diff --git a/src/harmony-typedarray.js b/src/harmony-typedarray.js
index 0129f38d507cd0f8d0483a5ba3bbed8a04a2d773..b6b93b4d64543df1aefce2c9b81f4256e9d68b6c 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -58,6 +58,45 @@ function NAMEForEach(f /* thisArg */) { // length == 1
%_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f);
}
}
+
+
+// ES6 draft 10-14-2014, section 22.1.3.6
+function NAMEFill(value /* [, start [, end ] ] */) { // length == 1
+ CHECK_OBJECT_COERCIBLE(this, "NAME.prototype.fill");
+
+ var array = ToObject(this);
wingo 2014/11/12 09:29:56 Need a check that the object is indeed a typed arr
aperez 2014/11/13 16:34:36 well, CHECK_OBJECT_COERCIBLE() just checks that th
wingo 2014/11/14 14:27:50 Please see http://people.mozilla.org/~jorendorff/e
+ var length = ToLength(array.length);
wingo 2014/11/12 09:29:56 Need to get the array's "length" internal slot, no
aperez 2014/11/13 16:34:36 The spec, in step 3 reads: 3. Let lenVal be Get
+
+ var i = 0;
+ var end = length;
+
+ if (%_ArgumentsLength() > 1) {
+ i = %_Arguments(1);
+ i = IS_UNDEFINED(i) ? 0 : TO_INTEGER(i);
wingo 2014/11/12 09:29:56 I think that here we need i = TO_INTEGER(i) in all
aperez 2014/11/13 16:34:36 Well, according to the spec, the first step of ToI
+ if (%_ArgumentsLength() > 2) {
+ end = %_Arguments(2);
+ end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
wingo 2014/11/12 09:29:56 Very strangely, this logic is correct for "end" bu
aperez 2014/11/13 16:34:36 For the case of end==undefined we want to take the
+ }
+ }
+
+ 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;
+ }
+
+ for (; i < end; i++)
+ array[i] = value;
+ return array;
+}
endmacro
TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
@@ -69,7 +108,8 @@ macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
// Set up non-enumerable functions on the prototype object.
InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
wingo 2014/11/12 09:29:56 Both of these should be DONT_WRITE and DONT_DELETE
aperez 2014/11/13 16:34:36 Acknowledged.
- "forEach", NAMEForEach
+ "forEach", NAMEForEach,
+ "fill", NAMEFill
));
endmacro
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-fill.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698