use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class TypeOfTest method doTest.
private void doTest(String expected, final String script) {
final ContextAction action = new ContextAction() {
public Object run(final Context context) {
final Scriptable scope = context.initStandardObjects();
return context.evaluateString(scope, script, "test script", 1, null);
}
};
doTest(expected, action);
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class Utils method executeScript.
/**
* Execute the provided script in a fresh context as "myScript.js".
* @param script the script code
*/
static void executeScript(final String script, final int optimizationLevel) {
final ContextAction action = new ContextAction() {
public Object run(Context cx) {
final Scriptable scope = cx.initStandardObjects();
return cx.evaluateString(scope, script, "myScript.js", 1, null);
}
};
Utils.runWithOptimizationLevel(action, optimizationLevel);
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class RequireTest method testNonSandboxed.
public void testNonSandboxed() throws Exception {
final Context cx = createContext();
final Scriptable scope = cx.initStandardObjects();
final Require require = getSandboxedRequire(cx, scope, false);
final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm();
ScriptableObject.putProperty(scope, "moduleUri", jsFile);
require.requireMain(cx, "testNonSandboxed");
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class JsTestsBase method runJsTest.
public void runJsTest(Context cx, Scriptable shared, String name, String source) {
// create a lightweight top-level scope
Scriptable scope = cx.newObject(shared);
scope.setPrototype(shared);
System.out.print(name + ": ");
Object result;
try {
result = cx.evaluateString(scope, source, "jstest input", 1, null);
} catch (RuntimeException e) {
System.out.println("FAILED");
throw e;
}
assertTrue(result != null);
assertTrue("success".equals(result));
System.out.println("passed");
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class JsTestsBase method runJsTests.
public void runJsTests(File[] tests) throws IOException {
ContextFactory factory = ContextFactory.getGlobal();
Context cx = factory.enterContext();
try {
cx.setOptimizationLevel(this.optimizationLevel);
Scriptable shared = cx.initStandardObjects();
for (File f : tests) {
// don't worry about very long
int length = (int) f.length();
// files
char[] buf = new char[length];
new FileReader(f).read(buf, 0, length);
String session = new String(buf);
runJsTest(cx, shared, f.getName(), session);
}
} finally {
Context.exit();
}
}
Aggregations