當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。