C Programming Tutorials and advice
CProgrammingTrends News Archives About Us Feedback

Recent Articles

Pointers And Their Pitfalls
This may seem like a very basic idea, but I have seen far too many programmers not know the proper way to handle pointers. Pointers were the first thing I learned about in my second programming class...

Worldwide Programming Competition To Begin Soon
Keep an eye out - or get your application in - if you're interested in a competition that should unearth and crown some of the world's best programmers.

CodePlex Foundation, MySpace's Qizmt
MySpace announced that they're open sourcing Qizmt, a MapReduce framework used by the MySpace Data Mining team. Unlike other leading MapReduce frameworks...

August TIOBE Index Indicates Growth
The C, C++, and C# programming languages all performed well in the latest TIOBE Programming Community Index. One of them held its ground in terms of overall rankings, while the other two managed...

Garbage Collection And C
Garbage collection is an extremely undervalued aspect of modern society. After all, we couldn't be buzzing around in hybrids and enjoying our plasma TVs if we were...


11.05.09

How To Use C Programming To Verify Your Javascript


By Mads Kristensen

In the past few days, I've worked on finding a way to do static code analysis on JavaScript files.The resaon is that I want to apply some sort of binary and source code checking like FxCop and StyleCop provides for C#.

There exist some tools for linting JavaScript like JavaScript Lint, but linting only checks syntax and not implementation. To do that I found the Jscript compiler build into the .NET Framework to be just what I wanted. It compiles JavaScript and reports if it finds any errors.

To test it out, I wrote a simple C# class that takes an array of JavaScript files to compile. I then called the class from a unit test, so I could make the test fail if the compiler finds any errors with the script files. The class contains a single public method called Compile and here is a simplified example on how to use it from any unit testing framework. You can download the class at the bottom of this post.





What's nice is that by doing compile time checking of JavaScripts, I get that extra little security that's so hard to get when developing JavaScript heavy websites. The Microsoft JScript compiler isn't perfect, so I still recommend using a linting tool as well. The two approaches cover different scenarios. I hope to have a very simple implementation on using a linting tool soon.

Download

Remember to add a reference to Microsoft.JScript in your Visual Studio project before using this class.

JavaScriptCompiler.cs (2,48 kb)

Comments

About the Author:
Mads Kristensen currently works as a Senior Developer at Traceworks located in Copenhagen, Denmark. Mads graduated from Copenhagen Technical Academy with a multimedia degree in 2003, but has been a professional developer since 2000. His main focus is on ASP.NET but is responsible for Winforms, Windows- and web services in his daily work as well. A true .NET developer with great passion for the simple solution.

http://www.madskristensen.dk/
About CProgrammingTrends
A collection of articles and tutorials designed to help C and C variant programmers in their programming work. C Programming Tutorials and advice





CProgrammingTrends is brought to you by:

SecurityConfig.com NetworkingFiles.com
NetworkNewz.com WebProASP.com
DatabaseProNews.com SQLProNews.com
ITcertificationNews.com SysAdminNews.com
LinuxProNews.com WirelessProNews.com
CProgrammingTrends.com ITmanagmentNews.com





-- CProgrammingTrends is an iEntry, Inc. publication --
iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509
2009 iEntry, Inc.  All Rights Reserved  Privacy Policy  Legal


archives | advertising info | news headlines | free newsletters | comments/feedback | submit article


CProgrammingTrends Home Page About Article Archive News Downloads WebProWorld Forums Jayde iEntry Advertise Contact