當前位置: 首頁>>代碼示例>>Java>>正文


Java ScriptableObject.put方法代碼示例

本文整理匯總了Java中org.mozilla.javascript.ScriptableObject.put方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptableObject.put方法的具體用法?Java ScriptableObject.put怎麽用?Java ScriptableObject.put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.mozilla.javascript.ScriptableObject的用法示例。


在下文中一共展示了ScriptableObject.put方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSetNullForScriptableSetter

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
public void testSetNullForScriptableSetter() throws Exception {
	
	final String scriptCode = "foo.myProp = new Foo2();\n"
		+ "foo.myProp = null;";

	final ContextFactory factory = new ContextFactory();
	final Context cx = factory.enterContext();

	try {
        final ScriptableObject topScope = cx.initStandardObjects();
        final Foo foo = new Foo();

        // define custom setter method
        final Method setMyPropMethod = Foo.class.getMethod("setMyProp", Foo2.class);
        foo.defineProperty("myProp", null, null, setMyPropMethod, ScriptableObject.EMPTY);

        topScope.put("foo", topScope, foo);
        
        ScriptableObject.defineClass(topScope, Foo2.class);
		
        cx.evaluateString(topScope, scriptCode, "myScript", 1, null);
	}
	finally {
		Context.exit();
	}
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:27,代碼來源:CustomSetterAcceptNullScriptableTest.java

示例2: testSetNullForScriptableSetter

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
public void testSetNullForScriptableSetter() throws Exception {

		final String scriptCode = "foo.myProp = new Foo2();\n"
			+ "foo.myProp = null;";

		final Context cx = RhinoAndroidHelper.prepareContext();

		try {
	        final ScriptableObject topScope = cx.initStandardObjects();
	        final Foo foo = new Foo();

	        // define custom setter method
	        final Method setMyPropMethod = Foo.class.getMethod("setMyProp", Foo2.class);
	        foo.defineProperty("myProp", null, null, setMyPropMethod, ScriptableObject.EMPTY);

	        topScope.put("foo", topScope, foo);

	        ScriptableObject.defineClass(topScope, Foo2.class);

	        cx.evaluateString(topScope, scriptCode, "myScript", 1, null);
		}
		finally {
			Context.exit();
		}
	}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:26,代碼來源:CustomSetterAcceptNullScriptableTest.java

示例3: executeModuleScript

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
private Scriptable executeModuleScript(Context cx, String id,
        Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
    final ScriptableObject moduleObject = (ScriptableObject)cx.newObject(
            nativeScope);
    URI uri = moduleScript.getUri();
    URI base = moduleScript.getBase();
    defineReadOnlyProperty(moduleObject, "id", id);
    if(!sandboxed) {
        defineReadOnlyProperty(moduleObject, "uri", uri.toString());
    }
    final Scriptable executionScope = new ModuleScope(nativeScope, uri, base);
    // Set this so it can access the global JS environment objects.
    // This means we're currently using the "MGN" approach (ModuleScript
    // with Global Natives) as specified here:
    // <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension>
    executionScope.put("exports", executionScope, exports);
    executionScope.put("module", executionScope, moduleObject);
    moduleObject.put("exports", moduleObject, exports);
    install(executionScope);
    if(isMain) {
        defineReadOnlyProperty(this, "main", moduleObject);
    }
    executeOptionalScript(preExec, cx, executionScope);
    moduleScript.getScript().exec(cx, executionScope);
    executeOptionalScript(postExec, cx, executionScope);
    return ScriptRuntime.toObject(cx, nativeScope,
            ScriptableObject.getProperty(moduleObject, "exports"));
}
 
開發者ID:MikaGuraN,項目名稱:HL4A,代碼行數:30,代碼來源:Require.java

示例4: executeModuleScript

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
private Scriptable executeModuleScript(Context cx, String id,
        Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
    final ScriptableObject moduleObject = (ScriptableObject)cx.newObject(
            nativeScope);
    URI uri = moduleScript.getUri();
    URI base = moduleScript.getBase();
    defineReadOnlyProperty(moduleObject, "id", id);
    if(!sandboxed) {
        defineReadOnlyProperty(moduleObject, "uri", uri.toString());
    }
    final Scriptable executionScope = new ModuleScope(nativeScope, uri, base);
    // Set this so it can access the global JS environment objects. 
    // This means we're currently using the "MGN" approach (ModuleScript 
    // with Global Natives) as specified here: 
    // <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension>
    executionScope.put("exports", executionScope, exports);
    executionScope.put("module", executionScope, moduleObject);
    moduleObject.put("exports", moduleObject, exports);
    install(executionScope);
    if(isMain) {
        defineReadOnlyProperty(this, "main", moduleObject);
    }
    executeOptionalScript(preExec, cx, executionScope);
    moduleScript.getScript().exec(cx, executionScope);
    executeOptionalScript(postExec, cx, executionScope);
    return ScriptRuntime.toObject(nativeScope,
            ScriptableObject.getProperty(moduleObject, "exports"));
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:30,代碼來源:Require.java

示例5: action

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
private static ContextAction action(final String fn, final Action a) {
    return new ContextAction() {
        public Object run(Context cx) {
            ScriptableObject scope1 = cx.initStandardObjects();
            ScriptableObject scope2 = cx.initStandardObjects();
            scope1.put("scope2", scope1, scope2);

            eval(cx, scope2, fn);
            a.run(cx, scope1, scope2);

            return null;
        }
    };
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:15,代碼來源:Bug783797Test.java

示例6: testIntArrayThenRemove

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
@Test
public void testIntArrayThenRemove()
{
    ScriptableObject a = (ScriptableObject)cx.newObject(root);
    // Set the external array data
    TestIntArray l = new TestIntArray(10);
    a.setExternalArrayData(l);
    for (int i = 0; i < 10; i++) {
        l.setArrayElement(i, i);
    }
    root.put("testArray", root, a);
    root.put("testArrayLength", root, 10);
    root.put("regularArray", root, false);
    runScript("jstests/extensions/external-array-test.js", 1);

    // Clear it and test again. When cleared, object should go back to behaving like a
    // regular JavaScript object.
    a.delete("stringField");
    a.delete("intField");
    a.setExternalArrayData(null);
    for (int i = 0; i < 10; i++) {
        a.put(i, a, i);
    }
    a.defineProperty("length", 10, ScriptableObject.DONTENUM);
    root.put("regularArray", root, true);
    runScript("jstests/extensions/external-array-test.js", 1);
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:28,代碼來源:ExternalArrayTest.java

示例7: buildArguments

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
public Object[] buildArguments() {
    ScriptableObject so = new NativeObject();
    so.put("success", so,
           (success) ? Boolean.TRUE : Boolean.FALSE);
    if (mime != null) {
        so.put("contentType", so,
               Context.toObject(mime, windowWrapper));
    }
    if (content != null) {
        so.put("content", so,
               Context.toObject(content, windowWrapper));
    }
    return new Object [] { so };
}
 
開發者ID:git-moss,項目名稱:Push2Display,代碼行數:15,代碼來源:WindowWrapper.java

示例8: executeModuleScript

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
private Scriptable executeModuleScript(Context cx, String id,
        Scriptable exports, ModuleScript moduleScript, boolean isMain)
{
    final ScriptableObject moduleObject = (ScriptableObject)cx.newObject(
            nativeScope);
    URI uri = moduleScript.getUri();
    URI base = moduleScript.getBase();
    defineReadOnlyProperty(moduleObject, "id", id);
    if(!sandboxed) {
        defineReadOnlyProperty(moduleObject, "uri", uri.toString());
    }
    final Scriptable executionScope = new ModuleScope(nativeScope, uri, base);
    // Set this so it can access the global JS environment objects.
    // This means we're currently using the "MGN" approach (ModuleScript
    // with Global Natives) as specified here:
    // <http://wiki.commonjs.org/wiki/Modules/ProposalForNativeExtension>
    executionScope.put("exports", executionScope, exports);
    executionScope.put("module", executionScope, moduleObject);
    moduleObject.put("exports", moduleObject, exports);
    install(executionScope);
    if(isMain) {
        defineReadOnlyProperty(this, "main", moduleObject);
    }
    executeOptionalScript(preExec, cx, executionScope);
    moduleScript.getScript().exec(cx, executionScope);
    executeOptionalScript(postExec, cx, executionScope);
    return ScriptRuntime.toObject(nativeScope,
            ScriptableObject.getProperty(moduleObject, "exports"));
}
 
開發者ID:tiffit,項目名稱:TaleCraft,代碼行數:30,代碼來源:Require.java


注:本文中的org.mozilla.javascript.ScriptableObject.put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。