gfwilliams / tiny-js

Automatically exported from code.google.com/p/tiny-js
MIT License
532 stars 88 forks source link

while(true){...} error #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
while(true){...} error

Original issue reported on code.google.com by zhoujr.m...@gmail.com on 29 Dec 2011 at 9:10

GoogleCodeExporter commented 9 years ago
Hi, 

Do you have any example code?

I'm not sure we support break in while loops (maybe on Armin's branch) so while 
(true) will always just be an infinite loop...

Original comment by pur3m...@googlemail.com on 29 Dec 2011 at 3:40

GoogleCodeExporter commented 9 years ago
Hi, 
Please see the statement: "int loopCount = TINYJS_LOOP_MAX_ITERATIONS;"
{
    var i = 0;
    while (true)i++;
}
After run the above statements, TinyJS will throw an exception 
"CScriptException("LOOP_ERROR")".
[WHILE Loop exceeded 8912 iterations]
I don't know what's the reason of limiting LOOP COUNT, and can you tell me?

The break in while loops is supported on Armin's branch, but not on the trunck.
The prefix opertation "++" and "--" is not supported too.

I tried to use code on Armin's branch, but it don't support some important key 
words too. Such as "var sObject = new Object();".

I hope you can support the break operation.
Waiting for you, thank you!

Original comment by zhoujr.m...@gmail.com on 29 Dec 2011 at 4:40

GoogleCodeExporter commented 9 years ago
The reasoning is that TinyJS is designed for scripting applications - as such 
it's generally used for very small loops. If you have lots of loop iterations 
we assume it's generally a bug in the script - and not getting stuck in an 
infinite (or huge) loop is a useful feature that has come in handy for me.

If you want more leeway, just set TINYJS_LOOP_MAX_ITERATIONS to something big. 
TinyJS isn't that fast, so setting it to 2 billion is effectively infinite.

As for the lack of Prefix, this is documented at the top of TinyJS.cpp, along 
with some other things that aren't implemented/don't work.

Break/continue may be implemented at some point, but not soon, and probably not 
by me. I use TinyJS for scripting in my applications, and for that, the current 
subset of Javascript is more than sufficient.

Armin's branch *does* support 'new' though, so maybe the only problem you have 
is with the use of 'Object'?

I'm afraid that if you're after a fully-featured JavaScript interpreter, you're 
probably better off going elsewhere. TinyJS is designed to be simple, and as 
such supporting the whole of the ECMAScript standard really isn't what it's 
about.

Original comment by pur3m...@googlemail.com on 5 Jan 2012 at 5:31

GoogleCodeExporter commented 9 years ago
Thanks, I got it.

Original comment by zhoujr.m...@gmail.com on 6 Jan 2012 at 1:49