本文整理了Java中org.mozilla.javascript.Context.setOptimizationLevel()
方法的一些代码示例,展示了Context.setOptimizationLevel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.setOptimizationLevel()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:setOptimizationLevel
[英]Set the current optimization level.
The optimization level is expected to be an integer between -1 and 9. Any negative values will be interpreted as -1, and any values greater than 9 will be interpreted as 9. An optimization level of -1 indicates that interpretive mode will always be used. Levels 0 through 9 indicate that class files may be generated. Higher optimization levels trade off compile time performance for runtime performance. The optimizer level can't be set greater than -1 if the optimizer package doesn't exist at run time.
[中]设置当前优化级别。
优化级别应为-1到9之间的整数。任何负值将被解释为-1,任何大于9的值将被解释为9。优化级别为-1表示将始终使用解释模式。级别0到9表示可以生成类文件。更高的优化级别以编译时性能换取运行时性能。如果优化器包在运行时不存在,则优化器级别不能设置为大于-1。
代码示例来源:origin: apache/incubator-druid
public JavaScriptPredicateFactory(final String script, final ExtractionFn extractionFn)
{
Preconditions.checkNotNull(script, "script must not be null");
this.script = script;
this.extractionFn = extractionFn;
final Context cx = Context.enter();
try {
cx.setOptimizationLevel(9);
scope = cx.initStandardObjects();
fnApply = cx.compileFunction(scope, script, "script", 1, null);
}
finally {
Context.exit();
}
}
代码示例来源:origin: facebook/stetho
/**
* Setups a proper javascript context so that it can run javascript code properly under android.
* For android we need to disable bytecode generation since the android vms don't understand JVM bytecode.
* @return a proper javascript context
*/
static @NonNull Context enterJsContext() {
final Context jsContext = Context.enter();
// If we cause the context to throw a runtime exception from this point
// we need to make sure that exit the context.
try {
jsContext.setLanguageVersion(Context.VERSION_1_8);
// We can't let Rhino to optimize the JS and to use a JIT because it would generate JVM bytecode
// and android runs on DEX bytecode. Instead we need to go in interpreted mode.
jsContext.setOptimizationLevel(-1);
} catch (RuntimeException e) {
// Something bad happened to the javascript context but it might still be usable.
// The first thing to do is to exit the context and then propagate the error.
Context.exit();
throw e;
}
return jsContext;
}
}
代码示例来源:origin: apache/incubator-druid
private static Function compile(String function)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
final ScriptableObject scope = context.initStandardObjects();
final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
Context.exit();
return new Function()
{
@Override
public double apply(Object[] args)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
return Context.toNumber(fn.call(cx, scope, scope, args));
}
};
}
代码示例来源:origin: apache/incubator-druid
private static Function<Object, Object> compile(String function)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(9);
final ScriptableObject scope = context.initStandardObjects();
final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
Context.exit();
return new Function<Object, Object>()
{
@Override
public Object apply(Object input)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
final Object res = fn.call(cx, scope, scope, new Object[]{input});
return res != null ? Context.toObject(res, scope) : null;
}
};
}
代码示例来源:origin: apache/incubator-druid
private static Function<Object, String> compile(String function)
{
final ContextFactory contextFactory = ContextFactory.getGlobal();
final Context context = contextFactory.enterContext();
context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
final ScriptableObject scope = context.initStandardObjects();
final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null);
Context.exit();
return new Function<Object, String>()
{
@Override
public String apply(Object input)
{
// ideally we need a close() function to discard the context once it is not used anymore
Context cx = Context.getCurrentContext();
if (cx == null) {
cx = contextFactory.enterContext();
}
final Object res = fn.call(cx, scope, scope, new Object[]{input});
return res != null ? Context.toString(res) : null;
}
};
}
代码示例来源:origin: apache/incubator-druid
context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
代码示例来源:origin: pentaho/pentaho-kettle
jsscope = jscx.initStandardObjects( null, false );
try {
jscx.setOptimizationLevel( Integer.valueOf( transMeta.environmentSubstitute( optimizationLevel ) ) );
} catch ( NumberFormatException nfe ) {
error_message =
代码示例来源:origin: pentaho/pentaho-kettle
jscx.setOptimizationLevel( -1 );
jsscope = jscx.initStandardObjects( null, false );
代码示例来源:origin: pentaho/pentaho-kettle
jscx.setOptimizationLevel( -1 );
jsscope = jscx.initStandardObjects( null, false );
代码示例来源:origin: pentaho/pentaho-kettle
String optimizationLevelAsString = environmentSubstitute( meta.getOptimizationLevel() );
if ( !Utils.isEmpty( Const.trim( optimizationLevelAsString ) ) ) {
data.cx.setOptimizationLevel( Integer.parseInt( optimizationLevelAsString.trim() ) );
logBasic( BaseMessages.getString( PKG, "ScriptValuesMod.Optimization.Level", environmentSubstitute( meta
.getOptimizationLevel() ) ) );
} else {
data.cx.setOptimizationLevel( Integer.parseInt( ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT ) );
logBasic( BaseMessages.getString(
PKG, "ScriptValuesMod.Optimization.UsingDefault", ScriptValuesMetaMod.OPTIMIZATION_LEVEL_DEFAULT ) );
代码示例来源:origin: rnewson/couchdb-lucene
context.setOptimizationLevel(9);
代码示例来源:origin: com.google.code.scriptengines/scriptengines-javascript
protected Context makeContext() {
Context cx = super.makeContext();
cx.setOptimizationLevel(-1);
return cx;
}
});
代码示例来源:origin: com.atlassian.pluginkit/ringojs-kit
private Context createContext() {
Context context = Context.enter();
context.setOptimizationLevel(-1); // Without this, Rhino hits a 64K bytecode limit and fails
return context;
}
代码示例来源:origin: cat.inspiracio/rhino-js-engine
protected Context makeContext() {
Context cx = super.makeContext();
cx.setOptimizationLevel(-1);
return cx;
}
});
代码示例来源:origin: org.verapdf/core
public static synchronized ScriptableObject initialise() {
context = Context.enter();
context.setOptimizationLevel(OPTIMIZATION_LEVEL);
return context.initStandardObjects();
}
代码示例来源:origin: apache/cxf
private Object[] compileScript(Context cx, String scriptStr, Scriptable scriptScope, File f) {
int opt = cx.getOptimizationLevel();
cx.setOptimizationLevel(-1);
Script script = cx.compileString(scriptStr, f.getName(), 1, null);
script.exec(cx, scriptScope);
Object[] ids = scriptScope.getIds();
cx.setOptimizationLevel(opt);
script = cx.compileString(scriptStr, f.getName(), 1, null);
script.exec(cx, scriptScope);
return ids;
}
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-js
private Object[] compileScript(Context cx, String scriptStr, Scriptable scriptScope, File f) {
int opt = cx.getOptimizationLevel();
cx.setOptimizationLevel(-1);
Script script = cx.compileString(scriptStr, f.getName(), 1, null);
script.exec(cx, scriptScope);
Object[] ids = scriptScope.getIds();
cx.setOptimizationLevel(opt);
script = cx.compileString(scriptStr, f.getName(), 1, null);
script.exec(cx, scriptScope);
return ids;
}
代码示例来源:origin: net.sourceforge.purrpackage/purrpackage
synchronized void init() {
if ( ! inited ) {
Context c = Context.enter();
c.setOptimizationLevel( -1 );
Global g = Main.getGlobal();
g.init( c );
inited = true;
}
}
代码示例来源:origin: com.github.tntim96/rhino
/**
* Called when a Context is created.
*/
public void contextCreated(Context cx) {
if (type != IPROXY_LISTEN) Kit.codeBug();
ContextData contextData = new ContextData();
Debugger debugger = new DimIProxy(dim, IPROXY_DEBUG);
cx.setDebugger(debugger, contextData);
cx.setGeneratingDebug(true);
cx.setOptimizationLevel(-1);
}
代码示例来源:origin: io.apisense/rhino-android
/**
* Create new Context instance to be associated with the current thread.
*/
@Override
protected Context makeContext() {
Context cx = super.makeContext();
cx.setLanguageVersion(languageVersion);
cx.setOptimizationLevel(optimizationLevel);
cx.setClassShutter(RhinoClassShutter.getInstance());
cx.setWrapFactory(RhinoWrapFactory.getInstance());
return cx;
}
内容来源于网络,如有侵权,请联系作者删除!