package net.happygiraffe.jslint;

import java.io.IOException;
import java.io.Reader;

import org.mozilla.javascript.Scriptable;

/**
 * A collection of useful routines.
 * 
 * @author dom
 * @version $Id$
 */
class Util {

    /**
     * Return the integer value of a JavaScript variable.
     * 
     * @param name
     *                the JavaScript variable
     * @param scope
     *                the JavaScript scope to read from
     * @return the value of <i>name</i> as an integer, or zero.
     */
    static int intValue(String name, Scriptable scope) {
        Object o = scope.get(name, scope);
        return o instanceof Number ? ((Number) o).intValue() : 0;
    }

    /**
     * Returns the value of a JavaScript variable, or null.
     * 
     * @param name
     *                the JavaScript variable.
     * @param scope
     *                the JavaScript scope to read from
     * @return the value of <i>name</i> or null.
     */
    static String stringValue(String name, Scriptable scope) {
        Object o = scope.get(name, scope);
        return o instanceof String ? (String) o : null;
    }

    /**
     * Read all of a {@link Reader} into memory as a {@link String}.
     * 
     * @param reader
     * @return
     * @throws IOException
     */
    static String readerToString(Reader reader) throws IOException {
        StringBuffer sb = new StringBuffer();
        int c;
        while ((c = reader.read()) != -1) {
            sb.append((char) c);
        }
        return sb.toString();
    }

}

@@ -79,16 +79,55 @@
 eader;%0A%0A
+import org.mozilla.javascript.Context;%0A
 import o
@@ -663,55 +663,63 @@
 n o 
-instanceof Number ? ((Number) o).intValue() : 0
+== Scriptable.NOT_FOUND ? 0 : (int) Context.toNumber(o)
 ;%0A  

Use the supplied Context.toNumber() instead of hand-rolling it ourselves.