本文整理汇总了Java中jdk.nashorn.internal.objects.Global.put方法的典型用法代码示例。如果您正苦于以下问题:Java Global.put方法的具体用法?Java Global.put怎么用?Java Global.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.objects.Global
的用法示例。
在下文中一共展示了Global.put方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadWithNewGlobal
import jdk.nashorn.internal.objects.Global; //导入方法依赖的package包/类
/**
* Implementation of {@code loadWithNewGlobal} Nashorn extension. Load a script file from a source
* expression, after creating a new global scope.
*
* @param from source expression for script
* @param args (optional) arguments to be passed to the loaded script
*
* @return return value for load call (undefined)
*
* @throws IOException if source cannot be found or loaded
*/
public Object loadWithNewGlobal(final Object from, final Object...args) throws IOException {
final Global oldGlobal = getGlobal();
final Global newGlobal = AccessController.doPrivileged(new PrivilegedAction<Global>() {
@Override
public Global run() {
try {
return newGlobal();
} catch (final RuntimeException e) {
if (Context.DEBUG) {
e.printStackTrace();
}
throw e;
}
}
}, CREATE_GLOBAL_ACC_CTXT);
// initialize newly created Global instance
initGlobal(newGlobal);
setGlobal(newGlobal);
final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal);
newGlobal.put("arguments", newGlobal.wrapAsObject(wrapped), env._strict);
try {
// wrap objects from newGlobal's world as mirrors - but if result
// is from oldGlobal's world, unwrap it!
return ScriptObjectMirror.unwrap(ScriptObjectMirror.wrap(load(newGlobal, from), newGlobal), oldGlobal);
} finally {
setGlobal(oldGlobal);
}
}