Chromium Code Reviews| Index: src/typedarray.js |
| diff --git a/src/typedarray.js b/src/typedarray.js |
| index 65659147ee7777cf1e8bc69196d4fc09a4beee89..2f9d052fce771131e66f96853c03b7f9307cc1b2 100644 |
| --- a/src/typedarray.js |
| +++ b/src/typedarray.js |
| @@ -130,6 +130,14 @@ function NAMEConstructByArrayLike(obj, arrayLike) { |
| } |
| } |
| +function NAMEConstructByIterable(obj, iterable) { |
| + var list = new InternalArray(); |
| + for (var element of iterable) { |
| + list.push(element); |
| + } |
| + return NAMEConstructByArrayLike(obj, list); |
| +} |
| + |
| function NAMEConstructor(arg1, arg2, arg3) { |
| if (%_IsConstructCall()) { |
| if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
| @@ -138,7 +146,14 @@ function NAMEConstructor(arg1, arg2, arg3) { |
| IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| NAMEConstructByLength(this, arg1); |
| } else { |
| - NAMEConstructByArrayLike(this, arg1); |
| + var iteratorFn = arg1[Symbol.iterator]; |
| + if (IS_UNDEFINED(iteratorFn) || iteratorFn === $arrayValues) { |
| + NAMEConstructByArrayLike(this, arg1); |
| + } else { |
| + // TODO(littledan): The code here is lazy and looks up @@iterator |
| + // twice. Currently, that's fine, but it'll be observable with proxies. |
|
adamk
2015/06/12 00:57:08
Proxies aren't required, a getter for @@iterator i
caitp (gmail)
2015/06/12 01:11:33
I think the only way to really fix that currently
Dan Ehrenberg
2015/06/12 02:42:22
Well, you can use for-of on most of the builtin it
|
| + NAMEConstructByIterable(this, arg1); |
| + } |
| } |
| } else { |
| throw MakeTypeError(kConstructorNotFunction, "NAME") |