Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

is there a way to validate a Javascript using Java?

Thread view: 
ufmemo@gmail.com - 25 May 2006 19:45 GMT
What i'm looking to do is to serve dynamically generated Javascript
from a J2EE application.  I'd like to see if there are Javascript
compiler exceptions before i serve the JS to the browser.

Is there a javascript interpreter for Java that I might be able to use
to tell if there are compile time exceptions in the JS?  An alternative
or other suggestions are welcome!  Thank you.

John Jimenez
Oliver Wong - 25 May 2006 20:07 GMT
> What i'm looking to do is to serve dynamically generated Javascript
> from a J2EE application.  I'd like to see if there are Javascript
[quoted text clipped - 3 lines]
> to tell if there are compile time exceptions in the JS?  An alternative
> or other suggestions are welcome!  Thank you.

   When I google for "javascript interpreter for java" I get
http://www.mozilla.org/rhino/

   - Oliver
alexandre_paterson@yahoo.fr - 26 May 2006 14:46 GMT
> > What i'm looking to do is to serve dynamically generated Javascript
> > from a J2EE application.  I'd like to see if there are Javascript
[quoted text clipped - 6 lines]
>     When I google for "javascript interpreter for java" I get
> http://www.mozilla.org/rhino/

I'd indeed expect "Rhino" to be one of the first matches, for Rhino
is actually included in Java 1.6

:)
Chris Smith - 25 May 2006 20:56 GMT
> What i'm looking to do is to serve dynamically generated Javascript
> from a J2EE application.  I'd like to see if there are Javascript
> compiler exceptions before i serve the JS to the browser.

The entirety of what you're asking for is absolutely IMPOSSIBLE, for any
sufficiently powerful language (of which JavaScript is considered
sufficiently powerful).  Alan Turing and Alonzo Church both gave
independent proofs of this in 1936.  There exists NO way to examine an
arbitrary piece of code and determine whether something will happen or
not in general.

That said, you can do as Oliver suggested and give it a few test runs
with Rhino.  The problem will be in simulating the user's web browser
accurately enough to reproduce any problems that might come up.  Are you
sure you want to re-implement the DOM for HTML, for instance?  It will
be a lot of work, and it won't be perfect... but it still might be
better than nothing.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Oliver Wong - 25 May 2006 21:18 GMT
>> What i'm looking to do is to serve dynamically generated Javascript
>> from a J2EE application.  I'd like to see if there are Javascript
[quoted text clipped - 6 lines]
> arbitrary piece of code and determine whether something will happen or
> not in general.

   I had assumed by "compiler exceptions", the OP meant they wanted to
check for syntax errors (e.g. missing braces or parentheses). The usefulness
of this? Perhaps as unit tests, or because the generated JavaScript depends
on user provided input. If the OP is indeed asking about behaviour of
syntactically legal JavaScript, then Chris is right: it's impossible, and a
summary of why is at http://en.wikipedia.org/wiki/Halting_problem

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.