use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class ApplyOnPrimitiveNumberTest method testIt.
public void testIt() {
final String script = "var fn = function() { return this; }\n" + "fn.apply(1)";
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);
assertEquals("object", ScriptRuntime.typeof(result));
assertEquals("1", Context.toString(result));
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class ArrayConcatTest method testArrayConcat.
public void testArrayConcat() {
final String script = "var a = ['a0', 'a1'];\n" + "a[3] = 'a3';\n" + "var b = ['b1', 'b2'];\n" + "b.concat(a)";
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);
assertEquals("b1,b2,a0,a1,,a3", Context.toString(result));
return null;
}
};
Utils.runWithAllOptimizationLevels(action);
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class Bug421071Test method createGlobalScope.
private TopLevelScope createGlobalScope() {
factory = new DynamicScopeContextFactory();
Context context = factory.enterContext();
// noinspection deprecation
TopLevelScope globalScope = new TopLevelScope(context);
Context.exit();
return globalScope;
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class Bug466207Test method setUp.
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
// set up a reference map
reference = new ArrayList<Object>();
reference.add("a");
reference.add(Boolean.TRUE);
reference.add(new HashMap<Object, Object>());
reference.add(new Integer(42));
reference.add("a");
// get a js object as map
Context context = Context.enter();
ScriptableObject scope = context.initStandardObjects();
list = (List<Object>) context.evaluateString(scope, "(['a', true, new java.util.HashMap(), 42, 'a']);", "testsrc", 1, null);
Context.exit();
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class Bug467396Test method testOverloadedVarargs.
public void testOverloadedVarargs() {
Context cx = ContextFactory.getGlobal().enterContext();
try {
Scriptable scope = cx.initStandardObjects();
Object result = unwrap(cx.evaluateString(scope, "java.lang.reflect.Array.newInstance(java.lang.Object, 1)", "source", 1, null));
assertTrue(result instanceof Object[]);
assertEquals(1, ((Object[]) result).length);
result = unwrap(cx.evaluateString(scope, "java.lang.reflect.Array.newInstance(java.lang.Object, [1])", "source", 1, null));
assertTrue(result instanceof Object[]);
assertEquals(1, ((Object[]) result).length);
result = unwrap(cx.evaluateString(scope, "java.lang.reflect.Array.newInstance(java.lang.Object, [1, 1])", "source", 1, null));
assertTrue(result instanceof Object[][]);
assertEquals(1, ((Object[][]) result).length);
assertEquals(1, ((Object[][]) result)[0].length);
result = unwrap(cx.evaluateString(scope, "java.lang.reflect.Array.newInstance(java.lang.Object, 1, 1)", "source", 1, null));
assertTrue(result instanceof Object[][]);
assertEquals(1, ((Object[][]) result).length);
assertEquals(1, ((Object[][]) result)[0].length);
} finally {
Context.exit();
}
}
Aggregations