Chromium Code Reviews| Index: src/typedarray.js |
| diff --git a/src/typedarray.js b/src/typedarray.js |
| index 65659147ee7777cf1e8bc69196d4fc09a4beee89..ad0d297b5792ffd7be168fcb9e74beb561b8f8a2 100644 |
| --- a/src/typedarray.js |
| +++ b/src/typedarray.js |
| @@ -43,6 +43,8 @@ utils.Import(function(from) { |
| MathMin = from.MathMin; |
| }); |
| +var InternalArray = utils.InternalArray; |
| + |
| // --------------- Typed Arrays --------------------- |
| macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
| @@ -130,6 +132,20 @@ function NAMEConstructByArrayLike(obj, arrayLike) { |
| } |
| } |
| +function NAMEConstructByIterable(obj, iterable, iteratorFn) { |
| + var list = new InternalArray(); |
| + var iterator = %_CallFunction(iterable, iteratorFn); |
| + while (true) { |
| + var current = iterator.next(); |
| + if (!IS_OBJECT(current)) { |
|
adamk
2015/06/12 18:06:45
I think you want IS_SPEC_OBJECT here.
The proper
Dan Ehrenberg
2015/06/13 00:11:40
How's this, just using for-of with a wrapper? We c
|
| + throw MakeTypeError(kIteratorResultNotAnObject, current); |
| + } |
| + if (current.done) break; |
| + list.push(current.value); |
| + } |
| + NAMEConstructByArrayLike(obj, list); |
| +} |
| + |
| function NAMEConstructor(arg1, arg2, arg3) { |
| if (%_IsConstructCall()) { |
| if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) { |
| @@ -138,7 +154,14 @@ function NAMEConstructor(arg1, arg2, arg3) { |
| IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) { |
| NAMEConstructByLength(this, arg1); |
| } else { |
| - NAMEConstructByArrayLike(this, arg1); |
| + var iteratorFn = arg1[symbolIterator]; |
| + 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. |
| + NAMEConstructByIterable(this, arg1, iteratorFn); |
| + } |
| } |
| } else { |
| throw MakeTypeError(kConstructorNotFunction, "NAME") |