本文整理汇总了Java中org.mozilla.javascript.tools.shell.Global类的典型用法代码示例。如果您正苦于以下问题:Java Global类的具体用法?Java Global怎么用?Java Global使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Global类属于org.mozilla.javascript.tools.shell包,在下文中一共展示了Global类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runDoctest
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@Test
public void runDoctest() throws Exception {
ContextFactory factory = ContextFactory.getGlobal();
Context cx = factory.enterContext();
try {
cx.setOptimizationLevel(optimizationLevel);
Global global = new Global(cx);
// global.runDoctest throws an exception on any failure
int testsPassed = global.runDoctest(cx, global, source, name, 1);
System.out.println(name + "(" + optimizationLevel + "): " +
testsPassed + " passed.");
assertTrue(testsPassed > 0);
} catch (Exception ex) {
System.out.println(name + "(" + optimizationLevel + "): FAILED due to "+ex);
throw ex;
} finally {
Context.exit();
}
}
示例2: runDoctest
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@Test
public void runDoctest() throws Exception {
Context cx = RhinoAndroidHelper.prepareContext();
try {
cx.setOptimizationLevel(optimizationLevel);
Global global = new Global(cx);
TestUtils.addAssetLoading(global);
// global.runDoctest throws an exception on any failure
int testsPassed = global.runDoctest(cx, global, source, name, 1);
System.out.println(name + "(" + optimizationLevel + "): " +
testsPassed + " passed.");
assertTrue(testsPassed > 0);
} catch (Exception ex) {
System.out.println(name + "(" + optimizationLevel + "): FAILED due to "+ex);
throw ex;
} finally {
Context.exit();
}
}
示例3: runDoctest
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@Test
public void runDoctest() throws Exception {
ContextFactory factory = ContextFactory.getGlobal();
Context cx = factory.enterContext();
try {
cx.setOptimizationLevel(optimizationLevel);
Global global = new Global(cx);
// global.runDoctest throws an exception on any failure
int testsPassed = global.runDoctest(cx, global, source, name, 1);
System.out.println(name + "(" + optimizationLevel + "): " +
testsPassed + " passed.");
assertTrue(testsPassed > 0);
} catch (Exception ex) {
System.out.println(name + "(" + optimizationLevel + "): FAILED due to "+ex);
throw ex;
} finally {
Context.exit();
}
}
示例4: init
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
protected void init() throws Exception {
context = Context.enter();
global = new Global();
global.init(context);
ScriptableObject.defineClass(global, ScriptableMessage.class);
ScriptableObject.defineClass(global, ScriptableIMC.class);
Object o = Context.javaToJS(new ScriptableConsole(), global);
ScriptableObject.putProperty(global, "console", o);
o = Context.javaToJS(new ScriptableGui(), global);
ScriptableObject.putProperty(global, "gui", o);
Scriptable imc = context.newObject(global, "IMC", null);
global.put("imc", global, imc);
}
示例5: mainEmbedded
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
/**
* Entry point for embedded applications. This method attaches
* to the global {@link ContextFactory} with a scope of a newly
* created {@link Global} object. No I/O redirection is performed
* as with {@link #main(String[])}.
*/
public static Main mainEmbedded(String title) {
ContextFactory factory = ContextFactory.getGlobal();
Global global = new Global();
global.init(factory);
return mainEmbedded(factory, global, title);
}
示例6: mainEmbeddedImpl
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
/**
* Helper method for {@link #mainEmbedded(String)}, etc.
*/
private static Main mainEmbeddedImpl(ContextFactory factory,
Object scopeProvider,
String title) {
if (title == null) {
title = "Rhino JavaScript Debugger (embedded usage)";
}
Main main = new Main(title);
main.doBreak();
main.setExitAction(new IProxy(IProxy.EXIT_ACTION));
main.attachTo(factory);
if (scopeProvider instanceof ScopeProvider) {
main.setScopeProvider((ScopeProvider)scopeProvider);
} else {
Scriptable scope = (Scriptable)scopeProvider;
if (scope instanceof Global) {
Global global = (Global)scope;
global.setIn(main.getIn());
global.setOut(main.getOut());
global.setErr(main.getErr());
}
main.setScope(scope);
}
main.pack();
main.setSize(600, 460);
main.setVisible(true);
return main;
}
示例7: loadAsset
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
public static void loadAsset(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
for (Object arg : args) {
String file = Context.toString(arg);
Global.load(cx, thisObj, new Object[]{copyFromAssets(file)}, funObj);
}
}
示例8: create
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@BeforeExperiment
@SuppressWarnings("unused")
void create()
throws IOException
{
cx = Context.enter();
cx.setOptimizationLevel(optLevel);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = new Global(cx);
for (String bn : BENCHMARKS) {
compileScript(cx, bn);
}
}
示例9: create
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@BeforeExperiment
@SuppressWarnings("unused")
void create()
throws IOException
{
cx = Context.enter();
cx.setOptimizationLevel(optLevel);
cx.setLanguageVersion(Context.VERSION_ES6);
scope = new Global(cx);
runCode(cx, scope, "testsrc/benchmarks/caliper/fieldTests.js");
Object[] sarray = new Object[stringKeys];
for (int i = 0; i < stringKeys; i++) {
int len = rand.nextInt(49) + 1;
char[] c = new char[len];
for (int cc = 0; cc < len; cc++) {
c[cc] = (char) ('a' + rand.nextInt(25));
}
sarray[i] = new String(c);
}
strings = cx.newArray(scope, sarray);
Object[] iarray = new Object[intKeys];
for (int i = 0; i < intKeys; i++) {
iarray[i] = rand.nextInt(10000);
}
ints = cx.newArray(scope, iarray);
}
示例10: runTest
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
private void runTest(int optLevel)
throws IOException
{
Context cx = RhinoAndroidHelper.prepareContext();
cx.setLanguageVersion(Context.VERSION_1_8);
cx.setOptimizationLevel(optLevel);
Global root = new Global(cx);
TestUtils.addAssetLoading(root);
root.put("RUN_NAME", root, "V8-Benchmark-" + optLevel);
Object result = cx.evaluateString(root, TestUtils.readAsset(TEST_SRC), TEST_SRC, 1, null);
results.put(optLevel, result.toString());
}
示例11: runTest
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
private void runTest(int optLevel)
throws IOException
{
Context cx = RhinoAndroidHelper.prepareContext();
cx.setLanguageVersion(Context.VERSION_1_8);
cx.setOptimizationLevel(optLevel);
Global root = new Global(cx);
TestUtils.addAssetLoading(root);
root.put("RUN_NAME", root, "SunSpider-" + optLevel);
Object result = cx.evaluateString(root, TestUtils.readAsset(TEST_SRC), TEST_SRC, 1, null);
results.put(optLevel, result.toString());
}
示例12: init
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@Before
public void init()
{
cx = RhinoAndroidHelper.prepareContext();
cx.setLanguageVersion(Context.VERSION_1_8);
cx.setGeneratingDebug(true);
Global global = new Global(cx);
TestUtils.addAssetLoading(global);
root = cx.newObject(global);
}
示例13: readFile
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
@JsScriptFuntion
public static Object readFile(Context cx, Scriptable thisObj,
Object[] args, Function funObj) throws IOException
{
List<File> dirList = readOnDirs;
for (int i = 0; i < args.length; i++) {
String filename = Context.toString(args[i]);
if (!isPathInsideOneOfListedDirs(dirList, filename)) {
throw new RuntimeException("File " + filename
+ " must be inside on one of those dirs: " + dirList);
}
}
return Global.readFile(cx, thisObj, args, funObj);
}
示例14: run
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
public Object run(Context context) {
try {
Global global = new Global(context); // 参考注意事项2
InputStream ins = new FileInputStream(file);
Reader reader = new InputStreamReader(ins);
Object result = context.evaluateReader(global, reader, file.getName(), 1, null);
return Context.toString(result);
} catch (Exception e) {
LogUtil.exception(e);
}
return "!!!ERROR!!!";
}
示例15: RhinoEngine
import org.mozilla.javascript.tools.shell.Global; //导入依赖的package包/类
public <T> RhinoEngine(final RhinoProperties rhinoProperties) {
this.executorService = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Preconditions.checkState(executionThread == null, "Only one thread is supported");
executionThread = FACTORY.newThread(r);
return executionThread;
}
});
// this ensures a single thread for this engine
runWithContext(new RhinoCallable<Void, RuntimeException>() {
@Override
protected Void doCall(Context cx, Scriptable s) {
try {
Global global = new Global(cx);
RequireProperties require = rhinoProperties.getRequire();
if (require != null) {
List<String> modulePathURIs = getModulePathURIs(require);
LOGGER.debug("Module paths: {}", modulePathURIs);
global.installRequire(cx, modulePathURIs, require.isSandboxed());
}
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
// we need to load compat/timeout.js because rhino does not have setTimeout, setInterval, etc.
try (Reader in = new InputStreamReader(classloader.getResourceAsStream("compat/timeout.js"))) {
cx.evaluateReader(global, in, "compat/timeout.js", 1, null);
}
scope = global;
prototype = new NativeObject();
scope.put("__prototype", scope, prototype);
return null;
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
});
}