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

Unified Diff: src/harmony-typedarray.js

Issue 660863003: Implement .of() on typed arrays (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 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/typedarrays-of.js » ('j') | test/mjsunit/harmony/typedarrays-of.js » ('J')
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..488ce082d42a6efeefe06a90e91052f2c32e3a3d 100644
--- a/src/harmony-typedarray.js
+++ b/src/harmony-typedarray.js
@@ -58,6 +58,29 @@ function NAMEForEach(f /* thisArg */) { // length == 1
%_CallFunction(new_receiver, TO_OBJECT_INLINE(element), i, this, f);
}
}
+
+// ES6 draft 08-24-14, section 22.2.2.2
+function NAMEOf() { // length == 0
+ var length = %_ArgumentsLength();
+ // TODO: Implement IsConstructor (ES6 section 7.2.5)
+ if (!IS_SPEC_FUNCTION(this)) {
wingo 2014/10/21 15:23:13 what does this case check? wouldn't this be caugh
+ throw MakeTypeError('incompatible_method_receiver',
+ ['NAME.of', this]);
+ }
+
+ var array = new this(length);
+ for (var i = 0; i < length; i++) {
+ array[i] = %_Arguments(i);
+ }
+ // Typed arrays update the "length" property themselves. If the "of"
+ // method has been transplanted to some other constructor, the
+ // length has to be set (which may optionally trigger a setter).
+ if (!%IsTypedArray(array)) {
wingo 2014/10/21 15:23:12 This isn't in the spec.
+ array.length = length;
+ }
+ return array;
+}
+
endmacro
TYPED_ARRAYS(TYPED_ARRAY_HARMONY_ADDITIONS)
@@ -67,6 +90,11 @@ function HarmonyTypedArrayExtendPrototypes() {
macro EXTEND_TYPED_ARRAY(ARRAY_ID, NAME, ELEMENT_SIZE)
%CheckIsBootstrapping();
+ // Set up non-enumerable functions on the object.
+ InstallFunctions(global.NAME, DONT_ENUM, $Array(
+ "of", NAMEOf
wingo 2014/10/21 15:23:12 This outer function name is a bit misleading -- we
+ ));
+
// Set up non-enumerable functions on the prototype object.
InstallFunctions(global.NAME.prototype, DONT_ENUM, $Array(
"forEach", NAMEForEach
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays-of.js » ('j') | test/mjsunit/harmony/typedarrays-of.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698