Dariusz on Software

Methods and Tools

About This Site

Software development stuff

Archive

Entries from May 2009.

Fri, 15 May 2009 10:25:15 +0000
Do you remember E_ALL setting in PHP? Or "use strict;" in Perl? Or strong declarations of function arguments in ANSI C? All those attempts are aimed at minimize probability of mistake during software development. By using stricter language simple programming errors could be easily detected during compilation (C) or during execution (interpreted languages). Java Script plays important role in web-based applications. It's the primary implementation tool for rich GUIs based on browsers (AJAX). Due to it's dynamic nature it accept broad range of programming constructs (including using of uninitialised variable). So it's not very safe to build large systems based on Java Script. JSLint will help you with elimination from Java Script errant constructs by defining strict subset of Java Script: JSLint defines a professional subset of JavaScript, a stricter language than that defined by Third Edition of the ECMAScript Programming Language Standard. The subset is related to recommendations found in Code Conventions for the JavaScript Programming Language. JSLint is written in JavaScript so it requires Java Script interpreter to run. Luckily we have Spidermonkey that is Mozilla's Java Script implementation written in C language. This implmentation is fast (at least with comparision to Rhino) and stable. The only problem is that Spidermonkey doesn't allow IO operations by default (for security reasons). I found an altered JSLint implementation suited for SpiderMonkey, but found it to hang up. The problem was with end-of-file detection algorithm:
while (blankcount < 10){
    line=readline();  

    if (line=="")
        blankcount++;
    else
        blankcount=0;
    if (line=="END") break;
        input += line;
        input += "\n";
}
I fixed it by checking for null instead of "":
while (true) {
    line=readline();

    if (line == null)
        break

    input += line;
    input += "\n";
}
And now it's working perfectly. Here's modified version. Enjoy!

AJAX programming IDE ;-)
Tags: javascript.

Tags

Created by Chronicle v3.5