use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class ContinuationsApiTest method testFunctionWithContinuations.
public void testFunctionWithContinuations() {
Context cx = Context.enter();
try {
// must use interpreter mode
cx.setOptimizationLevel(-1);
cx.evaluateString(globalScope, "function f(a) { return myObject.f(a); }", "function test source", 1, null);
Function f = (Function) globalScope.get("f", globalScope);
Object[] args = { 7 };
cx.callFunctionWithContinuations(f, globalScope, args);
fail("Should throw ContinuationPending");
} catch (ContinuationPending pending) {
Object applicationState = pending.getApplicationState();
assertEquals(7, ((Number) applicationState).intValue());
int saved = (Integer) applicationState;
Object result = cx.resumeContinuation(pending.getContinuation(), globalScope, saved + 1);
assertEquals(8, ((Number) result).intValue());
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class Bug421071Test method compileScript.
private Script compileScript() {
String scriptSource = "importPackage(java.util);\n" + "var searchmon = 3;\n" + "var searchday = 10;\n" + "var searchyear = 2008;\n" + "var searchwkday = 0;\n" + "\n" + "var myDate = Calendar.getInstance();\n // this is a java.util.Calendar" + "myDate.set(Calendar.MONTH, searchmon);\n" + "myDate.set(Calendar.DATE, searchday);\n" + "myDate.set(Calendar.YEAR, searchyear);\n" + "searchwkday.value = myDate.get(Calendar.DAY_OF_WEEK);";
Script script;
Context context = factory.enterContext();
try {
script = context.compileString(scriptSource, "testScript", 1, null);
return script;
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class Utils method runWithOptimizationLevel.
/**
* Runs the provided action at the given optimization level
*/
public static void runWithOptimizationLevel(final ContextFactory contextFactory, final ContextAction action, final int optimizationLevel) {
final Context cx = contextFactory.enterContext();
try {
cx.setOptimizationLevel(optimizationLevel);
action.run(cx);
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class ComplianceTest method createTest.
private static Test createTest(final File testDir, final String name) {
return new TestCase(name) {
@Override
public int countTestCases() {
return 1;
}
@Override
public void runBare() throws Throwable {
final Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
final Scriptable scope = cx.initStandardObjects();
ScriptableObject.putProperty(scope, "print", new Print(scope));
createRequire(testDir, cx, scope).requireMain(cx, "program");
} finally {
Context.exit();
}
}
};
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class RequireTest method testWithSandboxedRequire.
private void testWithSandboxedRequire(String moduleId) throws Exception {
final Context cx = createContext();
getSandboxedRequire(cx).requireMain(cx, moduleId);
}
Aggregations