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


Java JSType.isRepresentableAsInt方法代码示例

本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.isRepresentableAsInt方法的具体用法?Java JSType.isRepresentableAsInt怎么用?Java JSType.isRepresentableAsInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jdk.nashorn.internal.runtime.JSType的用法示例。


在下文中一共展示了JSType.isRepresentableAsInt方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: NativeArray

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
NativeArray(final long[] array) {
    this(ArrayData.allocate(array.length));

    ArrayData arrayData = this.getArray();
    Class<?> widest = int.class;

    for (int index = 0; index < array.length; index++) {
        final long value = array[index];

        if (widest == int.class && JSType.isRepresentableAsInt(value)) {
            arrayData = arrayData.set(index, (int) value, false);
        } else if (widest != Object.class && JSType.isRepresentableAsDouble(value)) {
            arrayData = arrayData.set(index, (double) value, false);
            widest = double.class;
        } else {
            arrayData = arrayData.set(index, (Object) value, false);
            widest = Object.class;
        }
    }

    this.setArray(arrayData);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:NativeArray.java

示例2: set

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public ArrayData set(final int index, final Object value, final boolean strict) {
    if (JSType.isRepresentableAsInt(value)) {
        return set(index, JSType.toInt32(value), strict);
    } else if (value == ScriptRuntime.UNDEFINED) {
        return new UndefinedArrayFilter(this).set(index, value, strict);
    }

    final ArrayData newData = convert(value == null ? Object.class : value.getClass());
    return newData.set(index, value, strict);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:IntArrayData.java

示例3: leaveCaseNode

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public Node leaveCaseNode(final CaseNode caseNode) {
    // Try to represent the case test as an integer
    final Node test = caseNode.getTest();
    if (test instanceof LiteralNode) {
        final LiteralNode<?> lit = (LiteralNode<?>)test;
        if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
            if (JSType.isRepresentableAsInt(lit.getNumber())) {
                return caseNode.setTest((Expression)LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
            }
        }
    }
    return caseNode;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:Lower.java

示例4: putSlot

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Store a value in an indexed slot of a generated class object.
 *
 * @param method Script method.
 * @param index  Slot index.
 * @param tuple  Tuple to store.
 */
private void putSlot(final MethodEmitter method, final long index, final MapTuple<T> tuple) {
    method.dup();
    if (JSType.isRepresentableAsInt(index)) {
        method.load((int)index);
    } else {
        method.load(index);
    }
    loadTuple(method, tuple, false); //we don't pack array like objects
    method.dynamicSetIndex(callSiteFlags);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:FieldObjectCreator.java

示例5: convertKey

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Returns a canonicalized key object by converting numbers to their narrowest representation and
 * ConsStrings to strings. Conversion of Double to Integer also takes care of converting -0 to 0
 * as required by step 6 of ECMA6 23.1.3.9.
 *
 * @param key a key
 * @return the canonical key
 */
static Object convertKey(final Object key) {
    if (key instanceof ConsString) {
        return key.toString();
    }
    if (key instanceof Double) {
        final Double d = (Double) key;
        if (JSType.isRepresentableAsInt(d.doubleValue())) {
            return d.intValue();
        }
    }
    return key;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:NativeMap.java

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

示例7: getIndex

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
private static int getIndex(final Number n) {
    final double value = n.doubleValue();
    return JSType.isRepresentableAsInt(value) ? (int)value : -1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:BrowserJSObjectLinker.java

示例8: parseNumber

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
private Number parseNumber() {
    final int start = pos;
    int c = next();

    if (c == '-') {
        c = next();
    }
    if (!isDigit(c)) {
        throw numberError(start);
    }
    // no more digits allowed after 0
    if (c != '0') {
        skipDigits();
    }

    // fraction
    if (peek() == '.') {
        pos++;
        if (!isDigit(next())) {
            throw numberError(pos - 1);
        }
        skipDigits();
    }

    // exponent
    c = peek();
    if (c == 'e' || c == 'E') {
        pos++;
        c = next();
        if (c == '-' || c == '+') {
            c = next();
        }
        if (!isDigit(c)) {
            throw numberError(pos - 1);
        }
        skipDigits();
    }

    final double d = Double.parseDouble(source.substring(start, pos));
    if (JSType.isRepresentableAsInt(d)) {
        return (int) d;
    }
    return d;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:JSONParser.java

示例9: loadIndex

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
MethodEmitter loadIndex(final MethodEmitter method, final long index) {
    return JSType.isRepresentableAsInt(index) ? method.load((int) index) : method.load((double) index);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:4,代码来源:ObjectCreator.java

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


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