本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptFunction.isStrict方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptFunction.isStrict方法的具体用法?Java ScriptFunction.isStrict怎么用?Java ScriptFunction.isStrict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ScriptFunction
的用法示例。
在下文中一共展示了ScriptFunction.isStrict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: allocate
import jdk.nashorn.internal.runtime.ScriptFunction; //导入方法依赖的package包/类
/**
* Factory to create correct Arguments object based on strict mode.
*
* @param arguments the actual arguments array passed
* @param callee the callee function that uses arguments object
* @param numParams the number of declared (named) function parameters
* @return Arguments Object
*/
public static ScriptObject allocate(final Object[] arguments, final ScriptFunction callee, final int numParams) {
// Strict functions won't always have a callee for arguments, and will pass null instead.
final boolean isStrict = callee == null || callee.isStrict();
final Global global = Global.instance();
final ScriptObject proto = global.getObjectPrototype();
if (isStrict) {
return new NativeStrictArguments(arguments, numParams, proto, NativeStrictArguments.getInitialMap());
}
return new NativeArguments(arguments, callee, numParams, proto, NativeArguments.getInitialMap());
}
示例2: sort
import jdk.nashorn.internal.runtime.ScriptFunction; //导入方法依赖的package包/类
private static Object[] sort(final Object[] array, final Object comparefn) {
final ScriptFunction cmp = compareFunction(comparefn);
final List<Object> list = Arrays.asList(array);
final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance();
Collections.sort(list, new Comparator<Object>() {
private final MethodHandle call_cmp = getCALL_CMP();
@Override
public int compare(final Object x, final Object y) {
if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) {
return 0;
} else if (x == ScriptRuntime.UNDEFINED) {
return 1;
} else if (y == ScriptRuntime.UNDEFINED) {
return -1;
}
if (cmp != null) {
try {
return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y));
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
}
return JSType.toString(x).compareTo(JSType.toString(y));
}
});
return list.toArray(new Object[array.length]);
}
示例3: getCallThis
import jdk.nashorn.internal.runtime.ScriptFunction; //导入方法依赖的package包/类
/**
* Given a script function used as a delegate for a SAM adapter, figure out
* the right object to use as its "this" when called.
* @param delegate the delegate function
* @param global the current global of the adapter
* @return either the passed global, or UNDEFINED if the function is strict.
*/
public static Object getCallThis(final ScriptFunction delegate, final Object global) {
return delegate.isStrict() ? ScriptRuntime.UNDEFINED : global;
}