decafjs / decaf

decaf core
MIT License
31 stars 7 forks source link

Why Rhino? #6

Closed mpcref closed 8 years ago

mpcref commented 9 years ago

What's the reasoning behind targeting Rhino instead of Nashorn? If it's done for supporting older versions of Java then my question is: Could decafjs be made to target Nashorn from Java 8 and up?

mschwartz commented 9 years ago

The default Java for OS X is 1.6. I really didn't want to force people to install a newer Java just to support decafjs. The idea is it should just work, which it does under 1.6, 1.7, and 1.8. After installing 1.8 on my Mac, I have to constantly edit a .plist file every time I upgrade one of the JetBrains IDEs - when I start them they put up a requester: "Java 6 is required, go install it." This can be fixed by editing the .plist file for the IDE and changing 1.6* to 1.6+. I am unsure if any other 1.8 incompatibilities or issues exist.

Rhino also has a built in debugger, which is a really great feature. There's not a single line of Java written to make decafjs, though it does include 3rd party .jar files. In order to support Nashorn and debug, you need to create a Java app that instantiates a Nashorn instance and set breakpoints in the Java code and step into the JavaScript (basically). You may be able to skip the Java breakpoint, but you get the idea.

In any case, see decafjs/decafn8 - I did get it running on Nashorn. But no debugger. And I found bugs in Nashorn - like JavaScript RegEx not being thread safe. There may be more such bugs, but I didn't bother to try finding them yet. The Nashorn team has been very quick to respond to my bug reports and fix the issues, so I'm not that worried.

I also am in contact with Jim Laskey of Oracle and I got him to update the Askari debugger demo. The documentation on Nashorn debugger protocols is either thin or nonexistent. But I think if I can find the time, I can wrap Askari into a Nashorn version of decaf and we're good to go.

I would love to be able to plug in the JavaScript engine of choice based upon JVM version.

That said, I think you will find decaf and rhino are not so bad as-is. And I don't see why any JavaScript code you write for it won't port to a Nashorn version of Decaf. People I know using it are VERY pleased with its performance and support for many databases and other libraries. Most importantly, they're loving writing synchronous JavaScript (and using threads) instead of callback hell.

My own experience is porting a PHP app to Decaf I see 300ms PHP execution times turn to 0-4ms times depending on how much of the code has been optimized by JIT.

mpcref commented 9 years ago

Thanks for the detailed reply! Those are some valid reasons, good to know that you're looking into Nashorn support.