本文整理匯總了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();
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
}
示例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();
}
}
示例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
}
}
示例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
}
}
示例8: addClass
import org.mozilla.javascript.ScriptableObject; //導入方法依賴的package包/類
public static void addClass(Scriptable scope, Class clazz) throws IllegalAccessException,
InstantiationException, InvocationTargetException
{
ScriptableObject.defineClass(scope, clazz);
}