本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.toInteger方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.toInteger方法的具体用法?Java JSType.toInteger怎么用?Java JSType.toInteger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.JSType
的用法示例。
在下文中一共展示了JSType.toInteger方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toExponential
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.7.4.6 Number.prototype.toExponential (fractionDigits)
*
* @param self self reference
* @param fractionDigits how many digital should be after the significand's decimal point. If undefined, use as many as necessary to uniquely specify number.
*
* @return number in decimal exponential notation
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toExponential(final Object self, final Object fractionDigits) {
final double x = getNumberValue(self);
final boolean trimZeros = fractionDigits == UNDEFINED;
final int f = trimZeros ? 16 : JSType.toInteger(fractionDigits);
if (Double.isNaN(x)) {
return "NaN";
} else if (Double.isInfinite(x)) {
return x > 0? "Infinity" : "-Infinity";
}
if (fractionDigits != UNDEFINED && (f < 0 || f > 20)) {
throw rangeError("invalid.fraction.digits", "toExponential");
}
final String res = String.format(Locale.US, "%1." + f + "e", x);
return fixExponent(res, trimZeros);
}
示例2: call
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public Object call(final Object thiz, final Object... args) {
if (args.length > 0) {
int index = JSType.toInteger(args[0]);
if (index < 0) {
index += (hist.size() - 1);
} else {
index--;
}
if (index >= 0 && index < (hist.size() - 1)) {
final CharSequence src = hist.get(index);
hist.replace(src);
err.println(src);
evaluator.accept(src.toString());
} else {
hist.removeLast();
err.println("no history entry @ " + (index + 1));
}
}
return UNDEFINED;
}
示例3: charCodeAt
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.5.4.5 String.prototype.charCodeAt (pos)
* @param self self reference
* @param pos position in string
* @return number representing charcode at position
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double charCodeAt(final Object self, final Object pos) {
final String str = checkObjectToString(self);
final int idx = JSType.toInteger(pos);
return idx < 0 || idx >= str.length() ? Double.NaN : str.charAt(idx);
}
示例4: substr
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA B.2.3 String.prototype.substr (start, length)
*
* @param self self reference
* @param start start position
* @param length length of section
* @return substring given start and length of section
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String substr(final Object self, final Object start, final Object length) {
final String str = JSType.toString(self);
final int strLength = str.length();
int intStart = JSType.toInteger(start);
if (intStart < 0) {
intStart = Math.max(intStart + strLength, 0);
}
final int intLen = Math.min(Math.max(length == UNDEFINED ? Integer.MAX_VALUE : JSType.toInteger(length), 0), strLength - intStart);
return intLen <= 0 ? "" : str.substring(intStart, intStart + intLen);
}
示例5: canLink
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public boolean canLink(final Object self, final CallSiteDescriptor desc, final LinkRequest request) {
try {
//check that it's a char sequence or throw cce
final CharSequence cs = (CharSequence)self;
//check that the index, representable as an int, is inside the array
final int intIndex = JSType.toInteger(request.getArguments()[2]);
return intIndex >= 0 && intIndex < cs.length(); //can link
} catch (final ClassCastException | IndexOutOfBoundsException e) {
//fallthru
}
return false;
}
示例6: toString
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.7.4.2 Number.prototype.toString ( [ radix ] )
*
* @param self self reference
* @param radix radix to use for string conversion
* @return string representation of this Number in the given radix
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String toString(final Object self, final Object radix) {
if (radix != UNDEFINED) {
final int intRadix = JSType.toInteger(radix);
if (intRadix != 10) {
if (intRadix < 2 || intRadix > 36) {
throw rangeError("invalid.radix");
}
return JSType.toString(getNumberValue(self), intRadix);
}
}
return JSType.toString(getNumberValue(self));
}
示例7: getLastIndex
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* Fast lastIndex getter
* @return last index property as int
*/
public int getLastIndex() {
return JSType.toInteger(lastIndex);
}