private void init( boolean translucent, int depth, int stencil ) { /* By default, GLSurfaceView() creates a RGB_565 opaque surface. * If we want a translucent one, we should change the surface's * format here, using PixelFormat.TRANSLUCENT for GL Surfaces * is interpreted as any 32-bit surface with alpha by SurfaceFlinger. */ this.getHolder().setFormat( PixelFormat.RGB_565 ); if ( translucent ) { this.getHolder().setFormat( PixelFormat.TRANSLUCENT ); } setEGLContextFactory( new ContextFactory() ); /* We need to choose an EGLConfig that matches the format of * our surface exactly. This is going to be done in our * custom config chooser. See ConfigChooser class definition * below. */ setEGLConfigChooser( translucent ? new ConfigChooser( 8, 8, 8, 8, depth, stencil ) : new ConfigChooser( 5, 6, 5, 0, depth, stencil ) ); setRenderer( new Renderer() ); }
public JavascriptRunner() { ContextFactory factory = new ContextFactory(); cx = factory.enterContext(); scope = cx.initStandardObjects(); }
Context ctx = new ContextFactory().enterContext();
public class AddPropertyToObject { public static void main(String[] args) { new ContextFactory().call(new ContextAction(){ @Override public Object run(Context ctx) { Scriptable scope = ctx.initStandardObjects(); try { Scriptable entity = ctx.newObject(scope); NativeObject result = (NativeObject) ctx.evaluateString( scope, "({age:3, name:'bob'})", "<inline>", 1, null); result.put("surname", result, "Smith"); for (Entry<Object, Object> p : result.entrySet()) { System.out.println(p.getKey() + ": " + p.getValue()); } } catch (Exception e) { e.printStackTrace(System.err); } return null; } }); } }
@Initialize public void init() { _contextFactory = new ContextFactory(); final Context context = _contextFactory.enterContext(); try { _script = context.compileString(sourceCode, this.getClass().getSimpleName(), 1, null); _sharedScope = context.initStandardObjects(); JavaScriptUtils.addToScope(_sharedScope, new JavaScriptLogger(), "logger", "log"); JavaScriptUtils.addToScope(_sharedScope, System.out, "out"); } finally { Context.exit(); } }
new ContextFactory().call(new ContextAction(){
@Initialize public void init() { _contextFactory = new ContextFactory(); final Context context = _contextFactory.enterContext(); try { _script = context.compileString(sourceCode, this.getClass().getSimpleName(), 1, null); _sharedScope = context.initStandardObjects(); JavaScriptUtils.addToScope(_sharedScope, new JavaScriptLogger(), "logger", "log"); JavaScriptUtils.addToScope(_sharedScope, System.out, "out"); } finally { Context.exit(); } }
@Override protected PicoContainer createContainerFromScript(final PicoContainer parentContainer, final Object assemblyScope) { final ClassLoader loader = getClassLoader(); ContextFactory contextFactory = new ContextFactory(); contextFactory.initApplicationClassLoader(loader);
private void dispose() { // ensure the debugger is closed exitDebugger(); // reset the context factory class for future use ContextFactory newGlobal = new ContextFactory(); setField(newGlobal, "hasCustomGlobal", Boolean.FALSE); setField(newGlobal, "global", newGlobal); setField(newGlobal, "sealed", Boolean.FALSE); setField(newGlobal, "listeners", null); setField(newGlobal, "disabledListening", Boolean.FALSE); setField(newGlobal, "applicationClassLoader", null); }
+ expression + "\n}}"; ContextFactory factory = new ContextFactory();
@Initialize public void init() { _contextFactory = new ContextFactory(); final Context context = _contextFactory.enterContext(); try { _script = context.compileString(sourceCode, this.getClass().getSimpleName(), 1, null); _sharedScope = context.initStandardObjects(); JavaScriptUtils.addToScope(_sharedScope, new JavaScriptLogger(), "logger", "log"); JavaScriptUtils.addToScope(_sharedScope, System.out, "out"); _script.exec(context, _sharedScope); _transformerObj = (NativeObject) _sharedScope.get("transformerObj"); if (_transformerObj == null) { throw new IllegalStateException("Required JS object 'transformerObj' not found!"); } _initializeFunction = (Function) _transformerObj.get("initialize"); _transformFunction = (Function) _transformerObj.get("transform"); _closeFunction = (Function) _transformerObj.get("close"); _initializeFunction.call(context, _sharedScope, _sharedScope, new Object[0]); } finally { Context.exit(); } }
@Override public String compile(Loader loader, URI uri, CharSequence content, boolean compress) { final ContextFactory cf = new ContextFactory(); final Context cx = cf.enterContext(); try { final Function runLessRun = (Function) sharedScope.get("runLessRun", sharedScope); Scriptable newScope = cx.newObject(sharedScope); newScope.setPrototype(sharedScope); newScope.setParentScope(null); try { final Object[] args = {uri, loader, content, compress}; final Object result = runLessRun.call(cx, newScope, newScope, args); return Context.toString(result); } catch (JavaScriptException e) { throw newLessException(e); } } finally { Context.exit(); } }