当前位置: 首页>>代码示例>>Java>>正文


Java JSType.toInteger方法代码示例

本文整理汇总了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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:28,代码来源:NativeNumber.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:HistoryObject.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:NativeString.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:NativeString.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:NativeString.java

示例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));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:NativeNumber.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:NativeRegExp.java


注:本文中的jdk.nashorn.internal.runtime.JSType.toInteger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。