-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Implementation of for...of loops #704
Conversation
Codecov Report
@@ Coverage Diff @@
## master #704 +/- ##
==========================================
+ Coverage 58.51% 59.28% +0.77%
==========================================
Files 152 156 +4
Lines 9476 9820 +344
==========================================
+ Hits 5545 5822 +277
- Misses 3931 3998 +67
Continue to review full report at Codecov.
|
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.
This looks good! I just skimmed through the code I'll do a proper review later :)
# Conflicts: # boa/src/builtins/array/array_iterator.rs # boa/src/builtins/array/mod.rs # boa/src/context.rs # boa/src/exec/iteration/mod.rs
This now works on most types of for...of loop. The one thing I'm unsure of is changing the behaviour of const declarations, as it feels a bit less neat, but I couldn't think of a different way to do it while still having the lhs of the for...of loop be parsed in the same way as an ordinary for loop. |
…out into their own file to allow for repeated use.
# Conflicts: # boa/src/builtins/array/array_iterator.rs # boa/src/builtins/array/mod.rs # boa/src/exec/iteration/mod.rs
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.
This is almost ready to merge :)
Great! In terms of implementing iterators for objects, there is still map to do. Should I implement this now (shouldn't take too long) or just leave it. Also, what should I do about the array index in the array iterator? |
# Conflicts: # boa/src/exec/declaration/mod.rs # boa/src/exec/iteration/mod.rs # boa/src/exec/mod.rs # boa/src/syntax/ast/node/declaration.rs # boa/src/syntax/ast/node/iteration.rs
Sure. if you want we can implement it in this :)
I think changing it to u32 is the best option, the array index can only be Edit: On second thought maybe we should merge this, and work on |
Currently the only issue with that is that it sometimes has to be placed back into a value. Should that be done as the Number type rather than Integer then? |
If value can fit in an Value::Integer(i32) it will be placed but if not it will be converted to |
This Pull Request fixes/closes #576.
It changes the following:
values()
function to arrays.Symbol.iterator
parameter to array pointing to thevalues()
function. Also adds theget_well_known_symbol()
function toContext
.Currently for...of only works if the iterating variable is declared before the loop and is referenced without another declaration. e.g.
I'm unsure of the approach to take for implementing the rest of the loop. The main problem is that the initial part of a for statement (
for (...
) is treated differently depending on whether it is an ordinary for loop or a for...of/in loop. My current idea is to loop through each token until either a semicolon or in/of is found, collecting the tokens into a vec and using that as a cursor to parse the initial element depending on what was found. This does seem a bit hacky though, so I'd be open to other ideas.A slightly more minor note is that I'm unsure of whether my implementation for
get_well_known_symbol
is correct as there seems to be a lot of indirection required to get the symbol object.