Java Code Examples for org.mozilla.javascript.ContextFactory#initGlobal()

The following examples show how to use org.mozilla.javascript.ContextFactory#initGlobal() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public void init() {
    //this can be initiated only once
    if (mScriptContextFactory == null) {
        mScriptContextFactory = new ScriptContextFactory();
        ContextFactory.initGlobal(mScriptContextFactory);
    }
    mScriptContextFactory.setInterpreter(this);

    rhino = Context.enter();
    // observingDebugger = new ObservingDebugger();
    // rhino.setDebugger(observingDebugger, new Integer(0));
    // rhino.setGeneratingDebug(true);

    // give some android love
    rhino.setOptimizationLevel(-1);

    scope = rhino.initStandardObjects();

    //let rhino do some java <-> js transformations for us
    rhino.getWrapFactory().setJavaPrimitiveWrap(false);
}
 
Example 2
protected synchronized void initSecureScriptContextFactory() {
  if (secureScriptContextFactory == null) {
    secureScriptContextFactory = new SecureScriptContextFactory();

    secureScriptContextFactory.setOptimizationLevel(getScriptOptimizationLevel());

    if (isEnableClassWhiteListing() || getWhiteListedClasses() != null
        || classWhitelister != null) {
      if (classWhitelister == null) {
        classWhitelister = new DefaultClassWhitelister();
        if (getWhiteListedClasses() != null && getWhiteListedClasses().size() > 0) {
          ((DefaultClassWhitelister)classWhitelister).setWhiteListedClasses(getWhiteListedClasses());
        }
      }
      secureScriptClassShutter = new SecureScriptClassShutter();
      secureScriptClassShutter.setClassWhitelister(classWhitelister);
      secureScriptContextFactory.setClassShutter(secureScriptClassShutter);
    }

    if (getMaxScriptExecutionTime() > 0L) {
      secureScriptContextFactory.setMaxScriptExecutionTime(getMaxScriptExecutionTime());
    }

    if (getMaxMemoryUsed() > 0L) {
      secureScriptContextFactory.setMaxMemoryUsed(getMaxMemoryUsed());
    }

    if (getMaxStackDepth() > 0) {
      secureScriptContextFactory.setMaxStackDepth(getMaxStackDepth());
    }

    if (getMaxScriptExecutionTime() > 0L || getMaxMemoryUsed() > 0L) {
      secureScriptContextFactory.setObserveInstructionCount(getNrOfInstructionsBeforeStateCheckCallback());
    }

    ContextFactory.initGlobal(secureScriptContextFactory);
  }
}
 
Example 3
protected synchronized void initSecureScriptContextFactory() {
    if (secureScriptContextFactory == null) {
        secureScriptContextFactory = new SecureScriptContextFactory();

        secureScriptContextFactory.setOptimizationLevel(getScriptOptimizationLevel());

        if (isEnableClassWhiteListing() || getWhiteListedClasses() != null) {
            secureScriptClassShutter = new SecureScriptClassShutter();
            if (getWhiteListedClasses() != null && getWhiteListedClasses().size() > 0) {
                secureScriptClassShutter.setWhiteListedClasses(getWhiteListedClasses());
            }
            secureScriptContextFactory.setClassShutter(secureScriptClassShutter);
        }

        if (getMaxScriptExecutionTime() > 0L) {
            secureScriptContextFactory.setMaxScriptExecutionTime(getMaxScriptExecutionTime());
        }

        if (getMaxMemoryUsed() > 0L) {
            secureScriptContextFactory.setMaxMemoryUsed(getMaxMemoryUsed());
        }

        if (getMaxStackDepth() > 0) {
            secureScriptContextFactory.setMaxStackDepth(getMaxStackDepth());
        }

        if (getMaxScriptExecutionTime() > 0L || getMaxMemoryUsed() > 0L) {
            secureScriptContextFactory.setObserveInstructionCount(getNrOfInstructionsBeforeStateCheckCallback());
        }

        secureScriptContextFactory.setEnableAccessToBeans(isEnableAccessToBeans());
        ContextFactory.initGlobal(secureScriptContextFactory);
    }
}
 
Example 4
public static void initMyFactory( )
{
	ContextFactory.initGlobal( new MyFactory( ) );
	if ( System.getSecurityManager( ) != null )
	{
		SecurityController.initGlobal( ScriptUtil
				.createSecurityController( ) );
	}
}