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


Java JSType.toUint32方法代码示例

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


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

示例1: push

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
 *
 * @param self self reference
 * @param arg argument to push
 * @return array after pushes
 */
@SpecializedFunction
public static double push(final Object self, final Object arg) {
    try {
        final ScriptObject sobj = (ScriptObject)self;
        final ArrayData arrayData = sobj.getArray();
        final long length = arrayData.length();
        if (bulkable(sobj) && length < JSType.MAX_UINT) {
            sobj.setArray(arrayData.push(true, arg));
            return length + 1;
        }

        long len = JSType.toUint32(sobj.getLength());
        sobj.set(len++, arg, CALLSITE_STRICT);
        sobj.set("length", len, CALLSITE_STRICT);
        return len;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:NativeArray.java

示例2: split

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.5.4.14 String.prototype.split (separator, limit)
 *
 * @param self      self reference
 * @param separator separator for split
 * @param limit     limit for splits
 * @return array object in which splits have been placed
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static ScriptObject split(final Object self, final Object separator, final Object limit) {
    final String str = checkObjectToString(self);
    final long lim = limit == UNDEFINED ? JSType.MAX_UINT : JSType.toUint32(limit);

    if (separator == UNDEFINED) {
        return lim == 0 ? new NativeArray() : new NativeArray(new Object[]{str});
    }

    if (separator instanceof NativeRegExp) {
        return ((NativeRegExp) separator).split(str, lim);
    }

    // when separator is a string, it is treated as a literal search string to be used for splitting.
    return splitString(str, JSType.toString(separator), lim);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:NativeString.java

示例3: lengthToInt

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
private static int lengthToInt(final Object len) {
    final long ln = JSType.toUint32(len);
    // NOTE: ECMASCript 5.1 section 15.3.4.3 says length should be treated as Uint32, but we wouldn't be able to
    // allocate a Java array of more than MAX_VALUE elements anyway, so at this point we have to throw an error.
    // People applying a function to more than 2^31 arguments will unfortunately be out of luck.
    if (ln > Integer.MAX_VALUE) {
        throw rangeError("range.error.inappropriate.array.length", JSType.toString(len));
    }
    return (int)ln;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:NativeFunction.java

示例4: length

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Length getter
 * @param self self reference
 * @return length property value
 */
@Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static Object length(final Object self) {
    if (self instanceof ScriptObject) {
        return JSType.toUint32(((ScriptObject)self).getArray().length());
    }

    return 0;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:NativeRegExpExecResult.java

示例5: getLength

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@Override
public Object getLength() {
    final long length = JSType.toUint32(getArray().length());
    if (length < Integer.MAX_VALUE) {
        return (int)length;
    }
    return length;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:9,代码来源:NativeArray.java

示例6: length

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * Length getter
 * @param self self reference
 * @return the length of the object
 */
@Getter(attributes = Attribute.NOT_ENUMERABLE | Attribute.NOT_CONFIGURABLE)
public static Object length(final Object self) {
    if (isArray(self)) {
        return JSType.toUint32(((ScriptObject) self).getArray().length());
    }

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

示例7: 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

示例8: reverse

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.8 Array.prototype.reverse ()
 *
 * @param self self reference
 * @return reversed array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object reverse(final Object self) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;
        final long         len    = JSType.toUint32(sobj.getLength());
        final long         middle = len / 2;

        for (long lower = 0; lower != middle; lower++) {
            final long    upper       = len - lower - 1;
            final Object  lowerValue  = sobj.get(lower);
            final Object  upperValue  = sobj.get(upper);
            final boolean lowerExists = sobj.has(lower);
            final boolean upperExists = sobj.has(upper);

            if (lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            } else if (!lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.delete(upper, true);
            } else if (lowerExists && !upperExists) {
                sobj.delete(lower, true);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            }
        }
        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:NativeArray.java

示例9: 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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:42,代码来源:NativeArray.java

示例10: sort

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.11 Array.prototype.sort ( comparefn )
 *
 * @param self       self reference
 * @param comparefn  element comparison function
 * @return sorted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static ScriptObject sort(final Object self, final Object comparefn) {
    try {
        final ScriptObject sobj    = (ScriptObject) self;
        final long         len     = JSType.toUint32(sobj.getLength());
        ArrayData          array   = sobj.getArray();

        if (len > 1) {
            // Get only non-missing elements. Missing elements go at the end
            // of the sorted array. So, just don't copy these to sort input.
            final ArrayList<Object> src = new ArrayList<>();

            for (final Iterator<Long> iter = array.indexIterator(); iter.hasNext(); ) {
                final long index = iter.next();
                if (index >= len) {
                    break;
                }
                src.add(array.getObject((int)index));
            }

            final Object[] sorted = sort(src.toArray(), comparefn);

            for (int i = 0; i < sorted.length; i++) {
                array = array.set(i, sorted[i], true);
            }

            // delete missing elements - which are at the end of sorted array
            if (sorted.length != len) {
                array = array.delete(sorted.length, len - 1);
            }

            sobj.setArray(array);
        }

        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:47,代码来源:NativeArray.java

示例11: 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

示例12: 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

示例13: shift

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

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

示例14: ReverseJSObjectIterator

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
ReverseJSObjectIterator(final JSObject obj, final boolean includeUndefined) {
    super(obj, includeUndefined);
    this.index = JSType.toUint32(obj.hasMember("length")? obj.getMember("length") : 0) - 1;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:ReverseJSObjectIterator.java

示例15: ScriptObjectIterator

import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
ScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) {
    super(includeUndefined);
    this.obj    = obj;
    this.length = JSType.toUint32(obj.getLength());
    this.index  = 0;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:ScriptObjectIterator.java


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