Matt
"Colin Adams" <ada...@kssg.com> wrote in message
news:O29qLHHABHA.1244@tkmsftngp03...
Does anyone know of a static type checker for javascript?
"Matt" <ma...@eesoft.org> wrote in message
news:OzK5TnTABHA.1352@tkmsftngp05...
Hi,
You could always run it through the JScript.NET compiler (JSC). Although
that won't work too well with an HTML page.
Peter
--
Peter Torr - pt...@microsoft.com
JScript .NET / VSA Runtime Program Manager
Please post all questions to the group. Thanks.
Could the JScript syntax checker inside JSCRIPT.DLL (standard IE, no .NET) be
used ?
If there is not already some documentation on what the function is called and
what arguments it expects, I would be glad to hear the details. I could then use
DynaWrap (
http://cwashington.netreach.net/project_bench/default.asp?topic=code ) to wrap
the API call directly, and use this for syntax checking programmatically in my
ScriptPackager (which expects wellformed JScript code, but produces hillarious
results otherwise).
--
Thor Larholm
<URL: http://www.jibbering.com/faq/> FAQ for comp.lang.javascript
Can such a thing ever exist? JScript is pretty dynamic. In many cases, the
only way to find type mismatches, undeclared functions, or undefined
variables will be to run the program. Static checking (something equivalent
to C's lint) wouldn't work for a non-trivial program. It's certainly
possible to compile the source into an intermediate language to catch syntax
errors and eliminate parsing costs, but much of the magic will still have to
occur at runtime.
"Colin Adams" <ada...@kssg.com> wrote in message
news:ebaOZ7sABHA.396@tkmsftngp02...
"Dave Methvin" <news...@methvin.com> wrote in message
news:ORCpjxzABHA.1496@tkmsftngp05...
<object id=idWPM classid=clsid:00fe3bec-b5e7-11d2-b931-002018654e2e
style="display:none">
</object>
You can embed the ScriptControl ActiveX object (download somewhere from
msdn.microsoft.com/scripting/ unless that's got trashed into unusability
like the rest of MSDN.)
Then you can do:
<object id=idWPM classid=clsid:00fe3bec-b5e7-11d2-b931-002018654e2e
style="display:none">
</object>
<script>
scripthost=new ActiveXObject("ScriptControl")
//wpmObject.browseObject(scripthost)
scripthost.language="JScript"
Jim="function jim() {j=0;for (i=0;i<10;i++) j++;return j}"
try {
scripthost.AddCode(Jim)
} catch (e) {
document.write(scripthost.Error.Line+'<br>')
document.write(scripthost.Error.Description+'<br>')
document.write(scripthost.Error.Number+'<br>')
}
try {
document.write(scripthost.Run("jim"))
} catch (e) {}
</script>
Documentation is there in the browseObject line - uncomment it :-)
WPM/Zeepe used here, save it as something.wpm
Jim.
They should shoot the person responsible for that crappy, useless navigation
system on MSDN. Oh, and the guy who moved everything around.
> Then you can do:
>
> <object id=idWPM classid=clsid:00fe3bec-b5e7-11d2-b931-002018654e2e
> style="display:none">
> </object>
> <script>
> scripthost=new ActiveXObject("ScriptControl")
> //wpmObject.browseObject(scripthost)
> scripthost.language="JScript"
> Jim="function jim() {j=0;for (i=0;i<10;i++) j++;return j}"
> try {
> scripthost.AddCode(Jim)
> } catch (e) {
> document.write(scripthost.Error.Line+'<br>')
> document.write(scripthost.Error.Description+'<br>')
> document.write(scripthost.Error.Number+'<br>')
> }
> try {
> document.write(scripthost.Run("jim"))
> } catch (e) {}
>
> </script>
>
> Documentation is there in the browseObject line - uncomment it :-)
> WPM/Zeepe used here, save it as something.wpm
Jim to the rescue once again :)
This still runs the code instead of merely checking for syntax errors, but is
better than nothing.
AddCode will just do the syntax check, the Run (in the second try block)
will run it, remove it if you don't want to run it - You'll need to
generate a DOM, if you're going to use it, do that with AddObject or
something IIRC - Peter will know more, well he should do :-)
Jim.
<on MS ScriptControl>
> > Jim to the rescue once again :)
> > This still runs the code instead of merely checking for syntax errors,
> but is
> > better than nothing.
>
> AddCode will just do the syntax check, the Run (in the second try block)
> will run it, remove it if you don't want to run it -
I was hoping for this too, but AddCode does indeed execute the added code. Try
this:
SC = new ActiveXObject("ScriptControl");
SC.Language = "JScript";
SC.AddCode("B = new ActiveXObject('WScript.Shell')");
I was hoping to avoid an execution of the code, and merely check for syntax
errors. Maybe I'll still have to poke around in JSCRIPT.DLL with DynaWrap and
find the API call which does only this.
> You'll need to
> generate a DOM, if you're going to use it, do that with AddObject or
> something IIRC - Peter will know more, well he should do :-)
I won't be using this in an execution context, my ScriptPackager is build to
reduce the codesize and for this to happen it needs wellformed code without
syntax errors. Being able to check for correct syntax would be a welcome
addition, but I have no problems with poking the other developers to provide
pure code ;)
Maybe Peter can shed some light on the situation ? Maybe ( can I hope so ?) he
knows the name of the API call in JSCRIPT.DLL that I could use ? :)
Sorry, it does yes, but only code at the global scope, wrap up the code
you want to test in a function
SC.AddCode("function Moomin() { B=new
ActiveXObject('WScript.Shell');B.PopUp("Moomins!") }")
And then it won't run, but you'll still get the syntax check no?
It may be CodeObject, rather than AddObject for adding global methods, I
can't remember it was ages ago I did this (found it in /script/ rather
than /junk/ though so must've been reasonably serious about doing
something with it - can't remember what though.
Jim.
hth
Andrew
"Thor Larholm" <th...@jubii.dk> wrote in message
news:#K0UMt7ABHA.408@tkmsftngp05...
<snip about JS syntax checking and API calls for JSCRIPT.DLL>
> I think the API you're looking for is UpgradeToJScriptDotNET :) Seriously
> this isn't something that JScript 5.x does but in JScript.NET and Script for
> the .NET Framework this is provided.
I know, and I am upgrading. However, while the entire .NET Framework is still
beta software, you won't find it on any of my running production machines, and
hence I can't use it for reallife applications. If I knew the name of the
function inside JSCRIPT.DLL that does the syntax checking of JS code in IE, I
could use this NOW instead of waiting ;)
Hi,
I'm at TechEd at the moment, so can't really check. You might be able to do
it if you host the IActiveScript engines directly, and mess around with the
engine states. I think you need to add the code and then put the engine into
CONNECTED state, but I can get more information from one of our developers
when I get back to Redmond.
If there's a way on the ScriptControl to set the state of the engine (I
don't know off-hand), try playing with that.
I'll be looking forward to it :)
> If there's a way on the ScriptControl to set the state of the engine (I
> don't know off-hand), try playing with that.
I'm poking around in ScriptControl as-I-write, maybe I'll find something there.
Untill then, have fun at TechEd and remember to promote JScript.NET in favor of
C# :P