use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class ErrorPropertiesTest method testIt.
private void testIt(final String script, final Object expected) {
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
try {
final ScriptableObject scope = cx.initStandardObjects();
final Object o = cx.evaluateString(scope, script, "myScript.js", 1, null);
Assert.assertEquals(expected, o);
return o;
} catch (final RuntimeException e) {
throw e;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class FunctionTest method assertEvaluates.
private void assertEvaluates(final Object expected, final String source) {
final ContextAction action = new ContextAction() {
public Object run(Context cx) {
final Scriptable scope = cx.initStandardObjects();
final Object rep = cx.evaluateString(scope, source, "test.js", 0, null);
assertEquals(expected, rep);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class GeneratedClassNameTest method doTest.
private void doTest(final String expectedName, final String scriptName) throws Exception {
final Script script = (Script) ContextFactory.getGlobal().call(new ContextAction() {
public Object run(final Context context) {
return context.compileString("var f = 1", scriptName, 1, null);
}
});
// remove serial number
String name = script.getClass().getSimpleName();
assertEquals(expectedName, name.substring(0, name.lastIndexOf('_')));
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class GeneratedMethodNameTest method doTest.
public void doTest(final String scriptCode) throws Exception {
final Context cx = ContextFactory.getGlobal().enterContext();
try {
Scriptable topScope = cx.initStandardObjects();
topScope.put("javaNameGetter", topScope, new JavaNameGetter());
Script script = cx.compileString(scriptCode, "myScript", 1, null);
script.exec(cx, topScope);
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class PrimitiveTypeScopeResolutionTest method testWithTwoScopes.
private void testWithTwoScopes(final String scriptScope1, final String scriptScope2) {
final ContextAction action = new ContextAction() {
public Object run(final Context cx) {
final Scriptable scope1 = cx.initStandardObjects(new MySimpleScriptableObject("scope1"));
final Scriptable scope2 = cx.initStandardObjects(new MySimpleScriptableObject("scope2"));
cx.evaluateString(scope2, scriptScope2, "source2", 1, null);
scope1.put("scope2", scope1, scope2);
return cx.evaluateString(scope1, scriptScope1, "source1", 1, null);
}
};
Utils.runWithAllOptimizationLevels(action);
}
Aggregations