当前位置: 首页>>代码示例>>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;未经允许,请勿转载。