Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

javascript/jscript syntax checking

41 views
Skip to first unread message

Colin Adams

unread,
Jun 29, 2001, 4:04:05 AM6/29/01
to
Is there such a beast as a javascript syntax checker?


Matt

unread,
Jun 30, 2001, 3:53:18 AM6/30/01
to
Yeah, your browser. Run the script. If you don't get any syntax errors, your
script is syntactically correct. This isn't to say that the script won't
generate other runtime errors, however.

Matt

"Colin Adams" <ada...@kssg.com> wrote in message
news:O29qLHHABHA.1244@tkmsftngp03...

Colin Adams

unread,
Jul 2, 2001, 4:15:15 AM7/2/01
to
OK, I'll phrase the question better.

Does anyone know of a static type checker for javascript?
"Matt" <ma...@eesoft.org> wrote in message
news:OzK5TnTABHA.1352@tkmsftngp05...

Peter Torr (MS)

unread,
Jul 2, 2001, 12:02:18 PM7/2/01
to
"Colin Adams" <ada...@kssg.com> wrote in message
news:ebaOZ7sABHA.396@tkmsftngp02...

> OK, I'll phrase the question better.
>
> Does anyone know of a static type checker for javascript?

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.


Thor Larholm

unread,
Jul 2, 2001, 2:21:34 PM7/2/01
to
"Peter Torr (MS)" <pt...@microsoft.com> wrote in message
news:#6wxiBxABHA.1488@tkmsftngp05...

> "Colin Adams" <ada...@kssg.com> wrote in message
> news:ebaOZ7sABHA.396@tkmsftngp02...
> > OK, I'll phrase the question better.
> >
> > Does anyone know of a static type checker for javascript?
>
> Hi,
>
> You could always run it through the JScript.NET compiler (JSC). Although
> that won't work too well with an HTML page.

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


Dave Methvin

unread,
Jul 2, 2001, 5:16:59 PM7/2/01
to
> Does anyone know of a static type checker for 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...

Colin Adams

unread,
Jul 3, 2001, 3:48:38 AM7/3/01
to
Yes, such a beast COULD exist - it would involve type inference - but
apparently there isn't anything, judging from the rplies I've seen so far.

"Dave Methvin" <news...@methvin.com> wrote in message
news:ORCpjxzABHA.1496@tkmsftngp05...

Jim Ley

unread,
Jul 3, 2001, 6:57:54 AM7/3/01
to

"Thor Larholm" <th...@jubii.dk> wrote in message
news:eZxQfOyABHA.236@tkmsftngp02...

> "Peter Torr (MS)" <pt...@microsoft.com> wrote in message
> news:#6wxiBxABHA.1488@tkmsftngp05...
> > "Colin Adams" <ada...@kssg.com> wrote in message
> > news:ebaOZ7sABHA.396@tkmsftngp02...
> > > OK, I'll phrase the question better.
> > >
> > > Does anyone know of a static type checker for javascript?
> >
> > Hi,
> >
> > You could always run it through the JScript.NET compiler (JSC).
Although
> > that won't work too well with an HTML page.
>
> Could the JScript syntax checker inside JSCRIPT.DLL (standard IE, no
.NET) be
> used ?

<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.


Thor Larholm

unread,
Jul 3, 2001, 7:31:35 AM7/3/01
to
"Jim Ley" <j...@jibbering.com> wrote in message
news:OrE6B96ABHA.1196@tkmsftngp05...

>
> "Thor Larholm" <th...@jubii.dk> wrote in message
> > Could the JScript syntax checker inside JSCRIPT.DLL (standard IE, no
> .NET) be
> > used ?
>
> <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.)

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.

Jim Ley

unread,
Jul 3, 2001, 7:48:45 AM7/3/01
to

"Thor Larholm" <th...@jubii.dk> wrote in message
news:eqlBGO7ABHA.2016@tkmsftngp03...

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.


Thor Larholm

unread,
Jul 3, 2001, 8:27:14 AM7/3/01
to
"Jim Ley" <j...@jibbering.com> wrote in message
news:uQ1HeZ7ABHA.1196@tkmsftngp05...

>
> "Thor Larholm" <th...@jubii.dk> wrote in message

<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 ? :)

Jim Ley

unread,
Jul 3, 2001, 8:35:45 AM7/3/01
to

"Thor Larholm" <th...@jubii.dk> wrote in message
news:#K0UMt7ABHA.408@tkmsftngp05...

> "Jim Ley" <j...@jibbering.com> wrote in message
> news:uQ1HeZ7ABHA.1196@tkmsftngp05...
> >
> > "Thor Larholm" <th...@jubii.dk> wrote in message
>
> <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.

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.


Andrew Clinick

unread,
Jul 3, 2001, 2:06:52 PM7/3/01
to
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.

hth

Andrew


"Thor Larholm" <th...@jubii.dk> wrote in message

news:#K0UMt7ABHA.408@tkmsftngp05...

Thor Larholm

unread,
Jul 3, 2001, 2:57:25 PM7/3/01
to
"Andrew Clinick" <reply@togroup> wrote in message
news:#ZFRzr#ABHA.1668@tkmsftngp02...

<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 ;)

Peter Torr (MS)

unread,
Jul 3, 2001, 1:40:01 PM7/3/01
to
"Thor Larholm" <th...@jubii.dk> wrote in message
news:#K0UMt7ABHA.408@tkmsftngp05...

> 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 ? :)

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.

Thor Larholm

unread,
Jul 4, 2001, 6:16:39 AM7/4/01
to
"Peter Torr (MS)" <pt...@microsoft.com> wrote in message
news:ehhDIJFBBHA.1780@tkmsftngp07...

> "Thor Larholm" <th...@jubii.dk> wrote in message
> news:#K0UMt7ABHA.408@tkmsftngp05...
> > 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 ? :)
>
> 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.

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

0 new messages