本文整理了Java中org.mozilla.javascript.Context.setLanguageVersion()
方法的一些代码示例,展示了Context.setLanguageVersion()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context.setLanguageVersion()
方法的具体详情如下:
包路径:org.mozilla.javascript.Context
类名称:Context
方法名:setLanguageVersion
[英]Set the language version.
Setting the language version will affect functions and scripts compiled subsequently. See the overview documentation for version-specific behavior.
[中]设置语言版本。
设置语言版本将影响随后编译的函数和脚本。有关特定于版本的行为,请参阅概述文档。
代码示例来源: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: rnewson/couchdb-lucene
public DocumentConverter(final Context context, final View view) throws IOException, JSONException {
this.context = context;
scope = context.initStandardObjects();
context.setLanguageVersion(Context.VERSION_1_8);
// Allow custom document helper class.
try {
ScriptableObject.defineClass(scope, RhinoDocument.class);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
// Add a log object
ScriptableObject.putProperty(scope, "log", new JSLog());
// Compile user-specified function
try {
viewFun = view.compileFunction(context, scope);
} catch (final RhinoException e) {
LOG.error("View code for " + view + " does not compile.");
throw e;
}
}
代码示例来源:origin: com.sun.phobos/phobos-rhino
/**
* Create a new Context.
*
* Note that the Context must be associated with a thread before
* it can be used to execute a script.
*
* @see #enter()
* @see #call(ContextAction)
*/
public Context()
{
setLanguageVersion(VERSION_DEFAULT);
optimizationLevel = codegenClass != null ? 0 : -1;
maximumInterpreterStackDepth = Integer.MAX_VALUE;
}
代码示例来源:origin: rhino/js
/**
* Creates a new context. Provided as a preferred super constructor for
* subclasses in place of the deprecated default public constructor.
* @param factory the context factory associated with this context (most
* likely, the one that created the context). Can not be null. The context
* features are inherited from the factory, and the context will also
* otherwise use its factory's services.
* @throws IllegalArgumentException if factory parameter is null.
*/
protected Context(ContextFactory factory)
{
if(factory == null) {
throw new IllegalArgumentException("factory == null");
}
this.factory = factory;
setLanguageVersion(VERSION_DEFAULT);
optimizationLevel = codegenClass != null ? 0 : -1;
maximumInterpreterStackDepth = Integer.MAX_VALUE;
}
代码示例来源:origin: org.geoserver.script/gs-script-js
/**
* Associate a context with the current thread. This calls Context.enter() and sets the language
* version to 1.8.
*
* @return a Context associated with the thread
*/
public static Context enterContext() {
Context cx = Context.enter();
cx.setLanguageVersion(Context.VERSION_1_8);
return cx;
}
}
代码示例来源:origin: org.apache.sling/org.apache.sling.scripting.javascript
@Override
protected Context makeContext() {
Context context = new SlingContext();
context.setLanguageVersion(languageVersion);
return context;
}
代码示例来源:origin: stackoverflow.com
Context ctx = Context.enter();
ctx.setLanguageVersion(Context.VERSION_1_7);
try {
CompilerEnvirons compEnv = new CompilerEnvirons();
compEnv.initFromContext(ctx);
...
}
finally { Context.exit(); }
代码示例来源:origin: stackoverflow.com
int optimisationLevel = 3;
int languageVersion = Context.VERSION_1_7;
try {
Context cx = Context.enter();
cx.setOptimizationLevel(optimisationLevel);
cx.setLanguageVersion(languageVersion);
ImporterTopLevel scope = new ImporterTopLevel(cx);
cx.evaluateString(scope, TEST_SCRIPT1, "doTest", 1, null);
for (int i = 0; i < 10; i++)
cx.evaluateString(scope, "doTest();", "", 1, null);
} finally {
Context.exit();
}
代码示例来源:origin: org.zkoss.maven/yuicompressor-maven-plugin-zk
/**
* Get and set the language version.
*
* This method is defined as a JavaScript function.
*/
public static double version(Context cx, Scriptable thisObj, Object[] args, Function funObj) {
double result = cx.getLanguageVersion();
if (args.length > 0) {
double d = Context.toNumber(args[0]);
cx.setLanguageVersion((int) d);
}
return result;
}
代码示例来源:origin: com.github.tntim96/rhino
/**
* Get and set the language version.
*
* This method is defined as a JavaScript function.
*/
public static double version(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
double result = cx.getLanguageVersion();
if (args.length > 0) {
double d = Context.toNumber(args[0]);
cx.setLanguageVersion((int) d);
}
return result;
}
代码示例来源:origin: ro.isdc.wro4j/rhino
/**
* Get and set the language version.
*
* This method is defined as a JavaScript function.
*/
public static double version(Context cx, Scriptable thisObj,
Object[] args, Function funObj)
{
double result = cx.getLanguageVersion();
if (args.length > 0) {
double d = Context.toNumber(args[0]);
cx.setLanguageVersion((int) d);
}
return result;
}
代码示例来源:origin: stackoverflow.com
public class MyContextFactory extends ContextFactory {
protected Context makeContext() {
Context cx = new MyContext(this);
cx.setOptimizationLevel(0);
cx.setLanguageVersion(Context.VERSION_1_8);
cx.setInstructionObserverThreshold(100000);
return cx;
}
}
代码示例来源:origin: alexo/wro4j
/**
* Initialize the context.
*/
private ScriptableObject createContext(final ScriptableObject initialScope) {
final Context context = getContext();
context.setOptimizationLevel(-1);
// TODO redirect errors from System.err to LOG.error()
context.setErrorReporter(new ToolErrorReporter(false));
context.setLanguageVersion(Context.VERSION_1_8);
InputStream script = null;
final ScriptableObject scriptCommon = (ScriptableObject) context.initStandardObjects(initialScope);
try {
script = getClass().getResourceAsStream("commons.js");
context.evaluateReader(scriptCommon, new InputStreamReader(script), "commons.js", 1, null);
} catch (final IOException e) {
throw new RuntimeException("Problem while evaluationg commons script.", e);
} finally {
IOUtils.closeQuietly(script);
}
return scriptCommon;
}
代码示例来源:origin: org.hibnet/webpipes-rhino
protected Context enterContext() {
Context context = Context.enter();
context.setOptimizationLevel(-1);
// TODO redirect errors from System.err to LOG.error()
context.setErrorReporter(new ToolErrorReporter(false));
context.setLanguageVersion(Context.VERSION_1_8);
return context;
}
代码示例来源:origin: ro.isdc.wro4j/rhino
@Override
protected void onContextCreated(Context cx)
{
cx.setLanguageVersion(languageVersion);
cx.setOptimizationLevel(optimizationLevel);
if (errorReporter != null) {
cx.setErrorReporter(errorReporter);
}
cx.setGeneratingDebug(generatingDebug);
super.onContextCreated(cx);
}
代码示例来源:origin: com.github.tntim96/rhino
@Override
protected void onContextCreated(Context cx)
{
cx.setLanguageVersion(languageVersion);
cx.setOptimizationLevel(optimizationLevel);
if (errorReporter != null) {
cx.setErrorReporter(errorReporter);
}
cx.setGeneratingDebug(generatingDebug);
super.onContextCreated(cx);
}
代码示例来源:origin: org.juzu/juzu-plugins-less
public Rhino1_7R3Context()
{
Context ctx = Context.enter();
try
{
ctx.setOptimizationLevel(1);
ctx.setLanguageVersion(Context.VERSION_1_7);
//
Global global = new Global();
global.init(ctx);
this.global = global;
this.ctx = ctx;
this.scope = ctx.initStandardObjects(global);
this.classCache = new HashMap<String, Class<?>>();
this.codeCache = new HashMap<String, byte[]>();
}
finally
{
Context.exit();
}
}
代码示例来源:origin: juzu/juzu
public Rhino1_7R3Context()
{
Context ctx = Context.enter();
try
{
ctx.setOptimizationLevel(1);
ctx.setLanguageVersion(Context.VERSION_1_7);
//
Global global = new Global();
global.init(ctx);
this.global = global;
this.ctx = ctx;
this.scope = ctx.initStandardObjects(global);
this.classCache = new HashMap<String, Class<?>>();
this.codeCache = new HashMap<String, byte[]>();
}
finally
{
Context.exit();
}
}
代码示例来源: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;
}
代码示例来源:origin: de.matrixweb.smaller/javascript
private void init(final Class<?> clazz) {
final Context context = Context.enter();
context.setOptimizationLevel(this.optimizationLevel);
context.setLanguageVersion(Context.VERSION_1_7);
final ScriptableObject scope = context.initStandardObjects();
final Require require = new Require(Context.getCurrentContext(), scope,
getModuleScriptProvider(clazz), null, null, false);
require.install(scope);
try {
this.moduleScope = new ModuleScope(scope, new URI("./" + this.name), null);
} catch (final URISyntaxException e) {
throw new SmallerException("Failed to create moduleScope", e);
}
addGlobalFunction("print", LOGGER, "info");
}
内容来源于网络,如有侵权,请联系作者删除!