本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptRuntime.apply方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptRuntime.apply方法的具体用法?Java ScriptRuntime.apply怎么用?Java ScriptRuntime.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ScriptRuntime
的用法示例。
在下文中一共展示了ScriptRuntime.apply方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: call
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
/**
* ECMA 15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, ... ] ] )
*
* @param self self reference
* @param args arguments for call
* @return result of call
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object call(final Object self, final Object... args) {
checkCallable(self);
final Object thiz = (args.length == 0) ? UNDEFINED : args[0];
Object[] arguments;
if (args.length > 1) {
arguments = new Object[args.length - 1];
System.arraycopy(args, 1, arguments, 0, arguments.length);
} else {
arguments = ScriptRuntime.EMPTY_ARRAY;
}
if (self instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)self, thiz, arguments);
} else if (self instanceof JSObject) {
return ((JSObject)self).call(thiz, arguments);
}
throw new AssertionError("should not reach here");
}
示例2: propertyIterator
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
@Override
public Iterator<String> propertyIterator() {
// Try __getIds__ first, if not found then try __getKeys__
// In jdk6, we had added "__getIds__" so this is just for compatibility.
Object func = adaptee.get(__getIds__);
if (!(func instanceof ScriptFunction)) {
func = adaptee.get(__getKeys__);
}
Object obj;
if (func instanceof ScriptFunction) {
obj = ScriptRuntime.apply((ScriptFunction)func, adaptee);
} else {
obj = new NativeArray(0);
}
final List<String> array = new ArrayList<>();
for (final Iterator<Object> iter = ArrayLikeIterator.arrayLikeIterator(obj); iter.hasNext(); ) {
array.add((String)iter.next());
}
return array.iterator();
}
示例3: propertyIterator
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
@Override
public Iterator<String> propertyIterator() {
// Try __getIds__ first, if not found then try __getKeys__
// In jdk6, we had added "__getIds__" so this is just for compatibility.
Object func = adaptee.get(__getIds__);
if (!(func instanceof ScriptFunction)) {
func = adaptee.get(__getKeys__);
}
Object obj;
if (func instanceof ScriptFunction) {
obj = ScriptRuntime.apply((ScriptFunction)func, this);
} else {
obj = new NativeArray(0);
}
final List<String> array = new ArrayList<>();
for (final Iterator<Object> iter = ArrayLikeIterator.arrayLikeIterator(obj); iter.hasNext(); ) {
array.add((String)iter.next());
}
return array.iterator();
}
示例4: apply
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
/**
* ECMA 15.3.4.3 Function.prototype.apply (thisArg, argArray)
*
* @param self self reference
* @param thiz {@code this} arg for apply
* @param array array of argument for apply
* @return result of apply
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object apply(final Object self, final Object thiz, final Object array) {
checkCallable(self);
final Object[] args = toApplyArgs(array);
if (self instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)self, thiz, args);
} else if (self instanceof JSObject) {
return ((JSObject)self).call(thiz, args);
}
throw new AssertionError("Should not reach here");
}
示例5: callAdaptee
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private Object callAdaptee(final Object retValue, final String name, final Object... args) {
final Object func = adaptee.get(name);
if (func instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)func, adaptee, args);
}
return retValue;
}
示例6: logEvent
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private static void logEvent(final RuntimeEvent<?> event) {
if (event != null) {
final Global global = Context.getGlobal();
if (global.has("Debug")) {
final ScriptObject debug = (ScriptObject)global.get("Debug");
final ScriptFunction addRuntimeEvent = (ScriptFunction)debug.get("addRuntimeEvent");
ScriptRuntime.apply(addRuntimeEvent, debug, event);
}
}
}
示例7: apply
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
/**
* ECMA 15.3.4.3 Function.prototype.apply (thisArg, argArray)
*
* @param self self reference
* @param thiz {@code this} arg for apply
* @param array array of argument for apply
* @return result of apply
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object apply(final Object self, final Object thiz, final Object array) {
checkCallable(self);
final Object[] args = toApplyArgs(array);
if (self instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)self, thiz, args);
} else if (self instanceof JSObject) {
return ((JSObject)self).call(thiz, args);
}
throw new AssertionError("Should not reach here");
}
示例8: callAdaptee
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private Object callAdaptee(final Object retValue, final String name, final Object... args) {
final Object func = adaptee.get(name);
if (func instanceof ScriptFunction) {
return ScriptRuntime.apply((ScriptFunction)func, this, args);
}
return retValue;
}
示例9: eval
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
private static Object eval(final Context cx, final String name, final String code) {
final Source source = sourceFor(name, code);
final ScriptObject global = Context.getGlobal();
final ScriptFunction func = cx.compileScript(source, global);
return func != null ? ScriptRuntime.apply(func, global) : null;
}
示例10: run
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
@Override
public int run(final OutputStream out, final OutputStream err, final String[] args) throws IOException {
final Global oldGlobal = Context.getGlobal();
try {
ctxOut.setDelegatee(out);
ctxErr.setDelegatee(err);
final ErrorManager errors = context.getErrorManager();
final Global global = context.createGlobal();
Context.setGlobal(global);
// For each file on the command line.
for (final String fileName : args) {
if (fileName.startsWith("-")) {
// ignore options in shared context mode (which was initialized upfront!)
continue;
}
final File file = new File(fileName);
final ScriptFunction script = context.compileScript(sourceFor(fileName, file.toURI().toURL()), global);
if (script == null || errors.getNumberOfErrors() != 0) {
return COMPILATION_ERROR;
}
try {
ScriptRuntime.apply(script, global);
} catch (final NashornException e) {
errors.error(e.toString());
if (context.getEnv()._dump_on_error) {
e.printStackTrace(context.getErr());
}
return RUNTIME_ERROR;
}
}
} finally {
context.getOut().flush();
context.getErr().flush();
Context.setGlobal(oldGlobal);
}
return SUCCESS;
}
示例11: apply
import jdk.nashorn.internal.runtime.ScriptRuntime; //导入方法依赖的package包/类
/**
* Hook to ScriptFunction "apply". A performance metering shell may
* introduce enter/exit timing here.
*
* @param target target function for apply
* @param self self reference for apply
*
* @return result of the function apply
*/
protected Object apply(final ScriptFunction target, final Object self) {
return ScriptRuntime.apply(target, self);
}