org.mozilla.javascript.tools.shell.Global.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 JavaScript  
字(11.8k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中org.mozilla.javascript.tools.shell.Global.<init>()方法的一些代码示例,展示了Global.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Global.<init>()方法的具体详情如下:
包路径:org.mozilla.javascript.tools.shell.Global
类名称:Global
方法名:<init>

Global.<init>介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

// 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();

代码示例来源:origin: stackoverflow.com

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];

代码示例来源:origin: stackoverflow.com

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());
    }
  }

代码示例来源:origin: ro.isdc.wro4j/rhino

/**
 * 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);
}

代码示例来源:origin: org.jvnet.hudson/embedded-rhino-debugger

/**
 * 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);
}

代码示例来源:origin: com.github.tntim96/rhino

/**
 * 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);
}

代码示例来源:origin: biz.gabrys.lesscss/compiler

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();
  }
}

代码示例来源:origin: stackoverflow.com

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);

代码示例来源:origin: com.google.code.maven-play-plugin.com.asual.lesscss/lesscss-engine

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);
  }
}

代码示例来源:origin: com.asual.lesscss/lesscss-servlet

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();
}

代码示例来源:origin: info.cukes/cucumber-rhino

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);
  }
}

代码示例来源:origin: lsc-project/lsc

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));
}

代码示例来源:origin: org.geoserver.script/gs-script-js

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();
  }
}

代码示例来源:origin: org.juzu/juzu-plugins-less

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();
 }
}

代码示例来源:origin: juzu/juzu

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();
 }
}

代码示例来源:origin: viltgroup/minium

@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);
    }
  }
});

代码示例来源:origin: org.apache.cocoon/cocoon-flowscript-impl

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;
  }
}

代码示例来源:origin: deas/alfresco

/**
 * 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);
}

代码示例来源:origin: org.springframework.extensions.surf/spring-webscripts

/**
 * 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);
}

代码示例来源:origin: org.alfresco.surf/spring-webscripts

/**
 * 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);
}

相关文章