本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.isRepresentableAsLong方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.isRepresentableAsLong方法的具体用法?Java JSType.isRepresentableAsLong怎么用?Java JSType.isRepresentableAsLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.JSType
的用法示例。
在下文中一共展示了JSType.isRepresentableAsLong方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validLength
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
static long validLength(final Object length, final boolean reject) {
final double doubleLength = JSType.toNumber(length);
if (!Double.isNaN(doubleLength) && JSType.isRepresentableAsLong(doubleLength)) {
final long len = (long) doubleLength;
if (len >= 0 && len <= JSType.MAX_UINT) {
return len;
}
}
if (reject) {
throw rangeError("inappropriate.array.length", ScriptRuntime.safeToString(length));
}
return -1;
}
示例2: set
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public ArrayData set(final int index, final double value, final boolean strict) {
if (JSType.isRepresentableAsLong(value)) {
array[index] = (long)value;
setLength(Math.max(index + 1, length()));
return this;
}
return convert(Double.class).set(index, value, strict);
}
示例3: getValueOf
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* Return value of token given its token descriptor.
*
* @param token Token descriptor.
* @return JavaScript value.
*/
Object getValueOf(final long token, final boolean strict) {
final int start = Token.descPosition(token);
final int len = Token.descLength(token);
switch (Token.descType(token)) {
case DECIMAL:
return Lexer.valueOf(source.getString(start, len), 10); // number
case OCTAL:
return Lexer.valueOf(source.getString(start, len), 8); // number
case HEXADECIMAL:
return Lexer.valueOf(source.getString(start + 2, len - 2), 16); // number
case FLOATING:
final String str = source.getString(start, len);
final double value = Double.valueOf(str);
if (str.indexOf('.') != -1) {
return value; //number
}
//anything without an explicit decimal point is still subject to a
//"representable as int or long" check. Then the programmer does not
//explicitly code something as a double. For example new Color(int, int, int)
//and new Color(float, float, float) will get ambiguous for cases like
//new Color(1.0, 1.5, 1.5) if we don't respect the decimal point.
//yet we don't want e.g. 1e6 to be a double unnecessarily
if (JSType.isRepresentableAsInt(value) && !JSType.isNegativeZero(value)) {
return (int)value;
} else if (JSType.isRepresentableAsLong(value) && !JSType.isNegativeZero(value)) {
return (long)value;
}
return value;
case STRING:
return source.getString(start, len); // String
case ESCSTRING:
return valueOfString(start, len, strict); // String
case IDENT:
return valueOfIdent(start, len); // String
case REGEX:
return valueOfPattern(start, len); // RegexToken::LexerToken
case XML:
return valueOfXML(start, len); // XMLToken::LexerToken
case DIRECTIVE_COMMENT:
return source.getString(start, len);
default:
break;
}
return null;
}
示例4: getArrayIndex
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* Return a valid index for this double, if it represents one.
*
* Doubles that aren't representable exactly as longs/ints aren't working
* array indexes, however, array[1.1] === array["1.1"] in JavaScript.
*
* @param key the key to check
* @return the array index this double represents or {@code -1} if this isn't a valid index.
* Note that negative return values other than {@code -1} are considered valid and can be converted to
* the actual index using {@link #toLongIndex(int)}.
*/
public static int getArrayIndex(final double key) {
if (JSType.isRepresentableAsInt(key)) {
return getArrayIndex((int) key);
} else if (JSType.isRepresentableAsLong(key)) {
return getArrayIndex((long) key);
}
return INVALID_ARRAY_INDEX;
}