use of org.mozilla.javascript.ScriptableObject 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.ScriptableObject in project hackpad by dropbox.
the class Bug448816Test method setUp.
@SuppressWarnings("unchecked")
@Override
protected void setUp() {
// set up a reference map
reference = new LinkedHashMap<Object, Object>();
reference.put("a", "a");
reference.put("b", Boolean.TRUE);
reference.put("c", new HashMap<Object, Object>());
reference.put(new Integer(1), new Integer(42));
// get a js object as map
Context context = Context.enter();
ScriptableObject scope = context.initStandardObjects();
map = (Map<Object, Object>) context.evaluateString(scope, "({ a: 'a', b: true, c: new java.util.HashMap(), 1: 42});", "testsrc", 1, null);
Context.exit();
}
use of org.mozilla.javascript.ScriptableObject in project stetho by facebook.
the class JsRuntimeReplFactoryBuilder method initJsScope.
@NonNull
private ScriptableObject initJsScope(@NonNull Context jsContext) {
// Set the main Rhino goodies
ImporterTopLevel importerTopLevel = new ImporterTopLevel(jsContext);
ScriptableObject scope = jsContext.initStandardObjects(importerTopLevel, false);
ScriptableObject.putProperty(scope, "context", Context.javaToJS(mContext, scope));
try {
importClasses(jsContext, scope);
importPackages(jsContext, scope);
importConsole(scope);
importVariables(scope);
importFunctions(scope);
} catch (StethoJsException e) {
String message = String.format("%s\n%s", e.getMessage(), Log.getStackTraceString(e));
LogUtil.e(e, message);
CLog.writeToConsole(Console.MessageLevel.ERROR, Console.MessageSource.JAVASCRIPT, message);
}
return scope;
}
use of org.mozilla.javascript.ScriptableObject in project gocd by gocd.
the class JsonTester method parseMap.
private static Map<String, Object> parseMap(ScriptableObject o) {
Map<String, Object> jsonMap = new LinkedHashMap<>();
for (Object basicId : o.getIds()) {
String id = valueOf(basicId);
jsonMap.put(id, parse(o.get(id, o)));
}
return jsonMap;
}
use of org.mozilla.javascript.ScriptableObject in project jslint4java by happygiraffe.
the class JSLintBuilder method fromReader.
/**
* Initialize the scope with an arbitrary jslint.
*
* @param reader
* an input source providing jslint.js.
* @param name
* the name of the resource backed by the reader
* @return a configured {@link JSLint}
* @throws IOException
* if there are any problems reading from {@code reader} .
*/
@NeedsContext
public JSLint fromReader(Reader reader, String name) throws IOException {
try {
Context cx = contextFactory.enterContext();
ScriptableObject scope = cx.initStandardObjects();
cx.evaluateReader(scope, reader, name, 1, null);
Function lintFunc = (Function) scope.get("JSLINT", scope);
return new JSLint(contextFactory, lintFunc);
} finally {
Context.exit();
}
}
Aggregations