use of org.mozilla.javascript.Scriptable 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();
}
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class Bug482203 method testJsApi.
public void testJsApi() throws Exception {
Context cx = Context.enter();
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(Bug482203.class.getResourceAsStream("conttest.js")), "", 1, null);
Scriptable scope = cx.initStandardObjects();
script.exec(cx, scope);
for (; ; ) {
Object cont = ScriptableObject.getProperty(scope, "c");
if (cont == null) {
break;
}
((Callable) cont).call(cx, scope, scope, new Object[] { null });
}
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class ContextFactoryTest method testCustomContextFactory.
public void testCustomContextFactory() {
ContextFactory factory = new MyFactory();
Context cx = factory.enterContext();
try {
Scriptable globalScope = cx.initStandardObjects();
// Test that FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME is enabled
/* TODO(stevey): fix this functionality in parser
Object result = cx.evaluateString(globalScope,
"var obj = {};" +
"function obj.foo() { return 'bar'; }" +
"obj.foo();",
"test source", 1, null);
assertEquals("bar", result);
*/
} catch (RhinoException e) {
fail(e.toString());
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Scriptable in project OpenAM by OpenRock.
the class RhinoScriptEngine method eval.
/**
* {@inheritDoc}
*/
@Override
public Object eval(final Reader reader, final ScriptContext scriptContext) throws ScriptException {
Reject.ifNull(reader, scriptContext);
Object result = null;
final Context context = factory.getContext();
try {
final Scriptable scope = getScope(context, scriptContext);
final String filename = getFilename(scriptContext);
result = context.evaluateReader(scope, reader, filename, 1, null);
} catch (RhinoException ex) {
throw convertException(ex);
} catch (IOException ex) {
throw new ScriptException(ex);
} finally {
factory.releaseContext(context);
}
return result;
}
use of org.mozilla.javascript.Scriptable in project OpenAM by OpenRock.
the class RhinoScriptEngine method evalCompiled.
/**
* Evaluates a pre-compiled script against this script engine. This should only be called by
* {@link org.forgerock.openam.scripting.factories.RhinoCompiledScript#eval(javax.script.ScriptContext)}.
*
* @param compiledScript The compiled script. Must not be null.
* @param scriptContext The JSR 223 script context. Must not be null.
* @return the result of evaluating the compiled script.
* @throws ScriptException if an error occurs during script execution.
*/
Object evalCompiled(final Script compiledScript, final ScriptContext scriptContext) throws ScriptException {
Reject.ifNull(compiledScript, scriptContext);
Object result = null;
final Context context = factory.getContext();
try {
final Scriptable scope = getScope(context, scriptContext);
result = compiledScript.exec(context, scope);
} catch (RhinoException ex) {
throw convertException(ex);
} finally {
factory.releaseContext(context);
}
return result;
}
Aggregations