-
Notifications
You must be signed in to change notification settings - Fork 684
Implement Iterator interface and Array iterators #2640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
647241a
to
ad426b2
Compare
da66b1c
to
9b1a982
Compare
9b1a982
to
792b3c7
Compare
Please add a test to |
792b3c7
to
00591fb
Compare
00591fb
to
e203f94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after minor fix.
e203f94
to
d7e48c0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.c
Outdated
Show resolved
Hide resolved
jerry-core/ecma/builtin-objects/ecma-builtin-array-iterator-prototype.c
Outdated
Show resolved
Hide resolved
jerry-core/ecma/builtin-objects/ecma-builtin-iterator-prototype.c
Outdated
Show resolved
Hide resolved
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
d7e48c0
to
e86fc09
Compare
@LaszloLango Thanks for the review, I've updated the PR according to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ecma_object_t *array_object_p = ECMA_GET_POINTER (ecma_object_t, | ||
ext_obj_p->u.pseudo_array.u2.iterated_value_cp); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is two newlines there. One is enough.
uint32_t length; | ||
|
||
/* 8 - 9. */ | ||
#ifndef CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if this length query construct is used elsewhere (did not find any proof for it yet). IMHO this would make a good helper function which can return the length of an array/typedarray, but maybe in the future.
|
||
ecma_extended_object_t *ext_array_obj_p = (ecma_extended_object_t *) array_object_p; | ||
|
||
length = ext_array_obj_p->u.array.length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For an ordinary array shouldn't we access the length
property? Like what would happen if there is an array created like this:
var arr = [];
arr.length = 30;
And then doing iteration on this new array.
else | ||
{ | ||
#endif /* !CONFIG_DISABLE_ES2015_TYPEDARRAY_BUILTIN */ | ||
JERRY_ASSERT (ecma_get_object_type (array_object_p) == ECMA_OBJECT_TYPE_ARRAY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if we are iterating over a function's arguments
array? AFAIK that has a different type.
} | ||
|
||
ecma_object_t *obj_p = ecma_get_object_from_value (this_val); | ||
ecma_extended_object_t *ext_obj_p = (ecma_extended_object_t *) obj_p; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this conversion object->extended_object
allowed here? Shouldn't there be a check if it is an extended object at all?
* The %IteratorPrototype% object's '@@iterator' routine | ||
* | ||
* See also: | ||
* ECMA-262 v6, 22.1.2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the Ecma docs the 22.1.2.1
is for Array.from ( items [ , mapfn [ , thisArg ] ] )
. Is this See also
entry ok? The reference 25.1.2.1 %IteratorPrototype% [ @@iterator ] ( )
would be better IMHO.
@@ -75,6 +76,7 @@ LIT_MAGIC_STRING_JOIN = "join" | |||
LIT_MAGIC_STRING_KEYS = "keys" | |||
LIT_MAGIC_STRING_NAME = "name" | |||
LIT_MAGIC_STRING_NULL = "null" | |||
LIT_MAGIC_STRING_NEXT = "next" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the entry next
be before the null
?
array = [0, 1, 2, 3, 4, 5]; | ||
iterator = array.entries (); | ||
|
||
for (var i = 0; i < array.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So... this means that if an element is removed from the array the iterator also loses that element, and after the loop the iterator.next().done
call will be true
?
Related part of the standard: https://www.ecma-international.org/ecma-262/6.0/#sec-array-iterator-objects
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]