当前位置: 首页>>代码示例>>Java>>正文


Java Function.getParentScope方法代码示例

本文整理汇总了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();
		}
	}
}
 
开发者ID:jutils,项目名称:jsen-js,代码行数:25,代码来源:HostedJavaMethod.java

示例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());
    }
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:11,代码来源:JSAdapter.java

示例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();
    }
}
 
开发者ID:GeeQuery,项目名称:ef-orm,代码行数:36,代码来源:RhinoScriptEngine.java

示例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();
		}
	}*/
}
 
开发者ID:ITman1,项目名称:ScriptBox,代码行数:77,代码来源:HostedJavaMethod.java


注:本文中的org.mozilla.javascript.Function.getParentScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。