本文整理匯總了Java中org.mozilla.javascript.Context.getOptimizationLevel方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getOptimizationLevel方法的具體用法?Java Context.getOptimizationLevel怎麽用?Java Context.getOptimizationLevel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.getOptimizationLevel方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processFileSecure
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
static void processFileSecure(Context cx, Scriptable scope,
String path, Object securityDomain)
throws IOException {
boolean isClass = path.endsWith(".class");
Object source = readFileOrUrl(path, !isClass);
byte[] digest = getDigest(source);
String key = path + "_" + cx.getOptimizationLevel();
ScriptReference ref = scriptCache.get(key, digest);
Script script = ref != null ? ref.get() : null;
if (script == null) {
if (isClass) {
script = loadCompiledScript(cx, path, (byte[]) source, securityDomain);
} else {
String strSrc = (String) source;
// Support the executable script #! syntax: If
// the first line begins with a '#', treat the whole
// line as a comment.
if (strSrc.length() > 0 && strSrc.charAt(0) == '#') {
for (int i = 1; i != strSrc.length(); ++i) {
int c = strSrc.charAt(i);
if (c == '\n' || c == '\r') {
strSrc = strSrc.substring(i);
break;
}
}
}
script = cx.compileString(strSrc, path, 1, securityDomain);
}
scriptCache.put(key, digest, script);
}
if (script != null) {
script.exec(cx, scope);
}
}
示例2: preHandle
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
@Override
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler)
throws Exception {
final Context cx = getContextFactory().enterContext();
if (cx.getOptimizationLevel() != -1) {
cx.setOptimizationLevel(-1);
}
return true;
}
示例3: processFileSecure
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
static void processFileSecure(Context cx, Scriptable scope,
String path, Object securityDomain) {
boolean isClass = path.endsWith(".class");
Object source = readFileOrUrl(path, !isClass);
if (source == null) {
exitCode = EXITCODE_FILE_NOT_FOUND;
return;
}
byte[] digest = getDigest(source);
String key = path + "_" + cx.getOptimizationLevel();
ScriptReference ref = scriptCache.get(key, digest);
Script script = ref != null ? ref.get() : null;
if (script == null) {
if (isClass) {
script = loadCompiledScript(cx, path, (byte[])source, securityDomain);
} else {
String strSrc = (String) source;
// Support the executable script #! syntax: If
// the first line begins with a '#', treat the whole
// line as a comment.
if (strSrc.length() > 0 && strSrc.charAt(0) == '#') {
for (int i = 1; i != strSrc.length(); ++i) {
int c = strSrc.charAt(i);
if (c == '\n' || c == '\r') {
strSrc = strSrc.substring(i);
break;
}
}
}
script = loadScriptFromSource(cx, strSrc, path, 1, securityDomain);
}
scriptCache.put(key, digest, script);
}
if (script != null) {
evaluateScript(script, cx, scope);
}
}