Example usage for jdk.nashorn.internal.runtime ErrorManager hasErrors

List of usage examples for jdk.nashorn.internal.runtime ErrorManager hasErrors

Introduction

In this page you can find the example usage for jdk.nashorn.internal.runtime ErrorManager hasErrors.

Prototype

public boolean hasErrors() 

Source Link

Document

Test to see if errors have occurred.

Usage

From source file:com.threecrickets.scripturian.adapter.NashornProgram.java

License:LGPL

public void execute(ExecutionContext executionContext) throws ParsingException, ExecutionException {
    ScriptObject oldGlobal = Context.getGlobal();
    try {/*from  w  w w.jav  a 2s  .  c  o  m*/
        ScriptObject globalScope = adapter.getGlobalScope(executionContext);
        ErrorManager errorManager = adapter.context.getErrorManager();

        // long s = System.currentTimeMillis();
        ScriptFunction script = adapter.context
                .compileScript(Source.sourceFor(executable.getDocumentName(), sourceCode), globalScope);
        if ((script == null) || errorManager.hasErrors())
            throw new ParsingException(executable.getDocumentName());
        // s = System.currentTimeMillis() - s;
        // System.out.println( "COMPILE: " + s / 1000.0f );

        try {
            // s = System.currentTimeMillis();
            ScriptRuntime.apply(script, globalScope);
            // s = System.currentTimeMillis() - s;
            // System.out.println( "RUN: " + s / 1000.0f );
        } catch (Throwable x) {
            throw NashornAdapter.createExecutionException(x, executable.getDocumentName());
        } finally {
            adapter.context.getOut().flush();
            adapter.context.getErr().flush();
        }
    } finally {
        if (oldGlobal != null)
            Context.setGlobal(oldGlobal);
    }
}

From source file:org.netbeans.es.perftest.nashorn.NashornParser.java

License:Open Source License

@Override
public boolean parse(File file, ParserOptions options) throws IOException {
    final PrintWriter err = options.isPrintError() ? options.getProgressWriter()
            : new PrintWriter(new OutputStreamWriter(new ByteArrayOutputStream()));
    final ScriptEnvironment env = new ScriptEnvironment(
            new jdk.nashorn.internal.runtime.options.Options(file.getAbsolutePath()), err, err);
    final Source src = Source.sourceFor(file.getName(), file);
    final ErrorManager em = new ErrorManager(err);
    final Parser p = new Parser(env, src, em);
    final FunctionNode node = p.parse();
    return !em.hasErrors();
}