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

The following are Jave code examples for showing how to use initGlobal() of the org.mozilla.javascript.ContextFactory class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: phonk   File: AppRunnerInterpreter.java   Source Code and License Vote up 6 votes
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
Project: BotLogic   File: GameManager.java   Source Code and License Vote up 6 votes
@Override
public void create() {
  Gdx.app.log(TAG, "created");

  Tween.registerAccessor(ModelEntity.class, new ModelEntityAccessor());
  Tween.registerAccessor(RTSCameraController.class, new CameraAccessor());
  Tween.registerAccessor(RobotEntity.class, new RobotEntityAccessor());
  ContextFactory.initGlobal(new ScriptContextFactory());

  BotLogic.game         = this;
  BotLogic.inputManager = new InputManager();
  BotLogic.audio        = new AudioManager();
  BotLogic.skin         = new FlatSkin();
  BotLogic.models       = new ModelManager();
  BotLogic.sprites      = new SpritesManager();
  BotLogic.entities     = new EntityManager();
  BotLogic.config       = new ConfigManager();

  BotLogic.screens      = new ScreenManager(this);// always last!!!
  BotLogic.config.load();
  loading = false;
  fpsLogger = new FPSLogger();

  BotLogic.screens.goToMainMenu();
}
 
Example 3
Project: https-github.com-hyb1996-NoRootScriptDroid   File: RhinoJavaScriptEngine.java   Source Code and License Vote up 5 votes
protected Context createContext() {
    if (!ContextFactory.hasExplicitGlobal()) {
        ContextFactory.initGlobal(new InterruptibleAndroidContextFactory(new File(mAndroidContext.getCacheDir(), "classes")));
    }
    Context context = new RhinoAndroidHelper(mAndroidContext).enterContext();
    contextCount++;
    context.setOptimizationLevel(-1);
    context.setLanguageVersion(Context.VERSION_ES6);
    return context;
}
 
Example 4
Project: flowable-engine   File: SecureJavascriptConfigurator.java   Source Code and License Vote up 5 votes
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());
        }

        ContextFactory.initGlobal(secureScriptContextFactory);
    }
}
 
Example 5
Project: TaleCraft   File: GlobalScriptManager.java   Source Code and License Vote up 5 votes
public void init(TaleCraft taleCraft, CommonProxy proxy) {
	TaleCraft.logger.info("Initializing Rhino Script Engine...");
	globalScope = new NativeObject();
	globalClassShutter = new GlobalClassShutter();
	cache = new WrapperClassCache();
	globalContextFactory = new GlobalContextFactory();
	ContextFactory.initGlobal(globalContextFactory);

	Context cx = Context.enter();
	try {
		ScriptRuntime.initStandardObjects(cx, globalScope, true);

		globalScriptObject = new GlobalScriptObject(this);
		ScriptableObject.putProperty(globalScope, "system", Context.javaToJS(globalScriptObject, globalScope));

		consoleOutput = new ConsoleOutput();
		ScriptableObject.putProperty(globalScope, "out", Context.javaToJS(consoleOutput, globalScope));

		// String loadMe = "RegExp; getClass; java; Packages; JavaAdapter;";
		// cx.evaluateString(globalScope , loadMe, "lazyLoad", 0, null);

		// Startup Script Test
		String startupTestScript = "msg = \"Rhino Time!\"; msg;";
		Object startupTestScriptResult = cx.evaluateString(globalScope, startupTestScript, "<cmd>", 0, null);
		TaleCraft.logger.info("Startup Script Test: " + startupTestScriptResult);
	} finally {
		Context.exit();
	}

	TaleCraft.logger.info("Script Engine initialized!");
}
 
Example 6
Project: birt   File: JavascriptEngineFactory.java   Source Code and License Vote up 5 votes
public static void initMyFactory( )
{
	ContextFactory.initGlobal( new MyFactory( ) );
	if ( System.getSecurityManager( ) != null )
	{
		SecurityController.initGlobal( ScriptUtil
				.createSecurityController( ) );
	}
}
 
Example 7
Project: cloutree-modelevaluator   File: JavaScriptProcessor.java   Source Code and License Vote up 5 votes
/**
   * Constructor which initializes a local JavaScript context. This is for security reasons to not access any
   * System or application ressources but only process on parameters and variables. 
   */
  public JavaScriptProcessor() {
	
if(ContextFactory.getGlobal() == null || ContextFactory.getGlobal() instanceof SandboxContextFactory) {
    ContextFactory.initGlobal(new SandboxContextFactory());
}

  }
 
Example 8
Project: effektif   File: RhinoSandboxedScriptService.java   Source Code and License Vote up 4 votes
@Override
public void brew(Brewery brewery) {
  this.maxScriptDurationInMillis = 1*1000; // 10 seconds
  this.contextFactory = new SandboxContextFactory();
  ContextFactory.initGlobal(this.contextFactory);
}
 
Example 9
Project: effektif   File: RhinoSandboxedScriptService.java   Source Code and License Vote up 4 votes
@Override
public void brew(Brewery brewery) {
  this.maxScriptDurationInMillis = 1*1000; // 10 seconds
  this.contextFactory = new SandboxContextFactory();
  ContextFactory.initGlobal(this.contextFactory);
}
 
Example 10
Project: MinecraftScripting   File: ScriptingMod.java   Source Code and License Vote up 4 votes
@EventHandler
public void init(FMLInitializationEvent event) {
	/*
	 * Initialize our special context factory
	 */
	ContextFactory.initGlobal(new SandboxContextFactory());
	ReflectionHelper.init();
	DefaultFilters.init(new File(new File(proxy.getMinecraftDir(), "scripts"), "server"));
	FMLCommonHandler.instance().bus().register(this);
	DISPATCHER.initialize();
	
	addAbbreviation("Vec3", ScriptVec3.class);
	addAbbreviation("Vec2", ScriptVec2.class);
	addAbbreviation("ItemStack", ScriptItemStack.class);
	addAbbreviation("Rand", ScriptRandom.class);
	addAbbreviation("Array", ScriptArray.class);
	addAbbreviation("IO", ScriptIO.class);
	addAbbreviation("Script", ScriptHelper.class);
	
	addAbbreviation("Block", ScriptBlock.class);
	addAbbreviation("Item", ScriptItem.class);
	
	addAbbreviation("Setting", Setting.class);
	addAbbreviation("SettingBoolean", SettingBoolean.class);
	addAbbreviation("SettingInt", SettingInt.class);
	addAbbreviation("SettingFloat", SettingFloat.class);
	addAbbreviation("SettingString", SettingString.class);
	addAbbreviation("SettingList", SettingList.class);
	addAbbreviation("SettingBlock", SettingBlock.class);
	addAbbreviation("SettingItem", SettingItem.class);
	
	addAbbreviation("DataWatcher", ScriptDataWatcher.class);
	addAbbreviation("Entity", ScriptEntity.class);
	
	addAbbreviation("TileEntity", ScriptTileEntity.class);

	addAbbreviation("TAG_Byte", TAG_Byte.class);
	addAbbreviation("TAG_Byte_Array", TAG_Byte_Array.class);
	addAbbreviation("TAG_Compound", TAG_Compound.class);
	addAbbreviation("TAG_Double", TAG_Double.class);
	addAbbreviation("TAG_Float", TAG_Float.class);
	addAbbreviation("TAG_Int", TAG_Int.class);
	addAbbreviation("TAG_Int_Array", TAG_Int_Array.class);
	addAbbreviation("TAG_List", TAG_List.class);
	addAbbreviation("TAG_Long", TAG_Long.class);
	addAbbreviation("TAG_Short", TAG_Short.class);
	addAbbreviation("TAG_String", TAG_String.class);
}