use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class StackTraceTest method runWithExpectedStackTrace.
private void runWithExpectedStackTrace(final String _source, final String _expectedStackTrace) {
final ContextAction action = new ContextAction() {
public Object run(Context cx) {
final Scriptable scope = cx.initStandardObjects();
try {
cx.evaluateString(scope, _source, "test.js", 0, null);
} catch (final JavaScriptException e) {
assertEquals(_expectedStackTrace, e.getScriptStackTrace());
return null;
}
throw new RuntimeException("Exception expected!");
}
};
Utils.runWithOptimizationLevel(action, -1);
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class StrictModeApiTest method testStrictModeError.
public void testStrictModeError() {
contextFactory = new MyContextFactory();
Context cx = contextFactory.enterContext();
try {
global = cx.initStandardObjects();
try {
runScript("({}.nonexistent);");
fail();
} catch (EvaluatorException e) {
assertTrue(e.getMessage().startsWith("Reference to undefined property"));
}
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Context 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.Context in project hackpad by dropbox.
the class Bug482203 method testJavaApi.
public void testJavaApi() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
Script script = cx.compileReader(new InputStreamReader(Bug482203.class.getResourceAsStream("conttest.js")), "", 1, null);
Scriptable scope = cx.initStandardObjects();
cx.executeScriptWithContinuations(script, scope);
for (; ; ) {
Object cont = ScriptableObject.getProperty(scope, "c");
if (cont == null) {
break;
}
cx.resumeContinuation(cont, scope, null);
}
} finally {
Context.exit();
}
}
use of org.mozilla.javascript.Context in project hackpad by dropbox.
the class ClassShutterExceptionTest method helper.
public void helper(String source) {
Context cx = Context.enter();
Context.ClassShutterSetter setter = cx.getClassShutterSetter();
try {
Scriptable globalScope = cx.initStandardObjects();
if (setter == null) {
setter = classShutterSetter;
} else {
classShutterSetter = setter;
}
setter.setClassShutter(new OpaqueShutter());
cx.evaluateString(globalScope, source, "test source", 1, null);
} finally {
setter.setClassShutter(null);
Context.exit();
}
}
Aggregations