
org.jasmine.Runtime Maven / Gradle / Ivy
package org.jasmine;
import org.dynjs.Config;
import org.dynjs.runtime.DynJS;
import org.dynjs.runtime.GlobalObject;
import org.dynjs.runtime.GlobalObjectFactory;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Sets.newTreeSet;
public class Runtime {
private final List specs;
private final ClassLoader parentClassLoader;
private final Config.CompileMode compileMode;
public Runtime(Iterable specs) {
this(specs, Config.CompileMode.JIT);
}
public Runtime(Iterable specs, Config.CompileMode compileMode) {
this(newArrayList(newTreeSet(specs)), compileMode, Thread.currentThread().getContextClassLoader());
}
public Runtime(Iterable specs, Config.CompileMode compileMode, ClassLoader parentClassLoader) {
this.parentClassLoader = parentClassLoader;
this.specs = newArrayList(newTreeSet(specs));
this.compileMode = compileMode;
}
public void execute(Notifier notifier) {
Config config = new Config(parentClassLoader);
config.setCompileMode(this.compileMode);
config.setGlobalObjectFactory(new GlobalObjectFactory() {
GlobalObject global;
@Override
public GlobalObject newGlobalObject(DynJS runtime) {
if(global == null){
global = new GlobalObject(runtime);
global.defineGlobalProperty("global", global);
}
return global;
}
});
DynJS dynjs = new DynJS(config);
Executor executor = (Executor) dynjs.evaluate("require('jasmine-jvm/executor').executor");
executor.execute(specs, notifier);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy