本文整理匯總了Java中jdk.nashorn.api.scripting.ScriptObjectMirror.unwrap方法的典型用法代碼示例。如果您正苦於以下問題:Java ScriptObjectMirror.unwrap方法的具體用法?Java ScriptObjectMirror.unwrap怎麽用?Java ScriptObjectMirror.unwrap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類jdk.nashorn.api.scripting.ScriptObjectMirror
的用法示例。
在下文中一共展示了ScriptObjectMirror.unwrap方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: __noSuchProperty__
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
/**
* Hook to search missing variables in ScriptContext if available
* @param self used to detect if scope call or not (this function is 'strict')
* @param name name of the variable missing
* @return value of the missing variable or undefined (or TypeError for scope search)
*/
public static Object __noSuchProperty__(final Object self, final Object name) {
final Global global = Global.instance();
final ScriptContext sctxt = global.scontext;
final String nameStr = name.toString();
if (sctxt != null) {
final int scope = sctxt.getAttributesScope(nameStr);
if (scope != -1) {
return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global);
}
}
switch (nameStr) {
case "context":
return sctxt;
case "engine":
return global.engine;
default:
break;
}
if (self == UNDEFINED) {
// scope access and so throw ReferenceError
throw referenceError(global, "not.defined", nameStr);
}
return UNDEFINED;
}
示例2: loadWithNewGlobal
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的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);
}
}
示例3: openWith
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
/**
* Entering a {@code with} node requires new scope. This is the implementation. When exiting the with statement,
* use {@link ScriptObject#getProto()} on the scope.
*
* @param scope existing scope
* @param expression expression in with
*
* @return {@link WithObject} that is the new scope
*/
public static ScriptObject openWith(final ScriptObject scope, final Object expression) {
final Global global = Context.getGlobal();
if (expression == UNDEFINED) {
throw typeError(global, "cant.apply.with.to.undefined");
} else if (expression == null) {
throw typeError(global, "cant.apply.with.to.null");
}
if (expression instanceof ScriptObjectMirror) {
final Object unwrapped = ScriptObjectMirror.unwrap(expression, global);
if (unwrapped instanceof ScriptObject) {
return new WithObject(scope, (ScriptObject)unwrapped);
}
// foreign ScriptObjectMirror
final ScriptObject exprObj = global.newObject();
NativeObject.bindAllProperties(exprObj, (ScriptObjectMirror)expression);
return new WithObject(scope, exprObj);
}
final Object wrappedExpr = JSType.toScriptObject(global, expression);
if (wrappedExpr instanceof ScriptObject) {
return new WithObject(scope, (ScriptObject)wrappedExpr);
}
throw typeError(global, "cant.apply.with.to.non.scriptobject");
}
示例4: __noSuchProperty__
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
/**
* Hook to search missing variables in ScriptContext if available
* @param self used to detect if scope call or not (this function is 'strict')
* @param name name of the variable missing
* @return value of the missing variable or undefined (or TypeError for scope search)
*/
public static Object __noSuchProperty__(final Object self, final Object name) {
final Global global = Global.instance();
final ScriptContext sctxt = global.currentContext();
final String nameStr = name.toString();
if (sctxt != null) {
final int scope = sctxt.getAttributesScope(nameStr);
if (scope != -1) {
return ScriptObjectMirror.unwrap(sctxt.getAttribute(nameStr, scope), global);
}
}
switch (nameStr) {
case "context":
return sctxt;
case "engine":
return global.engine;
default:
break;
}
if (self == UNDEFINED) {
// scope access and so throw ReferenceError
throw referenceError(global, "not.defined", nameStr);
}
return UNDEFINED;
}
示例5: unwrap
import jdk.nashorn.api.scripting.ScriptObjectMirror; //導入方法依賴的package包/類
/**
* Unwraps this adapter into its underlying non-JSObject representative.
* @param homeGlobal the home global for unwrapping
* @return either the unwrapped object or this if it should not be unwrapped in the specified global.
*/
public Object unwrap(final Object homeGlobal) {
final Object unwrapped = ScriptObjectMirror.unwrap(obj, homeGlobal);
return unwrapped != obj ? unwrapped : this;
}