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

Unified Diff: src/typedarray.js

Issue 1181903003: Allow TypedArrays to be initialized with iterables (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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")
« no previous file with comments | « no previous file | test/mjsunit/harmony/typedarrays.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698