public boolean applyInContext(Context cx, Object input) { if (extractionFn != null) { input = extractionFn.apply(input); } return Context.toBoolean(fnApply.call(cx, scope, scope, new Object[]{input})); }
@Override public String apply(Object input) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } final Object res = fn.call(cx, scope, scope, new Object[]{input}); return res != null ? Context.toString(res) : null; } };
@Override public double apply(Object[] args) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } return Context.toNumber(fn.call(cx, scope, scope, args)); } };
@Override public Object apply(Object input) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } final Object res = fn.call(cx, scope, scope, new Object[]{input}); return res != null ? Context.toObject(res, scope) : null; } };
String script = "function abc(x,y) {return x+y;}"; Context context = Context.enter(); try { ScriptableObject scope = context.initStandardObjects(); Scriptable that = context.newObject(scope); Function fct = context.compileFunction(scope, script, "script", 1, null); Object result = fct.call( context, scope, that, new Object[] {2, 3}); System.out.println(Context.jsToJava(result, int.class)); } finally { Context.exit(); }
String script = "function abc(x,y) {return x+y;}" + "function def(u,v) {return u-v;}"; Context context = Context.enter(); try { ScriptableObject scope = context.initStandardObjects(); context.evaluateString(scope, script, "script", 1, null); Function fct = (Function)scope.get("abc", scope); Object result = fct.call( context, scope, scope, new Object[] {2, 3}); System.out.println(Context.jsToJava(result, int.class)); } finally { Context.exit(); }
public Object exec(List arguments) throws TemplateModelException { Context cx = Context.getCurrentContext(); Object[] args = arguments.toArray(); BeansWrapper wrapper = getWrapper(); for (int i = 0; i < args.length; i++) { args[i] = wrapper.unwrap((TemplateModel) args[i]); } return wrapper.wrap(((Function) getScriptable()).call(cx, ScriptableObject.getTopLevelScope(fnThis), fnThis, args)); } }
result = viewFun.call(context, scope, null, new Object[]{scriptable}); } catch (final JavaScriptException e) { LOG.warn(doc + " caused exception during conversion.", e);
/** * @see org.mozilla.javascript.Function#call */ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { return ((Function)obj).call(cx,scope,thisObj,args); }
public Object run(Context cx) { handler.call(cx, globalObject, globalObject, args); return null; } });
public Object run(Context cx) { handler.call(cx, globalObject, globalObject, args); return null; } });
/** * @see org.mozilla.javascript.Function#call */ @Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { synchronized(thisObj instanceof Wrapper ? ((Wrapper)thisObj).unwrap() : thisObj) { return ((Function)obj).call(cx,scope,thisObj,args); } } }
public Object run(Context cx) { Object a = Context.toObject(arg, globalObject); Object[] args = { a }; handler.call(cx, globalObject, globalObject, args); return null; } });
public boolean applyInContext(Context cx, Object input) { if (extractionFn != null) { input = extractionFn.apply(input); } return Context.toBoolean(fnApply.call(cx, scope, scope, new Object[]{input})); }
public boolean applyInContext(Context cx, Object input) { if (extractionFn != null) { input = extractionFn.apply(input); } return Context.toBoolean(fnApply.call(cx, scope, scope, new Object[]{input})); }
@Override public Object apply(Object input) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } final Object res = fn.call(cx, scope, scope, new Object[]{input}); return res != null ? Context.toObject(res, scope) : null; } };
@Override public String apply(Object input) { // ideally we need a close() function to discard the context once it is not used anymore Context cx = Context.getCurrentContext(); if (cx == null) { cx = contextFactory.enterContext(); } final Object res = fn.call(cx, scope, scope, new Object[]{input}); return res != null ? Context.toString(res) : null; } };
@Close public void close() { final Context context = _contextFactory.enterContext(); try { _closeFunction.call(context, _sharedScope, _sharedScope, new Object[0]); } finally { Context.exit(); } }
public Object exec(List arguments) throws TemplateModelException { Context cx = Context.getCurrentContext(); Object[] args = arguments.toArray(); BeansWrapper wrapper = getWrapper(); for (int i = 0; i < args.length; i++) { args[i] = wrapper.unwrap((TemplateModel)args[i]); } return wrapper.wrap(((Function)getScriptable()).call(cx, ScriptableObject.getTopLevelScope(fnThis), fnThis, args)); } }
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()); } }