本文整理汇总了Java中org.mozilla.javascript.ContextFactory.getGlobal方法的典型用法代码示例。如果您正苦于以下问题:Java ContextFactory.getGlobal方法的具体用法?Java ContextFactory.getGlobal怎么用?Java ContextFactory.getGlobal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mozilla.javascript.ContextFactory
的用法示例。
在下文中一共展示了ContextFactory.getGlobal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runJsTests
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
public void runJsTests(File[] tests) throws IOException {
ContextFactory factory = ContextFactory.getGlobal();
Context cx = factory.enterContext();
try {
cx.setOptimizationLevel(this.optimizationLevel);
Scriptable shared = cx.initStandardObjects();
for (File f : tests) {
int length = (int) f.length(); // don't worry about very long
// files
char[] buf = new char[length];
new FileReader(f).read(buf, 0, length);
String session = new String(buf);
runJsTest(cx, shared, f.getName(), session);
}
} finally {
Context.exit();
}
}
示例2: runDoctest
import org.mozilla.javascript.ContextFactory; //导入方法依赖的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();
}
}
示例3: runDoctest
import org.mozilla.javascript.ContextFactory; //导入方法依赖的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: destroyMyFactory
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
public static void destroyMyFactory( )
{
ContextFactory factory = ContextFactory.getGlobal( );
if ( factory != null && factory instanceof MyFactory )
{
try
{
Class factoryClass = Class
.forName( "org.mozilla.javascript.ContextFactory" );
Field field = factoryClass.getDeclaredField( "hasCustomGlobal" );
field.setAccessible( true );
field.setBoolean( factoryClass, false );
field = factoryClass.getDeclaredField( "global" );
field.setAccessible( true );
field.set( factoryClass, new ContextFactory( ) );
}
catch ( Exception ex )
{
logger.log( Level.WARNING, ex.getMessage( ), ex );
}
}
}
示例5: getContextFactory
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
/**
* @return The Context factory which has to be used on android.
*/
@VisibleForTesting
public AndroidContextFactory getContextFactory() {
AndroidContextFactory factory;
if (!ContextFactory.hasExplicitGlobal()) {
factory = new AndroidContextFactory(cacheDirectory);
ContextFactory.getGlobalSetter().setContextFactoryGlobal(factory);
} else if (!(ContextFactory.getGlobal() instanceof AndroidContextFactory)) {
throw new IllegalStateException("Cannot initialize factory for Android Rhino: There is already another factory");
} else {
factory = (AndroidContextFactory) ContextFactory.getGlobal();
}
return factory;
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:17,代码来源:RhinoAndroidHelper.java
示例6: testReturns
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
public void testReturns() throws Exception {
ContextFactory contextFactory = ContextFactory.getGlobal();
evalJs(contextFactory, "'foo';");
evalJs(contextFactory, "'\u0fff'");
evalJs(contextFactory, "'\\u0fff'");
evalJs(contextFactory, "new java.util.ArrayList();");
evalJs(contextFactory, "[];");
evalJs(contextFactory, "0");
evalJs(contextFactory, "1;");
evalJs(contextFactory, "2");
evalJs(contextFactory, "0/0");
evalJs(contextFactory, "1/0");
evalJs(contextFactory, Integer.toString(Integer.MAX_VALUE));
evalJs(contextFactory, Long.toString(Integer.MAX_VALUE + (long) 1));
evalJs(contextFactory, "this.bar;");
evalJs(contextFactory, "null;");
evalJs(contextFactory, "zub = {};");
evalJs(contextFactory, "reb = function (){};");
evalJs(contextFactory, "new Error();");
evalJs(contextFactory, "/.*/;");
evalJs(contextFactory, "true");
evalJs(contextFactory, "new Date();");
evalJs(contextFactory, "this;");
evalJs(contextFactory, "var foo = 1.0; this.foo;");
evalJs(contextFactory,
"var foo = {}; (function bar() {var f = 1;}).call(foo);");
}
示例7: run
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
public <T> T run(Map<String, ?> actuals, Class<T> expectedResultType)
throws AbnormalExitException {
if (SANDBOXINGFACTORY != ContextFactory.getGlobal()) {
throw new IllegalStateException();
}
Context context = SANDBOXINGFACTORY.enterContext();
// Don't bother to compile tests to a class file. Removing this causes
// a 5x slow-down in Rhino-heavy tests.
context.setOptimizationLevel(-1);
try {
return runInContext(context, actuals, expectedResultType);
} finally {
Context.exit();
}
}
示例8: JavaScriptProcessor
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
/**
* Constructor which initializes a local JavaScript context. This is for security reasons to not access any
* System or application ressources but only process on parameters and variables.
*/
public JavaScriptProcessor() {
if(ContextFactory.getGlobal() == null || ContextFactory.getGlobal() instanceof SandboxContextFactory) {
ContextFactory.initGlobal(new SandboxContextFactory());
}
}
示例9: brew
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
@Override
public void brew(Brewery brewery) {
this.contextFactory = ContextFactory.getGlobal();
}
示例10: jsContextFactory
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
public ContextFactory jsContextFactory() {
return ContextFactory.getGlobal();
}
示例11: LanguageProviderRhino
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
public LanguageProviderRhino() {
factory = ContextFactory.getGlobal();
debugger = null;
}
示例12: getDebugContextFactory
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
private ContextFactory getDebugContextFactory() {
return ContextFactory.getGlobal(); // works!!!!!!!!!!
// return new ContextFactory(); // works
// return new ShellContextFactory(); // works
// return org.mozilla.javascript.tools.shell.Main.shellContextFactory; // works
}
示例13: readScripts
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
private void readScripts(List<User> userList) {
ContextFactory contextFactory = ContextFactory.getGlobal();
Context context = contextFactory.enterContext();
try {
for (User user : userList) {
Company company = new Company(this, user.getUsername(), grocer);
ThreadLocal.setCompany(company);
ScriptableObject prototype = context.initStandardObjects();
prototype.setParentScope(null);
Scriptable scope = context.newObject(prototype);
scope.setPrototype(prototype);
Object jsCompany = new SandboxNativeJavaObject(scope, company, Company.class);
prototype.put("company", scope, jsCompany);
Object jsSystemout = new SandboxNativeJavaObject(scope,
new DebugAdapter(this, gameRun.getResult(), company.getName()), DebugAdapter.class);
prototype.put("out", scope, jsSystemout);
prototype.put("console", scope, jsSystemout);
try {
long time = System.nanoTime();
context.evaluateString(scope, user.getMainJavaScript(), company.getName(), 1, null);
getResult().getCreateNotExists(company.getName()).addRunTime("init", System.nanoTime() - time);
getResult().getCreateNotExists(company.getName()).setCode(user.getMainJavaScript());
} catch (RhinoException e) {
if (e.getCause() instanceof GameException) {
log.info("Failed to initialize the JavaScript, but found a GameException", e);
} else {
String formattedStackTrace = ExceptionConverter.convertToString(e);
gameRun.getResult().addError(formattedStackTrace);
log.error("Failed to initialize the JavaScript. Player " + company.getName() + " bankrupt", e);
company.setBankruptFromError(formattedStackTrace);
}
}
companies.add(company);
}
ThreadLocal.resetCompany();
} finally {
Context.exit();
}
}
示例14: execute
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
/**
* Symbolically executes one path through the compiled program.
*
* @param rhinoContext the JavaScript scope containing the symbolic execution
* library functions
* @param script the compiled instrumented JavaScript
* @param input the arguments to pass to the entry function for symbolic
* execution
* @return the result of performing symbolic execution
*/
private SymbolicExecutionResult execute(Context rhinoContext, Script script,
Input input) {
ContextFactory contextFactory = ContextFactory.getGlobal();
Scriptable scope = rhinoContext.initStandardObjects();
scope.put("inputs", scope, input.toJSArray(contextFactory));
return new SymbolicExecutionResult(
(NativeObject) script.exec(rhinoContext, scope));
}
示例15: getContextFactory
import org.mozilla.javascript.ContextFactory; //导入方法依赖的package包/类
/**
* Returns the context factory configured in this holder, or
* {@link ContextFactory#getGlobal()} if it is null.
* @return the context factory configured in this holder.
*/
public ContextFactory getContextFactory() {
return contextFactory != null ? contextFactory : ContextFactory.getGlobal();
}