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

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: Make .fill() work only on typed arrays, use internal slot for length 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..34cbeb305f01d542346021958bcc3b03e4e1ca39 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -58,6 +58,46 @@ 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
+ if (!%IsTypedArray(this)) {
+ throw MakeTypeError('not_typed_array', []);
+ }
+
+ var length = %_TypedArrayGetLength(this);
+
+ var i = 0;
+ var end = length;
+
+ if (%_ArgumentsLength() > 1) {
+ i = %_Arguments(1);
+ i = 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;
+ }
+
+ for (; i < end; i++)
+ this[i] = value;
+ return this;
+}
endmacro
TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
@@ -68,9 +108,12 @@ macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
%CheckIsBootstrapping();
// Set up non-enumerable functions on the prototype object.
- InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
- "forEach", NAMEForEach
- ));
+ InstallFunctions(global.NAME.prototype, DONT_ENUM | DONT_DELETE | READ_ONLY,
+ $Array(
+ "forEach", NAMEForEach,
+ "fill", NAMEFill
+ )
+ );
endmacro
TYPED_ARRAYS(EXTEND_TYPED_ARRAY)
« 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