本文整理匯總了Java中org.mozilla.javascript.Context.getCurrentContext方法的典型用法代碼示例。如果您正苦於以下問題:Java Context.getCurrentContext方法的具體用法?Java Context.getCurrentContext怎麽用?Java Context.getCurrentContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Context
的用法示例。
在下文中一共展示了Context.getCurrentContext方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ensureScopePresent
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private void ensureScopePresent()
{
if (scope == null)
{
// Create a scope for the value conversion. This scope will be an empty scope exposing basic Object and Function, sufficient for value-conversion.
// In case no context is active for the current thread, we can safely enter end exit one to get hold of a scope
Context ctx = Context.getCurrentContext();
boolean closeContext = false;
if (ctx == null)
{
ctx = Context.enter();
closeContext = true;
}
scope = ctx.initStandardObjects();
scope.setParentScope(null);
if (closeContext)
{
// Only an exit call should be done when context didn't exist before
Context.exit();
}
}
}
示例2: getScope
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
private ScriptableObject getScope()
{
// Create a scope for the value conversion. This scope will be an empty scope exposing basic Object and Function, sufficient for value-conversion.
// In case no context is active for the current thread, we can safely enter end exit one to get hold of a scope
ScriptableObject scope;
Context ctx = Context.getCurrentContext();
boolean closeContext = false;
if (ctx == null)
{
ctx = Context.enter();
closeContext = true;
}
scope = ctx.initStandardObjects();
scope.setParentScope(null);
if (closeContext)
{
Context.exit();
}
return scope;
}
示例3: jsFunction_include
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
public void jsFunction_include(final Scriptable scope, String scriptName) throws Exception {
final Context cx = Context.getCurrentContext();
if (scriptName.charAt(0) != '/') {
// relative script name -- resolve it against currently executing
// script's directory
String pathPrefix = currentScriptDirectory;
while (scriptName.startsWith("../")) {
final int lastSlash = pathPrefix.lastIndexOf('/');
if (lastSlash == -1) {
throw new FileNotFoundException("script:" + currentScriptDirectory + '/' + scriptName);
}
scriptName = scriptName.substring(3);
pathPrefix = pathPrefix.substring(0, lastSlash);
}
scriptName = pathPrefix + '/' + scriptName;
} else {
// strip off leading slash
scriptName = scriptName.substring(1);
}
final Script script = scriptStorage.getScript(scriptName);
if (script == null) {
throw new FileNotFoundException("script:" + scriptName);
}
try {
final String oldScriptDirectory = currentScriptDirectory;
currentScriptDirectory = getDirectoryForScript(scriptName);
try {
script.exec(cx, scope);
} finally {
currentScriptDirectory = oldScriptDirectory;
}
} finally {
}
}
示例4: getHandler
import org.mozilla.javascript.Context; //導入方法依賴的package包/類
/**
* get the (cached) handler Function for this event Handler
* on first access compile the function
* @return
*/
Function getHandler() {
if (_handler == null) {
String attribute = _baseElement.getAttributeWithNoDefault( _handlerName );
if (attribute != null && Context.getCurrentContext() != null) {
_handler = Context.getCurrentContext().compileFunction( _baseElement, "function " + AbstractDomComponent.createAnonymousFunctionName() + "() { " + attribute + "}", "httpunit", 0, null );
}
}
return _handler;
}