joeking11829 / tiny-js

Automatically exported from code.google.com/p/tiny-js
0 stars 0 forks source link

Function symbol is evaluated in bracket-less body of false if-statement #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Precondition: foo is undefined
2. Run this code: if (foo !== undefined) foo();
3. Gives error message: "Expecting 'foo' to be a function"
4. This works: if (foo !== undefined) { foo(); }

What is the expected output? What do you see instead?

Expected bracket-less body to work.
Works when function is defined, for example: 
if (foo !== undefined) print('Hello');
Hello is not printed, as expected.

The implementation seems to take the value of the function symbol, even when 
the condition in the if-statement is false (have not looked at this in the 
actual implementation, I'm guessing).

What version of the product are you using? On what operating system?

TinyJS r11 (Tested on the MoSync port: http://code.google.com/p/mobile-tiny-js/ 
Have not tested with the original code, but I think it behaves the same as the 
port.)

Original issue reported on code.google.com by mikael.k...@gtempaccount.com on 28 Jul 2010 at 7:01

GoogleCodeExporter commented 9 years ago
actually, the whole 'do-not-execute-this' part is faulty, not only in this 
case. i fixed this in my fork ( http://gitorious.org/k8-tinyjs ), but i'm not 
sure if my fork will be of any use to you, 'cause i like to change names, 
styling and so on (so it can't be easily merged to mainline).

Original comment by ketmard...@gmail.com on 30 Jul 2010 at 9:49

GoogleCodeExporter commented 9 years ago
@ketmardark Ok, thanks for the info, perhaps this will eventually go into the 
trunk.

Original comment by mikael.k...@gtempaccount.com on 30 Jul 2010 at 2:14

GoogleCodeExporter commented 9 years ago
you still can be interested in my code, 'cause i fixed some memory leaks and 
other bugs (just wait for gitorious to allow pushing again or write me email 
and i tell the address of my private server).

i was in a need of small c-like language for scripting one of my project, so i 
debugged and cleaned up TinyJS (a good starting codebase, i must say). changes 
are not so big that they can't be reverted easily with any refactoring tool if 
you really need it.

but i will not actively maintain my fork i think, it was just 'i need this 
once, but NOW and working' case.

Original comment by ketmard...@gmail.com on 31 Jul 2010 at 3:43

GoogleCodeExporter commented 9 years ago
The way TinyJS works, it parses everything regardless (except for {}, which is 
what you noticed). In this case it shouldn't have attempted to look up the ID 
for the function but should have just parsed it.

I've fixed this now, and another potential issue with assignments. It should 
have made a (small) performance improvement - not that this is too quick in the 
first place :)

ketmardark: If you find any issues can you report them here? - preferably with 
a patch that applies to the source code that is here and some test case that I 
can add to the tests dir. I don't have the time to scan your code for changes - 
It's not much to ask for given you're using the code as a base.

Original comment by pur3m...@googlemail.com on 16 Aug 2010 at 10:05

GoogleCodeExporter commented 9 years ago
2pur3mail: sorry, i was in a hurry (and forgot my acc password %-), so i was 
just walking thru code and patching, without really nailing what i did. also i 
reformatted the code, so i can't do diffs.

just now i have no time to review it all and contribute back. besideas i was 
pretty sure that the project is stalled (if not dead), so don't even think to 
do bug reports.

actually, i rewritten lexer, added some autoptrs here and there, some flags and 
some code... i'll try to see what i can do to give it all back to you.

for now i'm not using your code anymore, 'cause i developed my own JS engine 
from scratch -- in C, with supporting for almost all JS features, AST builder 
and virtual machine (i need closures and proper supporting of 'var' statement, 
so i was forced to write my own engine %-).

Original comment by ketmard...@gmail.com on 20 Aug 2010 at 12:56

GoogleCodeExporter commented 9 years ago
Thanks, no rush for anything though... If you do have examples of bits of 
javascript that don't work that's probably useful - just so everyone is aware 
of what it can and can't do.

I know development on it goes in spurts - I use it in one of my products, and 
generally it's usable for what I want - It's only now and then that I do 
something a bit more ambitious in script and realise I need to make it more 
useful :)

Congrats on the C implementation - nice of you to release it in such a way that 
anyone can do what they want with it too :)

Original comment by pur3m...@googlemail.com on 20 Aug 2010 at 1:47

GoogleCodeExporter commented 9 years ago
>If you do have examples of bits of javascript that don't work
not that the following code doesn't work, but it doesn't work as it should. %-)
not sure if i should fill tickets with this, as most users don't really use 
such things, and implementing this features right will complicate code alot.

here is one of simple things tinyjs can't do:
function test () {
  z = 42; // SHOULD be local variable
  var z; // this declares 'z' as local for the WHOLE function
}
test();
print(z); // wow! it's '42'!

and another test case, involving closures:
function test () {
  var a = 42;
  return function () { return a; };
}
print(test()()); // should print '42', but prints 'undefined'

actually, i'm using closures and lambdas heavily, so i tested this first. %-)

>Congrats on the C implementation
tnx. i'm trying to do my best. %-)

>nice of you to release it in such a way that anyone can do what they want with 
it too
it's 'cause i'm too lazy to write proper documentation. so i think that anyone 
who is brave enought to use my code must be rewarded somehow. %-)

Original comment by ketmard...@gmail.com on 25 Aug 2010 at 10:53

GoogleCodeExporter commented 9 years ago
Hi ketmar, have you released your C implementation on 
http://gitorious.org/~ketmar? Is it open source? Would be cool to port it to 
MoSync :-) Also made a port of Lua: http://code.google.com/p/mobilelua/
Best, Micke

Original comment by mikael.k...@gtempaccount.com on 26 Aug 2010 at 7:24

GoogleCodeExporter commented 9 years ago
Hi again, is it http://gitorious.org/k8-tjs ?
Micke

Original comment by mikael.k...@gtempaccount.com on 26 Aug 2010 at 7:29

GoogleCodeExporter commented 9 years ago
2mikael: yes, that's it. and of course it's FOSS under WTFPL license. so anyone 
can do anything (s)he want with it. maybe i even integrate necessary pathes in 
mainline. %-)

p.s: sorry for late answers -- somehow i losing notification emails.

Original comment by ketmard...@gmail.com on 29 Aug 2010 at 11:40