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


Java ScriptableObject.defineClass方法代碼示例

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


在下文中一共展示了ScriptableObject.defineClass方法的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: test

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
@Test
public void test() throws IllegalAccessException, InstantiationException,
        InvocationTargetException {
    Context cx = Context.enter();
    try {
        ScriptableObject scope = cx.initStandardObjects();

        // define two classes that share a parent prototype
        ScriptableObject.defineClass(scope, Fruit.class, false, true);
        ScriptableObject.defineClass(scope, Vegetable.class, false, true);

        assertEquals(Boolean.TRUE,
                evaluate(cx, scope, "(new Fruit instanceof Food)"));
        assertEquals(Boolean.TRUE,
                evaluate(cx, scope, "(new Vegetable instanceof Food)"));
    } finally {
        Context.exit();
    }
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:20,代碼來源:DefineClassMapInheritance.java

示例3: 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

示例4: defineClass

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
public static void defineClass(ScriptableObject scope) {
    try {
        ScriptableObject.defineClass(scope, Environment.class);
    } catch (Exception e) {
        throw new Error(e.getMessage());
    }
}
 
開發者ID:middle2tw,項目名稱:whackpad,代碼行數:8,代碼來源:Environment.java

示例5: init

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
@Before
public void init() throws Exception {
    Context cx = Context.enter();
    try {
        scope = cx.initStandardObjects();
        ScriptableObject.defineClass(scope, AnnotatedHostObject.class);
        ScriptableObject.defineClass(scope, TraditionalHostObject.class);
    } finally {
        Context.exit();
    }
}
 
開發者ID:F43nd1r,項目名稱:rhino-android,代碼行數:12,代碼來源:DefineClassTest.java

示例6: defineGlobalWrapperClass

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
/**
 * Defines the class for the global object.
 */
protected void defineGlobalWrapperClass(Scriptable global) {
    try {
        ScriptableObject.defineClass(global, GlobalWrapper.class);
    } catch (Exception ex) {
        // cannot happen
    }
}
 
開發者ID:git-moss,項目名稱:Push2Display,代碼行數:11,代碼來源:SVG12RhinoInterpreter.java

示例7: defineGlobalWrapperClass

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
/**
 * Defines the class for the global object.
 */
protected void defineGlobalWrapperClass(Scriptable global) {
    try {
        ScriptableObject.defineClass(global, WindowWrapper.class);
    } catch (Exception ex) {
        // cannot happen
    }
}
 
開發者ID:git-moss,項目名稱:Push2Display,代碼行數:11,代碼來源:RhinoInterpreter.java

示例8: addClass

import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
public static void addClass(Scriptable scope, Class clazz) throws IllegalAccessException,
        InstantiationException, InvocationTargetException
{
    ScriptableObject.defineClass(scope, clazz);
}
 
開發者ID:gmrodrigues,項目名稱:JsSandbox,代碼行數:6,代碼來源:JsSandboxEvaluators.java


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