// Identifies the added properties to prototypes (ie String and Function) // for later filtering if you need a for-in loop. var stringAddons = []; var functionAddons = [] var _string = new String(); var _function = function() {}; for (var property in _string) { if (!_string.hasOwnProperty(property)) { stringAddons.push(property); }} for (var property in _function) { if (!_function.hasOwnProperty(property)) { functionAddons.push(property); }} // Wraps the undeclared identifiers var global = function() { this.badA = "hahaha"; this.badB = "hehehe"; this.badC = "hohoho"; String.prototype.star = function(){ return '***' + this + '***' } this.somethingUseful = { doStuff: function () { alert((global.badA + global.badB + global.badC).star()); } } } var global = new Global(); global.somethingUseful.doStuff();
Global myGlobal = new Global(); String[][][] myArray = myGlobal.getMyarray(); // returns the array reference myArray[2][2][1] = "me"; // set the value of a single array element final String name = myArray[2][2][1];
import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class HelloWorld extends Activity{ Global gb; TextView myTV; protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.helloworld); gb=new Global(this); myTV = (TextView) findViewById(R.id.textView1); myTV.setText("First line is: "+gb.getLine()); } }
/** * Entry point for embedded applications. This method attaches * to the global {@link ContextFactory} with a scope of a newly * created {@link Global} object. No I/O redirection is performed * as with {@link #main(String[])}. */ public static Main mainEmbedded(String title) { ContextFactory factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); return mainEmbedded(factory, global, title); }
/** * Entry point for embedded applications. This method attaches * to the global {@link ContextFactory} with a scope of a newly * created {@link Global} object. No I/O redirection is performed * as with {@link #main(String[])}. */ public static Dim mainEmbedded(String title) { ContextFactory factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); return mainEmbedded(factory, global, title); }
/** * Entry point for embedded applications. This method attaches * to the global {@link ContextFactory} with a scope of a newly * created {@link Global} object. No I/O redirection is performed * as with {@link #main(String[])}. */ public static Main mainEmbedded(String title) { ContextFactory factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); return mainEmbedded(factory, global, title); }
private void initialize() throws InitializationException { InputStreamReader reader = null; try { final Context context = Context.enter(); context.setLanguageVersion(Context.VERSION_1_8); final Global global = new Global(); global.init(context); scope = context.initStandardObjects(global); console = new ByteArrayOutputStream(); global.setOut(new PrintStream(console, false, CHARSET)); final URL lessFile = LessCompilerImpl.class.getResource("/less/less-rhino-1.7.5.js"); final URL lesscFile = LessCompilerImpl.class.getResource("/less/lessc-rhino-1.7.5.js"); final Collection<InputStream> streams = new ArrayList<InputStream>(); streams.add(lessFile.openConnection().getInputStream()); streams.add(lesscFile.openConnection().getInputStream()); reader = new InputStreamReader(new SequenceInputStream(Collections.enumeration(streams)), CHARSET); compiler = (Function) context.compileReader(reader, lessFile.toString(), 1, null); } catch (final Exception e) { throw new InitializationException("Failed to initialize Less compiler", e); } finally { IOUtils.closeQuietly(reader); Context.exit(); } }
mageView universityLogo; Global global = new Global(); View v2 = View.inflate(this, R.layout.my_action_bar, null); universityLogo = (ImageView)v2.findViewById(R.id.buttonLeft); switch(global.getLocation()){ case "33613": universityLogo.setImageResource(R.drawable.diploma); } ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayShowHomeEnabled(false); actionBar.setCustomView(mActionBarView); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
public LessEngine(LessOptions options) { try { logger.debug("Initializing LESS Engine."); classLoader = getClass().getClassLoader(); URL less = options.getLess(); URL env = classLoader.getResource("META-INF/env.js"); URL engine = classLoader.getResource("META-INF/engine.js"); URL cssmin = classLoader.getResource("META-INF/cssmin.js"); Context cx = Context.enter(); logger.debug("Using implementation version: " + cx.getImplementationVersion()); cx.setOptimizationLevel(9); Global global = new Global(); global.init(cx); scope = cx.initStandardObjects(global); cx.evaluateReader(scope, new InputStreamReader(env.openConnection().getInputStream()), env.getFile(), 1, null); cx.evaluateString(scope, "lessenv.charset = '" + options.getCharset() + "';", "charset", 1, null); cx.evaluateString(scope, "lessenv.css = " + options.isCss() + ";", "css", 1, null); cx.evaluateReader(scope, new InputStreamReader(less.openConnection().getInputStream()), less.getFile(), 1, null); cx.evaluateReader(scope, new InputStreamReader(cssmin.openConnection().getInputStream()), cssmin.getFile(), 1, null); cx.evaluateReader(scope, new InputStreamReader(engine.openConnection().getInputStream()), engine.getFile(), 1, null); compileString = (Function) scope.get("compileString", scope); compileFile = (Function) scope.get("compileFile", scope); Context.exit(); } catch (Exception e) { logger.error("LESS Engine intialization failed.", e); } }
protected void compress() throws IOException { URL cssmin = getClass().getClassLoader().getResource( "META-INF/cssmin.js"); Context cx = Context.enter(); cx.setOptimizationLevel(9); Global global = new Global(); global.init(cx); Scriptable scope = cx.initStandardObjects(global); cx.evaluateString(scope, "var exports = {};", "exports", 1, null); cx.evaluateReader(scope, new InputStreamReader(cssmin.openConnection() .getInputStream()), cssmin.getFile(), 1, null); Scriptable exports = (Scriptable) scope.get("exports", scope); Scriptable compressor = (Scriptable) exports.get("compressor", exports); Function fn = (Function) compressor.get("cssmin", compressor); content = ((String) Context.call(null, fn, compressor, compressor, new Object[] { new String(content, charset).replaceFirst( "^/\\*", "/*!") })).getBytes(charset); Context.exit(); }
public RhinoBackend(ResourceLoader resourceLoader) throws IOException { this.resourceLoader = resourceLoader; cx = Context.enter(); scope = new Global(cx); // This gives us access to global functions like load() scope.put("jsBackend", scope, this); for (Resource resource : resourceLoader.resources("classpath:cucumber/runtime/rhino", ".js")) { runScript(resource); } }
public void initContext(Context cx, Scriptable scope, Script script) { this.cx = cx; this.scope = scope; this.script = script; if (global == null || !global.isInitialized()) { global = new Global(cx); global.setIn(System.in); global.setOut(System.out); global.setErr(System.err); } // dim.setScopeProvider(new LscScopeProvider(global)); }
public CommonJSEngineFactory(List<String> modulePaths) { this.modulePaths = modulePaths; Context cx = CommonJSEngine.enterContext(); try { global = new Global(); global.initStandardObjects(cx, true); global.installRequire(cx, modulePaths, true); } finally { Context.exit(); } }
public Rhino1_7R3Context() { Context ctx = Context.enter(); try { ctx.setOptimizationLevel(1); ctx.setLanguageVersion(Context.VERSION_1_7); // Global global = new Global(); global.init(ctx); this.global = global; this.ctx = ctx; this.scope = ctx.initStandardObjects(global); this.classCache = new HashMap<String, Class<?>>(); this.codeCache = new HashMap<String, byte[]>(); } finally { Context.exit(); } }
public Rhino1_7R3Context() { Context ctx = Context.enter(); try { ctx.setOptimizationLevel(1); ctx.setLanguageVersion(Context.VERSION_1_7); // Global global = new Global(); global.init(ctx); this.global = global; this.ctx = ctx; this.scope = ctx.initStandardObjects(global); this.classCache = new HashMap<String, Class<?>>(); this.codeCache = new HashMap<String, byte[]>(); } finally { Context.exit(); } }
@Override protected Void doCall(Context cx, Scriptable s) { try { Global global = new Global(cx); RequireProperties require = rhinoProperties.getRequire(); if (require != null) { List<String> modulePathURIs = getModulePathURIs(require); LOGGER.debug("Module paths: {}", modulePathURIs); global.installRequire(cx, modulePathURIs, require.isSandboxed()); } // we need to load compat/timeout.js because rhino does not have setTimeout, setInterval, etc. try (Reader in = new InputStreamReader(classloader.getResourceAsStream("compat/timeout.js"))) { cx.evaluateReader(global, in, "compat/timeout.js", 1, null); } scope = global; prototype = new NativeObject(); scope.put("__prototype", scope, prototype); return null; } catch (IOException e) { throw Throwables.propagate(e); } } });
public void initialize() throws Exception { if (enableDebugger) { if (getLogger().isDebugEnabled()) { getLogger().debug("Flow debugger enabled, creating"); } getDebugger().doBreak(); } Context context = Context.enter(); context.setOptimizationLevel(OPTIMIZATION_LEVEL); context.setCompileFunctionsWithDynamicScope(true); context.setGeneratingDebug(true); // add support for Rhino objects to JXPath JXPathIntrospector.registerDynamicClass(Scriptable.class, ScriptablePropertyHandler.class); JXPathContextReferenceImpl.addNodePointerFactory(new ScriptablePointerFactory()); try { scope = new Global(context); // Access to Cocoon internal objects FOM_Cocoon.init(scope); } catch (Exception e) { Context.exit(); throw e; } }
/** * Activate the Debugger */ public synchronized void activate() { factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); global.setIn(System.in); global.setOut(System.out); global.setErr(System.err); initDebugger(); ScopeProvider sp = new AlfrescoScopeProvider((Scriptable)global); dim.setScopeProvider(sp); gui = new AlfrescoGui(dim, getTitle(), this); gui.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); gui.setExitAction(this); }
/** * Activate the Debugger */ public synchronized void activate() { factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); global.setIn(System.in); global.setOut(System.out); global.setErr(System.err); initDebugger(); ScopeProvider sp = new AlfrescoScopeProvider((Scriptable)global); dim.setScopeProvider(sp); gui = new AlfrescoGui(dim, getTitle(), this); gui.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); gui.setExitAction(this); }
/** * Activate the Debugger */ public synchronized void activate() { factory = ContextFactory.getGlobal(); Global global = new Global(); global.init(factory); global.setIn(System.in); global.setOut(System.out); global.setErr(System.err); initDebugger(); ScopeProvider sp = new AlfrescoScopeProvider((Scriptable)global); dim.setScopeProvider(sp); gui = new AlfrescoGui(dim, getTitle(), this); gui.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); gui.setExitAction(this); }