Search in sources :

Example 1 with ToolErrorReporter

use of org.mozilla.javascript.tools.ToolErrorReporter in project hackpad by dropbox.

the class Main method exec.

/**
     *  Execute the given arguments, but don't System.exit at the end.
     */
public static int exec(String[] origArgs) {
    errorReporter = new ToolErrorReporter(false, global.getErr());
    shellContextFactory.setErrorReporter(errorReporter);
    String[] args = processOptions(origArgs);
    if (mainModule != null && !fileList.contains(mainModule))
        fileList.add(mainModule);
    if (processStdin)
        fileList.add(null);
    if (!global.initialized) {
        global.init(shellContextFactory);
    }
    IProxy iproxy = new IProxy(IProxy.PROCESS_FILES);
    iproxy.args = args;
    shellContextFactory.call(iproxy);
    return exitCode;
}
Also used : ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter)

Example 2 with ToolErrorReporter

use of org.mozilla.javascript.tools.ToolErrorReporter in project hackpad by dropbox.

the class Main method exec.

private int exec(String[] args) {
    R = new ToolErrorReporter(true, System.err);
    int arg_count = process_options(args);
    if (arg_count == 0) {
        option_error(ToolErrorReporter.getMessage("msg.idswitch.no_file_argument"));
        return -1;
    }
    if (arg_count > 1) {
        option_error(ToolErrorReporter.getMessage("msg.idswitch.too_many_arguments"));
        return -1;
    }
    P = new CodePrinter();
    P.setIndentStep(4);
    P.setIndentTabSize(0);
    try {
        process_file(args[0]);
    } catch (IOException ex) {
        print_error(ToolErrorReporter.getMessage("msg.idswitch.io_error", ex.toString()));
        return -1;
    } catch (EvaluatorException ex) {
        return -1;
    }
    return 0;
}
Also used : EvaluatorException(org.mozilla.javascript.EvaluatorException) ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter)

Example 3 with ToolErrorReporter

use of org.mozilla.javascript.tools.ToolErrorReporter in project hackpad by dropbox.

the class PipeThread method runDoctest.

public int runDoctest(Context cx, Scriptable scope, String session, String sourceName, int lineNumber) {
    doctestCanonicalizations = new HashMap<String, String>();
    String[] lines = session.split("[\n\r]+");
    String prompt0 = this.prompts[0].trim();
    String prompt1 = this.prompts[1].trim();
    int testCount = 0;
    int i = 0;
    while (i < lines.length && !lines[i].trim().startsWith(prompt0)) {
        // skip lines that don't look like shell sessions
        i++;
    }
    while (i < lines.length) {
        String inputString = lines[i].trim().substring(prompt0.length());
        inputString += "\n";
        i++;
        while (i < lines.length && lines[i].trim().startsWith(prompt1)) {
            inputString += lines[i].trim().substring(prompt1.length());
            inputString += "\n";
            i++;
        }
        String expectedString = "";
        while (i < lines.length && !lines[i].trim().startsWith(prompt0)) {
            expectedString += lines[i] + "\n";
            i++;
        }
        PrintStream savedOut = this.getOut();
        PrintStream savedErr = this.getErr();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        this.setOut(new PrintStream(out));
        this.setErr(new PrintStream(err));
        String resultString = "";
        ErrorReporter savedErrorReporter = cx.getErrorReporter();
        cx.setErrorReporter(new ToolErrorReporter(false, this.getErr()));
        try {
            testCount++;
            Object result = cx.evaluateString(scope, inputString, "doctest input", 1, null);
            if (result != Context.getUndefinedValue() && !(result instanceof Function && inputString.trim().startsWith("function"))) {
                resultString = Context.toString(result);
            }
        } catch (RhinoException e) {
            ToolErrorReporter.reportException(cx.getErrorReporter(), e);
        } finally {
            this.setOut(savedOut);
            this.setErr(savedErr);
            cx.setErrorReporter(savedErrorReporter);
            resultString += err.toString() + out.toString();
        }
        if (!doctestOutputMatches(expectedString, resultString)) {
            String message = "doctest failure running:\n" + inputString + "expected: " + expectedString + "actual: " + resultString + "\n";
            if (sourceName != null)
                throw Context.reportRuntimeError(message, sourceName, lineNumber + i - 1, null, 0);
            else
                throw Context.reportRuntimeError(message);
        }
    }
    return testCount;
}
Also used : ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter)

Example 4 with ToolErrorReporter

use of org.mozilla.javascript.tools.ToolErrorReporter in project Auto.js by hyb1996.

the class Main method exec.

/**
 * Execute the given arguments, but don't System.exit at the end.
 */
public static int exec(String[] origArgs) {
    errorReporter = new ToolErrorReporter(false, global.getErr());
    shellContextFactory.setErrorReporter(errorReporter);
    String[] args = processOptions(origArgs);
    if (exitCode > 0) {
        return exitCode;
    }
    if (processStdin) {
        fileList.add(null);
    }
    if (true) {
        global.init(shellContextFactory);
    }
    IProxy iproxy = new IProxy(IProxy.PROCESS_FILES);
    iproxy.args = args;
    shellContextFactory.call(iproxy);
    return exitCode;
}
Also used : ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter)

Example 5 with ToolErrorReporter

use of org.mozilla.javascript.tools.ToolErrorReporter in project pentaho-kettle by pentaho.

the class ScriptDialog method parseVariables.

// This could be useful for further improvements
public static ScriptNode parseVariables(Context cx, Scriptable scope, String source, String sourceName, int lineno, Object securityDomain) {
    // Interpreter compiler = new Interpreter();
    CompilerEnvirons evn = new CompilerEnvirons();
    // evn.setLanguageVersion(Context.VERSION_1_5);
    evn.setOptimizationLevel(-1);
    evn.setGeneratingSource(true);
    evn.setGenerateDebugInfo(true);
    ErrorReporter errorReporter = new ToolErrorReporter(false);
    Parser p = new Parser(evn, errorReporter);
    // IOException
    ScriptNode tree = p.parse(source, "", 0);
    new NodeTransformer().transform(tree);
    // Script result = (Script)compiler.compile(scope, evn, tree, p.getEncodedSource(),false, null);
    return tree;
}
Also used : ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ErrorReporter(org.mozilla.javascript.ErrorReporter) NodeTransformer(org.mozilla.javascript.NodeTransformer) CompilerEnvirons(org.mozilla.javascript.CompilerEnvirons) ToolErrorReporter(org.mozilla.javascript.tools.ToolErrorReporter) ScriptNode(org.mozilla.javascript.ast.ScriptNode) Parser(org.mozilla.javascript.Parser)

Aggregations

ToolErrorReporter (org.mozilla.javascript.tools.ToolErrorReporter)6 CompilerEnvirons (org.mozilla.javascript.CompilerEnvirons)2 ErrorReporter (org.mozilla.javascript.ErrorReporter)2 NodeTransformer (org.mozilla.javascript.NodeTransformer)2 Parser (org.mozilla.javascript.Parser)2 ScriptNode (org.mozilla.javascript.ast.ScriptNode)2 EvaluatorException (org.mozilla.javascript.EvaluatorException)1