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


Java JSType.toLong方法代码示例

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


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

示例1: slice

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.10 Array.prototype.slice ( start [ , end ] )
 *
 * @param self  self reference
 * @param start start of slice (inclusive)
 * @param end   end of slice (optional, exclusive)
 * @return sliced array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object slice(final Object self, final Object start, final Object end) {
    final Object       obj                 = Global.toObject(self);
    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final ScriptObject sobj                = (ScriptObject)obj;
    final long         len                 = JSType.toUint32(sobj.getLength());
    final long         relativeStart       = JSType.toLong(start);
    final long         relativeEnd         = end == ScriptRuntime.UNDEFINED ? len : JSType.toLong(end);

    long k = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
    final long finale = relativeEnd < 0 ? Math.max(len + relativeEnd, 0) : Math.min(relativeEnd, len);

    if (k >= finale) {
        return new NativeArray(0);
    }

    if (bulkable(sobj)) {
        return new NativeArray(sobj.getArray().slice(k, finale));
    }

    // Construct array with proper length to have a deleted filter on undefined elements
    final NativeArray copy = new NativeArray(finale - k);
    for (long n = 0; k < finale; n++, k++) {
        if (sobj.has(k)) {
            copy.defineOwnProperty(ArrayIndex.getArrayIndex(n), sobj.get(k));
        }
    }

    return copy;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:42,代码来源:NativeArray.java

示例2: indexOf

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.14 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
 *
 * @param self           self reference
 * @param searchElement  element to search for
 * @param fromIndex      start index of search
 * @return index of element, or -1 if not found
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static long indexOf(final Object self, final Object searchElement, final Object fromIndex) {
    try {
        final ScriptObject sobj = (ScriptObject)Global.toObject(self);
        final long         len  = JSType.toUint32(sobj.getLength());
        if (len == 0) {
            return -1;
        }

        final long         n = JSType.toLong(fromIndex);
        if (n >= len) {
            return -1;
        }


        for (long k = Math.max(0, n < 0 ? len - Math.abs(n) : n); k < len; k++) {
            if (sobj.has(k)) {
                if (ScriptRuntime.EQ_STRICT(sobj.get(k), searchElement)) {
                    return k;
                }
            }
        }
    } catch (final ClassCastException | NullPointerException e) {
        //fallthru
    }

    return -1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:NativeArray.java

示例3: lastIndexOf

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
 *
 * @param self self reference
 * @param args arguments: element to search for and optional from index
 * @return index of element, or -1 if not found
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static long lastIndexOf(final Object self, final Object... args) {
    try {
        final ScriptObject sobj = (ScriptObject)Global.toObject(self);
        final long         len  = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            return -1;
        }

        final Object searchElement = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
        final long   n             = args.length > 1 ? JSType.toLong(args[1]) : len - 1;

        for (long k = n < 0 ? len - Math.abs(n) : Math.min(n, len - 1); k >= 0; k--) {
            if (sobj.has(k)) {
                if (ScriptRuntime.EQ_STRICT(sobj.get(k), searchElement)) {
                    return k;
                }
            }
        }
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }

    return -1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:NativeArray.java

示例4: toLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
private static Long toLong(final Object obj0) {
    // TODO - Order tests for performance.
    for (Object obj = obj0; ;) {
        if (obj == null) {
            return null;
        } else if (obj instanceof Long) {
            return (Long) obj;
        } else if (obj instanceof Integer) {
            return ((Integer)obj).longValue();
        } else if (obj instanceof Double) {
            final Double d = (Double)obj;
            if(Double.isInfinite(d.doubleValue())) {
                return 0L;
            }
            return d.longValue();
        } else if (obj instanceof Float) {
            final Float f = (Float)obj;
            if(Float.isInfinite(f.floatValue())) {
                return 0L;
            }
            return f.longValue();
        } else if (obj instanceof Number) {
            return ((Number)obj).longValue();
        } else if (obj instanceof String || obj instanceof ConsString) {
            return JSType.toLong(obj);
        } else if (obj instanceof Boolean) {
            return (Boolean)obj ? 1L : 0L;
        } else if (obj instanceof ScriptObject) {
            obj = JSType.toPrimitive(obj, Number.class);
            continue;
        } else if (obj == UNDEFINED) {
            return null; // null or 0L?
        }
        throw assertUnexpectedType(obj);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:JavaArgumentConverters.java

示例5: getLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public long getLong(final int index) {
    if (index >= length()) {
        return JSType.toLong(get(index));
    }
    return underlying.getLong(index);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:LengthNotWritableFilter.java

示例6: getLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public long getLong(final int index) {
    if (index >= 0 && index < maxDenseLength) {
        return underlying.getLong(index);
    }
    return JSType.toLong(sparseMap.get(indexToKey(index)));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:8,代码来源:SparseArrayData.java

示例7: indexOf

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.14 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
 *
 * @param self           self reference
 * @param searchElement  element to search for
 * @param fromIndex      start index of search
 * @return index of element, or -1 if not found
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static double indexOf(final Object self, final Object searchElement, final Object fromIndex) {
    try {
        final ScriptObject sobj = (ScriptObject)Global.toObject(self);
        final long         len  = JSType.toUint32(sobj.getLength());
        if (len == 0) {
            return -1;
        }

        final long         n = JSType.toLong(fromIndex);
        if (n >= len) {
            return -1;
        }


        for (long k = Math.max(0, n < 0 ? len - Math.abs(n) : n); k < len; k++) {
            if (sobj.has(k)) {
                if (ScriptRuntime.EQ_STRICT(sobj.get(k), searchElement)) {
                    return k;
                }
            }
        }
    } catch (final ClassCastException | NullPointerException e) {
        //fallthru
    }

    return -1;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:NativeArray.java

示例8: lastIndexOf

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.15 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
 *
 * @param self self reference
 * @param args arguments: element to search for and optional from index
 * @return index of element, or -1 if not found
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static double lastIndexOf(final Object self, final Object... args) {
    try {
        final ScriptObject sobj = (ScriptObject)Global.toObject(self);
        final long         len  = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            return -1;
        }

        final Object searchElement = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
        final long   n             = args.length > 1 ? JSType.toLong(args[1]) : len - 1;

        for (long k = n < 0 ? len - Math.abs(n) : Math.min(n, len - 1); k >= 0; k--) {
            if (sobj.has(k)) {
                if (ScriptRuntime.EQ_STRICT(sobj.get(k), searchElement)) {
                    return k;
                }
            }
        }
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }

    return -1;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:NativeArray.java

示例9: toLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
private static Long toLong(final Object obj0) {
    // TODO - Order tests for performance.
    for (Object obj = obj0; ;) {
        if (obj == null) {
            return null;
        } else if (obj instanceof Long) {
            return (Long) obj;
        } else if (obj instanceof Integer) {
            return ((Integer)obj).longValue();
        } else if (obj instanceof Double) {
            final Double d = (Double)obj;
            if(Double.isInfinite(d)) {
                return 0L;
            }
            return d.longValue();
        } else if (obj instanceof Float) {
            final Float f = (Float)obj;
            if(Float.isInfinite(f)) {
                return 0L;
            }
            return f.longValue();
        } else if (obj instanceof Number) {
            return ((Number)obj).longValue();
        } else if (isString(obj)) {
            return JSType.toLong(obj);
        } else if (obj instanceof Boolean) {
            return (Boolean)obj ? 1L : 0L;
        } else if (obj instanceof ScriptObject) {
            obj = JSType.toPrimitive(obj, Number.class);
            continue;
        } else if (obj == UNDEFINED) {
            return null; // null or 0L?
        }
        throw assertUnexpectedType(obj);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:JavaArgumentConverters.java

示例10: splice

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self self reference
 * @param args arguments
 * @return result of splice
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
    final Object obj = Global.toObject(self);

    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final Object start = args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED;
    final Object deleteCount = args.length > 1 ? args[1] : ScriptRuntime.UNDEFINED;

    Object[] items;

    if (args.length > 2) {
        items = new Object[args.length - 2];
        System.arraycopy(args, 2, items, 0, items.length);
    } else {
        items = ScriptRuntime.EMPTY_ARRAY;
    }

    final ScriptObject sobj                = (ScriptObject)obj;
    final long         len                 = JSType.toUint32(sobj.getLength());
    final long         relativeStart       = JSType.toLong(start);

    final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
    final long actualDeleteCount = Math.min(Math.max(JSType.toLong(deleteCount), 0), len - actualStart);

    NativeArray returnValue;

    if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
        try {
            returnValue =  new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));

            // Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
            int k = (int) actualStart;
            for (int i = 0; i < items.length; i++, k++) {
                sobj.defineOwnProperty(k, items[i]);
            }
        } catch (final UnsupportedOperationException uoe) {
            returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
        }
    } else {
        returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
    }

    return returnValue;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:55,代码来源:NativeArray.java

示例11: toLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@SuppressWarnings("unused")
private static long toLong(final JSObject obj) {
    return JSType.toLong(toNumber(obj));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:JSObjectLinker.java

示例12: getLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public long getLong(final int index) {
    return JSType.toLong(array[index]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:ObjectArrayData.java

示例13: splice

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.12 Array.prototype.splice ( start, deleteCount [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self self reference
 * @param args arguments
 * @return result of splice
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object splice(final Object self, final Object... args) {
    final Object obj = Global.toObject(self);

    if (!(obj instanceof ScriptObject)) {
        return ScriptRuntime.UNDEFINED;
    }

    final ScriptObject sobj          = (ScriptObject)obj;
    final long         len           = JSType.toUint32(sobj.getLength());
    final long         relativeStart = JSType.toLong(args.length > 0 ? args[0] : ScriptRuntime.UNDEFINED);

    final long actualStart = relativeStart < 0 ? Math.max(len + relativeStart, 0) : Math.min(relativeStart, len);
    final long actualDeleteCount;
    Object[] items = ScriptRuntime.EMPTY_ARRAY;

    if (args.length == 0) {
        actualDeleteCount = 0;
    } else if (args.length == 1) {
        actualDeleteCount = len - actualStart;
    } else {
        actualDeleteCount = Math.min(Math.max(JSType.toLong(args[1]), 0), len - actualStart);
        if (args.length > 2) {
            items = new Object[args.length - 2];
            System.arraycopy(args, 2, items, 0, items.length);
        }
    }

    NativeArray returnValue;

    if (actualStart <= Integer.MAX_VALUE && actualDeleteCount <= Integer.MAX_VALUE && bulkable(sobj)) {
        try {
            returnValue = new NativeArray(sobj.getArray().fastSplice((int)actualStart, (int)actualDeleteCount, items.length));

            // Since this is a dense bulkable array we can use faster defineOwnProperty to copy new elements
            int k = (int) actualStart;
            for (int i = 0; i < items.length; i++, k++) {
                sobj.defineOwnProperty(k, items[i]);
            }
        } catch (final UnsupportedOperationException uoe) {
            returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
        }
    } else {
        returnValue = slowSplice(sobj, actualStart, actualDeleteCount, items, len);
    }

    return returnValue;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:56,代码来源:NativeArray.java

示例14: getLong

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Fetch long value of node
 *
 * @return long value of node
 */
public long getLong() {
    return JSType.toLong(value);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:LiteralNode.java


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