public static String getVersion() { return ContextFactory.getGlobal().enterContext().getImplementationVersion(); }
private static Function compile(String function) { final ContextFactory contextFactory = ContextFactory.getGlobal(); final Context context = contextFactory.enterContext(); context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL); final ScriptableObject scope = context.initStandardObjects(); final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null); Context.exit(); return new Function() { @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)); } }; }
private static Function<Object, String> compile(String function) { final ContextFactory contextFactory = ContextFactory.getGlobal(); final Context context = contextFactory.enterContext(); context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL); final ScriptableObject scope = context.initStandardObjects(); final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null); Context.exit(); return new Function<Object, String>() { @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; } }; }
private static Function<Object, Object> compile(String function) { final ContextFactory contextFactory = ContextFactory.getGlobal(); final Context context = contextFactory.enterContext(); context.setOptimizationLevel(9); final ScriptableObject scope = context.initStandardObjects(); final org.mozilla.javascript.Function fn = context.compileFunction(scope, function, "fn", 1, null); Context.exit(); return new Function<Object, Object>() { @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; } }; }
@Before public void setUp() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); jsContext = ContextFactory.getGlobal().enterContext(); jsScope = jsContext.initStandardObjects(); view = new MappingJackson2XmlView(); }
@Before public void setUp() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); jsContext = ContextFactory.getGlobal().enterContext(); jsScope = jsContext.initStandardObjects(); view = new MappingJackson2JsonView(); }
final ContextFactory contextFactory = ContextFactory.getGlobal(); Context context = contextFactory.enterContext(); context.setOptimizationLevel(JavaScriptConfig.DEFAULT_OPTIMIZATION_LEVEL);
Scriptable scope; cx = ContextFactory.getGlobal().enterContext();
Script jsscript; jscx = ContextFactory.getGlobal().enterContext(); jsscope = jscx.initStandardObjects( null, false ); try {
jscx = ContextFactory.getGlobal().enterContext(); jscx.setOptimizationLevel( -1 ); jsscope = jscx.initStandardObjects( null, false );
jscx = ContextFactory.getGlobal().enterContext(); jscx.setOptimizationLevel( -1 ); jsscope = jscx.initStandardObjects( null, false );
data.cx = ContextFactory.getGlobal().enterContext();
/** * @deprecated * @see ContextFactory#removeListener(ContextFactory.Listener) * @see ContextFactory#getGlobal() */ public static void removeContextListener(ContextListener listener) { ContextFactory.getGlobal().addListener(listener); }
public static Scriptable runScript(final Script script) { return (Scriptable)ContextFactory.getGlobal().call( new ContextAction() { public Object run(Context cx) { ScriptableObject global = ScriptRuntime.getGlobal(cx); script.exec(cx, global); return global; } }); }
public static Scriptable runScript(final Script script) { return (Scriptable)ContextFactory.getGlobal().call( new ContextAction() { public Object run(Context cx) { ScriptableObject global = ScriptRuntime.getGlobal(cx); script.exec(cx, global); return global; } }); }
/** * @deprecated * @see ContextFactory#removeListener(org.mozilla.javascript.ContextFactory.Listener) * @see ContextFactory#getGlobal() */ public static void removeContextListener(ContextListener listener) { ContextFactory.getGlobal().addListener(listener); }
/** * @deprecated * @see ContextFactory#removeListener(ContextFactory.Listener) * @see ContextFactory#getGlobal() */ public static void removeContextListener(ContextListener listener) { ContextFactory.getGlobal().addListener(listener); }
private void dropRootScope() { // ensure the debugger is closed if the root scope will // be replaced to ensure no references to the old scope // and context remain ContextFactory contextFactory = ContextFactory.getGlobal(); if (contextFactory instanceof SlingContextFactory) { ((SlingContextFactory) contextFactory).exitDebugger(); } // drop the scope rootScope = null; }
public void destroy() { if (initialized) { if (listener != null) { ContextFactory.getGlobal().removeListener(listener); } initialized = false; } }
public static Scriptable runScript(final Script script) { return (Scriptable)ContextFactory.getGlobal().call( new ContextAction() { public Object run(Context cx) { ScriptableObject global = ScriptRuntime.getGlobal(cx); script.exec(cx, global); return global; } }); }