本文整理汇总了Java中org.mozilla.javascript.NativeFunction类的典型用法代码示例。如果您正苦于以下问题:Java NativeFunction类的具体用法?Java NativeFunction怎么用?Java NativeFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NativeFunction类属于org.mozilla.javascript包,在下文中一共展示了NativeFunction类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: put
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
@Override
public void put(String name, Scriptable start, Object value) {
if (name.equals("__proxy__")) {
NativeObject proxy = (NativeObject) value;
Object getter = proxy.get("get", start);
if (getter instanceof NativeFunction) {
mGetter = (NativeFunction) getter;
}
Object setter = proxy.get("set", start);
if (setter instanceof NativeFunction) {
mSetter = (NativeFunction) setter;
}
} else if (mSetter != null) {
mSetter.call(Context.getCurrentContext(), start, start, new Object[]{name, value});
} else {
super.put(name, start, value);
}
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:19,代码来源:ProxyObject.java
示例2: getParamsFromVariables
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
@Override
protected Map<String, Object> getParamsFromVariables() throws IOException {
Map<String, Object> params = new HashMap<String, Object>();
Object[] ids = scope.getIds();
for (Object id : ids) {
if (id instanceof String) {
String name = (String) id;
Object value = scope.get(name, scope);
if (!(value instanceof NativeFunction)) {
LOG.debug("Registering parameter "+name+" => "+scope.get(name, scope));
params.put(name, eval(name).toString());
}
}
}
return params;
}
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:17,代码来源:JsScriptEngine.java
示例3: bind
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
/**
* javascript helper for binding parameters.
* See: {@link Pig#bind(Map)}
* @param o a javascript object to be converted into a Map
* @return the bound script
* @throws IOException if {@link Pig#bind(Map)} throws an IOException
*/
public BoundScript bind(Object o) throws IOException {
NativeObject vars = (NativeObject)o;
Map<String, Object> params = new HashMap<String, Object>();
Object[] ids = vars.getIds();
for (Object id : ids) {
if (id instanceof String) {
String name = (String) id;
Object value = vars.get(name, vars);
if (!(value instanceof NativeFunction) && value != null) {
params.put(name, value.toString());
}
}
}
return pig.bind(params);
}
开发者ID:sigmoidanalytics,项目名称:spork-streaming,代码行数:23,代码来源:JSPig.java
示例4: adaptFunctionScope
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
protected void adaptFunctionScope(final Pair<Scriptable, Function> callback, final Scriptable globalScope, final boolean restore)
{
if (callback != null)
{
final Function fn = callback.getSecond();
if (fn instanceof NativeFunction)
{
if (restore)
{
final Scriptable parentScope = fn.getParentScope();
if (parentScope instanceof ThreadLocalParentScope)
{
fn.setParentScope(((ThreadLocalParentScope) parentScope).getRealParentScope());
}
}
else
{
fn.setParentScope(new ThreadLocalParentScope(fn.getParentScope(), globalScope, this.facadeFactory));
}
}
}
}
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:23,代码来源:AbstractExecuteBatchFunction.java
示例5: waitFor
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
@Override
public void waitFor(NativeFunction func, long waitIterationMilliseconds) {
while (!RhinoUtils.toBoolean(func.call(javaScriptEngine.getContext(),
javaScriptEngine.getScope(),
javaScriptEngine.getScope(),
new Object[0]))) {
try {
Thread.sleep(waitIterationMilliseconds);
} catch (InterruptedException e) {
throw new ScriptException(ErrorType.Timeout, "waitFor() interrupted");
}
}
}
开发者ID:loadtestgo,项目名称:pizzascript,代码行数:14,代码来源:PizzaImpl.java
示例6: testFunction
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
public void testFunction() throws Exception {
Context cx = Context.enter();
try {
cx.setOptimizationLevel(-1);
cx.setLanguageVersion(Context.VERSION_1_7);
cx.setApplicationClassLoader(getClass().getClassLoader());
final Scriptable scope = cx.initStandardObjects();
System.out.println("START TEST OF RHINO");
Object result = cx.evaluateString(scope,
new StringBuffer()
.append("function( a, b ) { return a + b ; }")
.toString(),
"testFunction", 1, null
);
Assert.assertNotNull(result);
Assert.assertTrue( result instanceof NativeFunction );
result = ((NativeFunction)result).call( cx, scope, null /*this*/, new Object[] { 10, 5 });
Assert.assertNotNull(result);
Assert.assertTrue(result instanceof Number);
Assert.assertEquals(((java.lang.Number) result).intValue(), 15);
System.out.printf("END TEST OF RHINO [%s]\n", result.getClass());
}
finally {
Context.exit();
}
}
开发者ID:bsorrentino,项目名称:android-js,代码行数:37,代码来源:HelloAndroidActivityTest.java
示例7: addStepDefinition
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
public void addStepDefinition(Global jsStepDefinition, NativeRegExp regexp, NativeFunction bodyFunc, NativeFunction argumentsFromFunc) throws Throwable {
StackTraceElement stepDefLocation = jsLocation();
RhinoStepDefinition stepDefinition = new RhinoStepDefinition(cx, scope, jsStepDefinition, regexp, bodyFunc, stepDefLocation, argumentsFromFunc);
glue.addStepDefinition(stepDefinition);
}
开发者ID:viltgroup,项目名称:minium,代码行数:6,代码来源:MiniumBackend.java
示例8: doBeforeProcess
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
protected Scriptable doBeforeProcess(final Context parentContext, final Scriptable parentScope, final Scriptable thisObj,
final Pair<Scriptable, Function> beforeProcessCallback)
{
final Context cx = Context.enter();
try
{
this.scriptProcessor.inheritCallChain(parentContext);
final Scriptable processScope = cx.newObject(parentScope);
processScope.setPrototype(null);
processScope.setParentScope(null);
// check for registerChildScope function on logger and register process scope if function is available
final Object loggerValue = ScriptableObject.getProperty(parentScope, RhinoLogFunction.LOGGER_OBJ_NAME);
if (loggerValue instanceof Scriptable)
{
final Scriptable loggerObj = (Scriptable) loggerValue;
final Object registerChildScopeFuncValue = ScriptableObject.getProperty(loggerObj,
RhinoLogFunction.REGISTER_CHILD_SCOPE_FUNC_NAME);
if (registerChildScopeFuncValue instanceof Function)
{
final Function registerChildScopeFunc = (Function) registerChildScopeFuncValue;
registerChildScopeFunc.call(cx, parentScope, thisObj, new Object[] { processScope });
}
}
if (beforeProcessCallback.getSecond() != null)
{
final Scriptable beforeProcessOriginalCallScope = beforeProcessCallback.getFirst();
final Scriptable beforeProcessCallScope = this.facadeFactory.toFacadedObject(beforeProcessOriginalCallScope, parentScope);
final Function beforeProcessFn = beforeProcessCallback.getSecond();
if (beforeProcessFn instanceof NativeFunction)
{
// native function has parent scope based on location in source code
// per batch function contract we need to execute it in our process scope
final NativeFunction nativeFn = (NativeFunction) beforeProcessFn;
final ThreadLocalParentScope threadLocalParentScope = (ThreadLocalParentScope) nativeFn.getParentScope();
threadLocalParentScope.setEffectiveParentScope(processScope);
try
{
// execute with thread local parent scope
nativeFn.call(cx, processScope, beforeProcessCallScope, new Object[0]);
}
finally
{
threadLocalParentScope.removeEffectiveParentScope();
}
}
else
{
// not a native function, so has no associated scope - calling as-is
beforeProcessFn.call(cx, processScope, beforeProcessCallScope, new Object[0]);
}
}
return processScope;
}
catch (final WrappedException ex)
{
final Throwable wrappedException = ex.getWrappedException();
if (wrappedException instanceof RuntimeException)
{
throw (RuntimeException) wrappedException;
}
throw ex;
}
finally
{
Context.exit();
}
}
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:74,代码来源:AbstractExecuteBatchFunction.java
示例9: doProcess
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
protected void doProcess(final Context parentContext, final Scriptable parentScope, final Scriptable processScope,
final Scriptable thisObj, final Pair<Scriptable, Function> processCallback, final Object element)
{
final Context cx = Context.enter();
try
{
this.scriptProcessor.inheritCallChain(parentContext);
final Scriptable processOriginalCallScope = processCallback.getFirst();
final Scriptable processCallScope = this.facadeFactory.toFacadedObject(processOriginalCallScope, parentScope);
final Function processFn = processCallback.getSecond();
if (processFn instanceof NativeFunction)
{
// native function has parent scope based on location in source code
// per batch function contract we need to execute it in our process scope
final NativeFunction nativeFn = (NativeFunction) processFn;
final ThreadLocalParentScope threadLocalParentScope = (ThreadLocalParentScope) nativeFn.getParentScope();
threadLocalParentScope.setEffectiveParentScope(processScope);
try
{
// execute with thread local parent scope
nativeFn.call(cx, processScope, processCallScope, new Object[] { element });
}
finally
{
threadLocalParentScope.removeEffectiveParentScope();
}
}
else
{
// not a native function, so has not associated scope - calling as-is
processFn.call(cx, processScope, processCallScope, new Object[] { element });
}
}
catch (final WrappedException ex)
{
final Throwable wrappedException = ex.getWrappedException();
if (wrappedException instanceof RuntimeException)
{
throw (RuntimeException) wrappedException;
}
throw ex;
}
finally
{
Context.exit();
}
}
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:51,代码来源:AbstractExecuteBatchFunction.java
示例10: doAfterProcess
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
protected void doAfterProcess(final Context parentContext, final Scriptable parentScope, final Scriptable processScope,
final Scriptable thisObj, final Pair<Scriptable, Function> afterProcessCallback)
{
final Context cx = Context.enter();
try
{
this.scriptProcessor.inheritCallChain(parentContext);
if (afterProcessCallback.getSecond() != null)
{
final Scriptable afterProcessOriginalCallScope = afterProcessCallback.getFirst();
final Scriptable afterProcessCallScope = this.facadeFactory.toFacadedObject(afterProcessOriginalCallScope, parentScope);
final Function afterProcessFn = afterProcessCallback.getSecond();
if (afterProcessFn instanceof NativeFunction)
{
// native function has parent scope based on location in source code
// per batch function contract we need to execute it in our process scope
final NativeFunction nativeFn = (NativeFunction) afterProcessFn;
final ThreadLocalParentScope threadLocalParentScope = (ThreadLocalParentScope) nativeFn.getParentScope();
threadLocalParentScope.setEffectiveParentScope(processScope);
try
{
// execute with thread local parent scope
nativeFn.call(cx, processScope, afterProcessCallScope, new Object[0]);
}
finally
{
threadLocalParentScope.removeEffectiveParentScope();
}
}
else
{
// not a native function, so has not associated scope - calling as-is
afterProcessFn.call(cx, processScope, afterProcessCallScope, new Object[0]);
}
}
}
catch (final WrappedException ex)
{
final Throwable wrappedException = ex.getWrappedException();
if (wrappedException instanceof RuntimeException)
{
throw (RuntimeException) wrappedException;
}
throw ex;
}
finally
{
Context.exit();
// clear thread-local facade mapping
this.facadeFactory.clearThread();
}
}
开发者ID:AFaust,项目名称:alfresco-enhanced-script-environment,代码行数:56,代码来源:AbstractExecuteBatchFunction.java
示例11: waitFor
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
/**
* Wait for the given function to return true
*
* @param func
*/
void waitFor(NativeFunction func);
开发者ID:loadtestgo,项目名称:pizzascript,代码行数:7,代码来源:Pizza.java
示例12: RhinoBroadcastReceiver
import org.mozilla.javascript.NativeFunction; //导入依赖的package包/类
/**
*
* @param onReceiveFunction
*/
public RhinoBroadcastReceiver(NativeFunction onReceiveFunction) {
this.onReceiveFunction = onReceiveFunction;
}
开发者ID:bsorrentino,项目名称:android-js,代码行数:8,代码来源:RhinoBroadcastReceiver.java
注:本文中的org.mozilla.javascript.NativeFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论