use of org.mozilla.javascript.Scriptable 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);
}
use of org.mozilla.javascript.Scriptable 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.Scriptable 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.Scriptable 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();
}
}
use of org.mozilla.javascript.Scriptable in project hackpad by dropbox.
the class Main method processFiles.
static void processFiles(Context cx, String[] args) {
// define "arguments" array in the top-level object:
// need to allocate new array since newArray requires instances
// of exactly Object[], not ObjectSubclass[]
Object[] array = new Object[args.length];
System.arraycopy(args, 0, array, 0, args.length);
Scriptable argsObj = cx.newArray(global, array);
global.defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
for (String file : fileList) {
processSource(cx, file);
}
}
Aggregations