本文整理汇总了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();
}
}*/
}