Search in sources :

Example 21 with Function

use of org.mozilla.javascript.Function in project jslint4java by happygiraffe.

the class JSLintBuilder method fromReader.

/**
 * Initialize the scope with an arbitrary jslint.
 *
 * @param reader
 *            an input source providing jslint.js.
 * @param name
 *            the name of the resource backed by the reader
 * @return a configured {@link JSLint}
 * @throws IOException
 *             if there are any problems reading from {@code reader} .
 */
@NeedsContext
public JSLint fromReader(Reader reader, String name) throws IOException {
    try {
        Context cx = contextFactory.enterContext();
        ScriptableObject scope = cx.initStandardObjects();
        cx.evaluateReader(scope, reader, name, 1, null);
        Function lintFunc = (Function) scope.get("JSLINT", scope);
        return new JSLint(contextFactory, lintFunc);
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) Function(org.mozilla.javascript.Function) ScriptableObject(org.mozilla.javascript.ScriptableObject)

Aggregations

Function (org.mozilla.javascript.Function)21 ScriptableObject (org.mozilla.javascript.ScriptableObject)12 Context (org.mozilla.javascript.Context)10 Scriptable (org.mozilla.javascript.Scriptable)6 ContextAction (org.mozilla.javascript.ContextAction)4 Map (java.util.Map)3 SightlyException (org.apache.sling.scripting.sightly.SightlyException)3 BaseFunction (org.mozilla.javascript.BaseFunction)3 HashMap (java.util.HashMap)2 TimingFunction (org.apache.sling.scripting.sightly.js.impl.async.TimingFunction)2 HybridObject (org.apache.sling.scripting.sightly.js.impl.rhino.HybridObject)2 ContinuationPending (org.mozilla.javascript.ContinuationPending)2 NativeArray (org.mozilla.javascript.NativeArray)2 NativeObject (org.mozilla.javascript.NativeObject)2 RhinoException (org.mozilla.javascript.RhinoException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ResultBuilder (com.googlecode.jslint4java.JSLintResult.ResultBuilder)1 ArgumentReader (com.scratchdisk.script.ArgumentReader)1 StringArgumentReader (com.scratchdisk.script.StringArgumentReader)1 ExtendedJavaClass (com.scratchdisk.script.rhino.ExtendedJavaClass)1