本文整理汇总了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();
}
}
示例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();
}
}
示例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"));
}
示例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"));
}
示例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;
}
};
}
示例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);
}
示例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 };
}
示例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"));
}