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

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: null proto for iterator 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..15b8438004245eab59c60d03c78da719da09b9a4 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,17 @@ function NAMEConstructByArrayLike(obj, arrayLike) {
}
}
+function NAMEConstructByIterable(obj, iterable, iteratorFn) {
+ var list = new InternalArray();
+ var iterator = %_CallFunction(iterable, iteratorFn);
+ var newIterable = {__proto__: null};
arv (Not doing code reviews) 2015/06/15 15:53:18 var newIterable = { __proto__: null, [symbolIt
arv (Not doing code reviews) 2015/06/15 15:53:19 This hack/workaround needs a comment.
Dan Ehrenberg 2015/06/15 18:14:19 Done.
Dan Ehrenberg 2015/06/15 18:14:20 Done.
+ newIterable[symbolIterator] = function() { return iterator; };
+ for (var value of newIterable) {
arv (Not doing code reviews) 2015/06/15 15:53:19 var list = [...newIterable]; would work if we wer
Dan Ehrenberg 2015/06/15 18:14:20 Would it? I thought it was important to use an Int
+ list.push(value);
+ }
+ NAMEConstructByArrayLike(obj, list);
+}
+
function NAMEConstructor(arg1, arg2, arg3) {
if (%_IsConstructCall()) {
if (IS_ARRAYBUFFER(arg1) || IS_SHAREDARRAYBUFFER(arg1)) {
@@ -138,7 +151,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.
arv (Not doing code reviews) 2015/06/15 15:53:18 This comment is out of date now
Dan Ehrenberg 2015/06/15 18:14:20 Deleted.
+ NAMEConstructByIterable(this, arg1, iteratorFn);
+ }
}
} 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