当前位置: 首页>>代码示例>>Java>>正文


Java ScriptableObject.putProperty方法代码示例

本文整理汇总了Java中org.mozilla.javascript.ScriptableObject.putProperty方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptableObject.putProperty方法的具体用法?Java ScriptableObject.putProperty怎么用?Java ScriptableObject.putProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mozilla.javascript.ScriptableObject的用法示例。


在下文中一共展示了ScriptableObject.putProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: runScript

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
/**
 * 执行JS
 * 
 * @param js js代码
 * @param functionName js方法名称
 * @param functionParams js方法参数
 * @return
 */
public static String runScript(Context context, String js, String functionName, Object[] functionParams) {
	org.mozilla.javascript.Context rhino = org.mozilla.javascript.Context.enter();
	rhino.setOptimizationLevel(-1);
	try {
		Scriptable scope = rhino.initStandardObjects();

		ScriptableObject.putProperty(scope, "javaContext", org.mozilla.javascript.Context.javaToJS(context, scope));
		ScriptableObject.putProperty(scope, "javaLoader", org.mozilla.javascript.Context.javaToJS(context.getClass().getClassLoader(), scope));

		rhino.evaluateString(scope, js, context.getClass().getSimpleName(), 1, null);

		Function function = (Function) scope.get(functionName, scope);

		Object result = function.call(rhino, scope, scope, functionParams);
		if (result instanceof String) {
			return (String) result;
		} else if (result instanceof NativeJavaObject) {
			return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
		} else if (result instanceof NativeObject) {
			return (String) ((NativeObject) result).getDefaultValue(String.class);
		}
		return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
	} finally {
		org.mozilla.javascript.Context.exit();
	}
}
 
开发者ID:SShineTeam,项目名称:Huochexing12306,代码行数:35,代码来源:A6Util.java

示例2: createTest

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
private static Test createTest(final File testDir, final String name) {
    return new TestCase(name) {
        @Override
        public int countTestCases() {
            return 1;
        }
        @Override
        public void runBare() throws Throwable {
            final Context cx = Context.enter();
            try {
                cx.setOptimizationLevel(-1);
                final Scriptable scope = cx.initStandardObjects();
                ScriptableObject.putProperty(scope, "print", new Print(scope));
                createRequire(testDir, cx, scope).requireMain(cx, "program");
            }
            finally {
                Context.exit();
            }
        }
    };
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:22,代码来源:ComplianceTest.java

示例3: runScript

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
public String runScript(String js, String functionName, Object[] functionParams) {
    Context rhino = Context.enter();
    rhino.setOptimizationLevel(-1);
    try {
        Scriptable scope = rhino.initStandardObjects();

        ScriptableObject.putProperty(scope, "javaContext", Context.javaToJS(mActivity.getContext(), scope));
        ScriptableObject.putProperty(scope, "javaLoader", Context.javaToJS(ChapterActivity.class.getClassLoader(), scope));

        rhino.evaluateString(scope, js, "ChapterActivity", 1, null);

        Function function = (Function) scope.get(functionName, scope);

        Object result = function.call(rhino, scope, scope, functionParams);
        if (result instanceof String) {
            return (String) result;
        } else if (result instanceof NativeJavaObject) {
            return (String) ((NativeJavaObject) result).getDefaultValue(String.class);
        } else if (result instanceof NativeObject) {
            return (String) ((NativeObject) result).getDefaultValue(String.class);
        }
        return result.toString();//(String) function.call(rhino, scope, scope, functionParams);
    } finally {
        Context.exit();
    }
}
 
开发者ID:hanFengSan,项目名称:Yakami-manga,代码行数:27,代码来源:ChapterController.java

示例4: createNewDecorationScope

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
public Scriptable createNewDecorationScope(World world, BlockPos[] pos, NBTTagCompound options) {
	Context cx = Context.enter();
	Scriptable newScope = cx.newObject(globalScope);
	newScope.setPrototype(globalScope);
	newScope.setParentScope(null);
	MutableBlockPos[] mpos = new MutableBlockPos[pos.length];
	for(int i = 0; i < pos.length; i++){
		mpos[i] = new MutableBlockPos(pos[i]);
	}
	ScriptableObject.putProperty(newScope, "positions", Context.javaToJS(mpos, newScope));
	ScriptableObject.putProperty(newScope, "world", Context.javaToJS(new WorldObjectWrapper(world), newScope));
	ScriptableObject.putProperty(newScope, "options", Context.javaToJS(new CompoundTagWrapper(options), newScope));
	Context.exit();

	return newScope;
}
 
开发者ID:tiffit,项目名称:TaleCraft,代码行数:17,代码来源:GlobalScriptManager.java

示例5: init

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@Override
public void init() {
    mThread = Thread.currentThread();
    ScriptableObject.putProperty(mScriptable, "__engine__", this);
    mRequirePath = (String[]) getTag(TAG_PATH);
    initRequireBuilder(mContext, mScriptable);
    mContext.evaluateString(mScriptable, getInitScript().getScript(), "<init>", 1, null);
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:9,代码来源:RhinoJavaScriptEngine.java

示例6: put

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object put(final Object key, final Object value) {
    keySet().add(key);
    final Object oldValue = get(key);
    if (key instanceof Number) {
        ScriptableObject.putProperty(s, ((Number) key).intValue(), value);
    } else {
        ScriptableObject.putProperty(s, String.valueOf(key), value);
    }
    return oldValue;
}
 
开发者ID:szegedi,项目名称:spring-web-jsflow,代码行数:13,代码来源:ScriptableMap.java

示例7: testNonSandboxed

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
public void testNonSandboxed() throws Exception
{
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm();
    ScriptableObject.putProperty(scope, "moduleUri", jsFile);
    require.requireMain(cx, "testNonSandboxed");
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:10,代码来源:RequireTest.java

示例8: testNonSandboxed

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
public void testNonSandboxed() throws Exception {
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    final String jsFile = TestUtils.readAsset(dir + File.separator + "testNonSandboxed.js");
    ScriptableObject.putProperty(scope, "moduleUri", jsFile);
    require.requireMain(cx, "testNonSandboxed");
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:9,代码来源:RequireTest.java

示例9: testNonSandboxed

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@Override
public void testNonSandboxed() throws Exception
{
    final Context cx = createContext();
    final Scriptable scope = cx.initStandardObjects();
    final Require require = getSandboxedRequire(cx, scope, false);
    final String jsFile = getClass().getResource("testNonSandboxed.js").toExternalForm();
    ScriptableObject.putProperty(scope, "moduleUri", jsFile);
    require.requireMain(cx, "testNonSandboxed");
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:11,代码来源:RequireJarTest.java

示例10: testRequire

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@org.junit.Test
public void testRequire() throws Throwable {
    final Context cx = RhinoAndroidHelper.prepareContext();
    try {
        cx.setOptimizationLevel(-1);
        final Scriptable scope = cx.initStandardObjects();
        ScriptableObject.putProperty(scope, "print", new Print(scope));
        createRequire(testDir, cx, scope).requireMain(cx, "program");
    } finally {
        Context.exit();
    }
}
 
开发者ID:F43nd1r,项目名称:rhino-android,代码行数:13,代码来源:ComplianceTest.java

示例11: putScopeObject

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@Override
public void putScopeObject(String name, Object obj) {
    try {
        Context cx = Context.enter();
        cx.setOptimizationLevel(-1); // always interpretive mode          
        ScriptableObject.putProperty(scope, name, Context.javaToJS(obj, scope));
    } finally {
        Context.exit();            
    }            
}
 
开发者ID:adrianromero,项目名称:helloiot,代码行数:11,代码来源:Rhino.java

示例12: putScopeFunction

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@Override
public void putScopeFunction(String name, Object obj, String method, int params) throws ScriptExecException {
    try {
        Context cx = Context.enter();
        cx.setOptimizationLevel(-1); // always interpretive mode                     
        ScriptableObject.putProperty(scope, "__" + name, Context.javaToJS(obj, scope));         
        cx.evaluateString(scope, "function " + name + "(" + createArgs(params) + ") {return __" + name +"." + method + "(" + createArgs(params) + ");}", "<cmd>", 1, null);
    } finally {
        Context.exit();            
    }
}
 
开发者ID:adrianromero,项目名称:helloiot,代码行数:12,代码来源:Rhino.java

示例13: putScopeMap

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
@Override
public void putScopeMap(Map<String, Object> params) throws ScriptExecException {
    try {
        Context cx = Context.enter();
        cx.setOptimizationLevel(-1); // always interpretive mode     
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            ScriptableObject.putProperty(scope, entry.getKey(), Context.javaToJS(entry.getValue(), scope));
        }
    } finally {
        Context.exit();            
    }            
}
 
开发者ID:adrianromero,项目名称:helloiot,代码行数:13,代码来源:Rhino.java

示例14: init

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
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!");
}
 
开发者ID:tiffit,项目名称:TaleCraft,代码行数:32,代码来源:GlobalScriptManager.java

示例15: createNewBlockScope

import org.mozilla.javascript.ScriptableObject; //导入方法依赖的package包/类
public Scriptable createNewBlockScope(World world, BlockPos blockpos) {
	Context cx = Context.enter();
	Scriptable newScope = cx.newObject(globalScope);
	newScope.setPrototype(globalScope);
	newScope.setParentScope(null);

	ScriptableObject.putProperty(newScope, "position", Context.javaToJS(new MutableBlockPos(blockpos), newScope));
	ScriptableObject.putProperty(newScope, "world", Context.javaToJS(new WorldObjectWrapper(world), newScope));

	Context.exit();

	return newScope;
}
 
开发者ID:tiffit,项目名称:TaleCraft,代码行数:14,代码来源:GlobalScriptManager.java


注:本文中的org.mozilla.javascript.ScriptableObject.putProperty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。