Index: src/typedarray.js |
diff --git a/src/typedarray.js b/src/typedarray.js |
index 96d968fe814dc70853766e2408f4bbb98c0fa5c5..d1192ede7eeb8f1993f49f0570d50e491a1502e3 100644 |
--- a/src/typedarray.js |
+++ b/src/typedarray.js |
@@ -123,12 +123,27 @@ function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) { |
%TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); |
} |
+ function TryConstructByArrayLike(obj, arrayLike) { |
rossberg
2013/05/02 11:52:20
Nit: why is this called TryConstruct?
|
+ var length = arrayLike.length; |
+ var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length); |
+ var byteLength = l * elementSize; |
+ var buffer = new $ArrayBuffer(byteLength); |
+ %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength); |
+ for (var i = 0; i < l; i++) { |
+ obj[i] = arrayLike[i]; |
+ } |
+ } |
+ |
return function (arg1, arg2, arg3) { |
if (%_IsConstructCall()) { |
if (IS_ARRAYBUFFER(arg1)) { |
ConstructByArrayBuffer(this, arg1, arg2, arg3); |
- } else { |
+ } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || IS_BOOLEAN(arg1)) { |
ConstructByLength(this, arg1); |
+ } else if (!IS_UNDEFINED(arg1)){ |
+ TryConstructByArrayLike(this, arg1); |
+ } else { |
+ throw MakeTypeError("parameterless_typed_array_constr", name); |
} |
} else { |
return new constructor(arg1, arg2, arg3); |