Search in sources :

Example 1 with EcmaError

use of org.mozilla.javascript.EcmaError in project cucumber-jvm by cucumber.

the class HTMLFormatterTest method writes_valid_report_js.

@Test
public void writes_valid_report_js() throws IOException {
    URL reportJs = new URL(outputDir, "report.js");
    Context cx = Context.enter();
    Global scope = new Global(cx);
    try {
        cx.evaluateReader(scope, new InputStreamReader(reportJs.openStream(), "UTF-8"), reportJs.getFile(), 1, null);
        fail("Should have failed");
    } catch (EcmaError expected) {
        assertTrue(expected.getMessage().startsWith("ReferenceError: \"document\" is not defined."));
    }
}
Also used : Context(org.mozilla.javascript.Context) EcmaError(org.mozilla.javascript.EcmaError) InputStreamReader(java.io.InputStreamReader) URL(java.net.URL) Global(org.mozilla.javascript.tools.shell.Global) Test(org.junit.Test)

Example 2 with EcmaError

use of org.mozilla.javascript.EcmaError in project BPjs by bThink-BGU.

the class JsEventSet method contains.

@Override
public boolean contains(BEvent event) {
    try {
        Object result = predicate.call(Context.getCurrentContext(), predicate, predicate.getParentScope(), new Object[] { Context.javaToJS(event, predicate.getParentScope()) });
        Boolean res = (Boolean) Context.jsToJava(result, Boolean.class);
        if (res == null) {
            throw new RuntimeException("JS Predicate returned null, not a boolean value. " + predicate.toString());
        }
        return res;
    } catch (EvaluatorException ee) {
        throw new BPjsRuntimeException("JS Predicate did not return a boolean value.", ee);
    } catch (EcmaError ee) {
        throw new BPjsRuntimeException("Error evaluating JS Predicate:" + ee.getMessage(), ee);
    }
}
Also used : BPjsRuntimeException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException) EcmaError(org.mozilla.javascript.EcmaError) EvaluatorException(org.mozilla.javascript.EvaluatorException) BPjsRuntimeException(il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException)

Aggregations

EcmaError (org.mozilla.javascript.EcmaError)2 BPjsRuntimeException (il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 Test (org.junit.Test)1 Context (org.mozilla.javascript.Context)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 Global (org.mozilla.javascript.tools.shell.Global)1