use of org.mozilla.javascript.ContextAction in project hackpad by dropbox.
the class DeletePropertyTest method testDeletePropInPrototype.
/**
* delete should not delete anything in the prototype chain.
*/
@Test
public void testDeletePropInPrototype() throws Exception {
final String script = "Array.prototype.foo = function() {};\n" + "Array.prototype[1] = function() {};\n" + "var t = [];\n" + "[].foo();\n" + "for (var i in t) delete t[i];\n" + "[].foo();\n" + "[][1]();\n";
final ContextAction action = new ContextAction() {
public Object run(final Context _cx) {
final ScriptableObject scope = _cx.initStandardObjects();
final Object result = _cx.evaluateString(scope, script, "test script", 0, null);
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of org.mozilla.javascript.ContextAction 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.ContextAction 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.ContextAction 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.ContextAction 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