本文整理汇总了Java中jdk.nashorn.internal.runtime.linker.Bootstrap.isStrictCallable方法的典型用法代码示例。如果您正苦于以下问题:Java Bootstrap.isStrictCallable方法的具体用法?Java Bootstrap.isStrictCallable怎么用?Java Bootstrap.isStrictCallable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.linker.Bootstrap
的用法示例。
在下文中一共展示了Bootstrap.isStrictCallable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
/**
* Apply action main loop.
* @return result of apply
*/
public final T apply() {
final boolean strict = Bootstrap.isStrictCallable(callbackfn);
// for non-strict callback, need to translate undefined thisArg to be global object
thisArg = (thisArg == ScriptRuntime.UNDEFINED && !strict)? Context.getGlobal() : thisArg;
applyLoopBegin(iter);
final boolean reverse = iter.isReverse();
while (iter.hasNext()) {
final Object val = iter.next();
index = iter.nextIndex() + (reverse ? 1 : -1);
try {
if (!forEach(val, index)) {
return result;
}
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
}
return result;
}
示例2: sort
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static Object[] sort(final Object[] array, final Object comparefn) {
final Object cmp = compareFunction(comparefn);
final List<Object> list = Arrays.asList(array);
final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();
try {
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));
}
});
} catch (final IllegalArgumentException iae) {
// Collections.sort throws IllegalArgumentException when
// Comparison method violates its general contract
// See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
// If "comparefn" is not undefined and is not a consistent
// comparison function for the elements of this array, the
// behaviour of sort is implementation-defined.
}
return list.toArray(new Object[0]);
}
示例3: sort
import jdk.nashorn.internal.runtime.linker.Bootstrap; //导入方法依赖的package包/类
private static Object[] sort(final Object[] array, final Object comparefn) {
final Object cmp = compareFunction(comparefn);
final List<Object> list = Arrays.asList(array);
final Object cmpThis = cmp == null || Bootstrap.isStrictCallable(cmp) ? ScriptRuntime.UNDEFINED : Global.instance();
try {
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));
}
});
} catch (final IllegalArgumentException iae) {
// Collections.sort throws IllegalArgumentException when
// Comparison method violates its general contract
// See ECMA spec 15.4.4.11 Array.prototype.sort (comparefn).
// If "comparefn" is not undefined and is not a consistent
// comparison function for the elements of this array, the
// behaviour of sort is implementation-defined.
}
return list.toArray(new Object[array.length]);
}