-
Notifications
You must be signed in to change notification settings - Fork 596
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
For loop bugfix - explore enabling break and continue within for loops #216
Comments
Made a commit in for_loop_break_continue branch - 8700c0c samples/loop_demo can't work. in generated loop_demo.js, when for_loop_signal is set, the moment after // end of JS code line if put casper.then(function() { // start of JS code
for_loop_signal = '[BREAK_SIGNAL]'; return;
}); // end of JS code problem is variables set with casper.then() blocks remains in casper context. ie the moment exit IIFE pattern, for_loop_signal variable remains blanks and the code to break or continue does not trigger. })(n); // end of IIFE pattern
if (for_loop_signal == '[BREAK_SIGNAL]') {for_loop_signal = ''; break;}
else if (for_loop_signal == '[CONTINUE_SIGNAL]') {for_loop_signal = ''; continue;}}
}); We can look into this together next week... |
Experimental implementation using file IO doesn't work as well - 6cbf1f5 |
use casper.bypass() to count how many steps to teleport to and bypass when a break statement is issued. nice catch @Aussiroth ! Co-Authored-By: Alvin Yan <[email protected]> Co-Authored-By: Victor Loh <[email protected]>
TagUI script to test this issue here:
Expected output:1 Actual output:1 Issue with nested loop is likely due to finding the outermost for loop break signal and jumping to it, instead of the one for the inner for loop. |
above commit gives following output. uses a teleport marker (variable of the loop) to track which loop to break. however, still not showing
|
above commit adds stricter conditions to give correct output. turns out the stack also contains the terminating marker, thus the outer loop for the n for loop will have the market for k for loop and results in false-positive match. below stricter condition to check for real match - if (casper.steps[s].toString() == ("function () {for_loop_signal = '[BREAK_SIGNAL]["+teleport_marker+"]';}"))
|
looks ok for repeated use of for loop variables. would have thought will have issues as the markers are similar, but below works, haven't figure out why.
|
Adding on, it works because the later steps in stack are not created yet, so later blocks of for loops with similar variable names wont trigger false-positive if a search is done from the back. |
I'll clean up the code and add continue so that you guys can stress test... continue's implementation is probably adding a marker near the start of the loop and searching from forward direction instead of from the back. reference debugging code that can be used in the last casper.then block in generated js for (s = casper.steps.length-1; s >= 0; s--) {
casper.echo('\n\n\n\n\n' + s + ' ------------------------------------------------------------\n' + casper.steps[s].toString());} |
doesn't work but don't break existing break test case.
Getting very close to final working version that works for continue or break step. for your stress / edge-cases testing.. to use, use continue or continue; or break or break; in a for loop |
eg for n from 1 to infinity { echo n } if constant too big, takes very large to build stack before execution. trade-off decided to be 1024
Co-Authored-By: Alvin Yan <[email protected]> Co-Authored-By: Victor Loh <[email protected]> * #216 - experimenting with using signal variable * #216 - possible solution found use casper.bypass() to count how many steps to teleport to and bypass when a break statement is issued. nice catch @Aussiroth ! * #216 - use teleport marker * #216 - use stricter matching conditions * #216 - more complicated test * #216 - cleaned up to work for break step * #216 - initial implementation of continue doesn't work but don't break existing break test case. * #216 - working version of continue + break * #216 - add infinity constant for looping eg for n from 1 to infinity { echo n } if constant too big, takes very large to build stack before execution. trade-off decided to be 1024
Co-Authored-By: Alvin Yan <[email protected]> Co-Authored-By: Victor Loh <[email protected]>
merged to cutting edge release, now prepping to release v4.0 |
Attempt to fix the loss of
continue
andbreak
forfor
-loops in TagUI scripts due to the IIFE pattern.Proposed fix
upon translating from TagUI script to javascript, replace
continue
s andbreak
s into returning corresponding flags.then check the flag and carry out
break
/continue
accordinglyThe text was updated successfully, but these errors were encountered: