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 |