本文整理匯總了Java中org.mozilla.javascript.Function.getParentScope方法的典型用法代碼示例。如果您正苦於以下問題:Java Function.getParentScope方法的具體用法?Java Function.getParentScope怎麽用?Java Function.getParentScope使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.mozilla.javascript.Function
的用法示例。
在下文中一共展示了Function.getParentScope方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import org.mozilla.javascript.Function; //導入方法依賴的package包/類
/**
* Calls JavaScript native function.
*
* @param function Function to be called.
* @param args Call arguments.
*/
public static void call(final Function function, final Object... args) {
Scriptable scope = function.getParentScope();
ObjectTopLevel topLevel = JavaScriptEngine.getObjectTopLevel(scope);
if (topLevel != null) {
Context cx = topLevel.getBrowserScriptEngine().enterContext();
try {
function.call(cx, scope, scope, args);
} catch (Exception ex) {
try {
JavaScriptEngine.throwWrappedScriptException(ex);
} catch (ScriptException e) {
throw new WrappedException(e);
}
} finally {
Context.exit();
}
}
}
示例2: call
import org.mozilla.javascript.Function; //導入方法依賴的package包/類
private Object call(Function func, Object[] args) {
Context cx = Context.getCurrentContext();
Scriptable thisObj = getAdaptee();
Scriptable scope = func.getParentScope();
try {
return func.call(cx, scope, thisObj, args);
} catch (RhinoException re) {
throw Context.reportRuntimeError(re.getMessage());
}
}
示例3: invoke
import org.mozilla.javascript.Function; //導入方法依賴的package包/類
private Object invoke(Object thiz, String name, Object... args)
throws ScriptException, NoSuchMethodException {
Context cx = enterContext();
try {
if (name == null) {
throw new NullPointerException("method name is null");
}
if (thiz != null && !(thiz instanceof Scriptable)) {
thiz = Context.toObject(thiz, topLevel);
}
Scriptable engineScope = getRuntimeScope(context);
Scriptable localScope = (thiz != null)? (Scriptable) thiz :
engineScope;
Object obj = ScriptableObject.getProperty(localScope, name);
if (! (obj instanceof Function)) {
throw new NoSuchMethodException("no such method: " + name);
}
Function func = (Function) obj;
Scriptable scope = func.getParentScope();
if (scope == null) {
scope = engineScope;
}
Object result = func.call(cx, scope, localScope,
wrapArguments(args));
return unwrapReturnValue(result);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
throw new ScriptException(re.toString(), re.sourceName(), line);
} finally {
Context.exit();
}
}
示例4: call
import org.mozilla.javascript.Function; //導入方法依賴的package包/類
/**
* Calls JavaScript native function.
*
* @param function Function to be called.
* @param args Call arguments.
*/
public static void call(final Function function, final Object... args) {
// FIXME?: Should not be here an origin check?
Scriptable scope = function.getParentScope();
ObjectTopLevel topLevel = WindowJavaScriptEngine.getObjectTopLevel(scope);
if (topLevel == null) {
throw new InternalException("Top level scope is null");
}
BrowserScriptEngine engine = topLevel.getBrowserScriptEngine();
WindowScriptEngine windowEngine = null;
if (engine instanceof WindowScriptEngine) {
windowEngine = (WindowScriptEngine)engine;
} else {
throw new InternalException("Scripting engine is not WindowScriptEngine");
}
Window window = windowEngine.getWindow();
WindowScriptSettings settings = window.getScriptSettings();
Html5DocumentImpl document = window.getDocumentImpl();
final URL address = document.getAddress();
FunctionInvocation invocation = new FunctionInvocation() {
@Override
public Object getThiz() {
return function;
}
@Override
public String getName() {
return "";
}
@Override
public Object[] getArgs() {
return args;
}
@Override
public URL getOrigin() {
return address;
}
};
InvokeWindowScript script = new InvokeWindowScript(invocation, address, WindowJavaScriptEngine.JAVASCRIPT_LANGUAGE, settings, false);
ScriptException scriptException = script.getException();
if (scriptException != null) {
document.reportScriptError(script);
}
/*Scriptable scope = function.getParentScope();
ObjectTopLevel topLevel = getObjectTopLevel(scope);
if (topLevel != null) {
Context cx = topLevel.getBrowserScriptEngine().enterContext();
try {
Object arg = WindowJavaScriptEngine.javaToJS(event, scope);
Object[] args = {arg};
function.call(cx, scope, scope, args);
} catch (Exception ex) {
try {
WindowJavaScriptEngine.throwWrappedScriptException(ex);
} catch (ScriptException e) {
throw new WrappedException(e);
}
} finally {
Context.exit();
}
}*/
}