Java Code Examples for jdk.nashorn.internal.objects.annotations.Function

The following examples show how to use jdk.nashorn.internal.objects.annotations.Function. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.5.4.8 String.prototype.lastIndexOf (searchString, position)
 * @param self   self reference
 * @param search string to search for
 * @param pos    position to start search
 * @return last position of match or -1
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static int lastIndexOf(final Object self, final Object search, final Object pos) {

    final String str       = checkObjectToString(self);
    final String searchStr = JSType.toString(search);
    final int length       = str.length();

    int end;

    if (pos == UNDEFINED) {
        end = length;
    } else {
        final double numPos = JSType.toNumber(pos);
        end = Double.isNaN(numPos) ? length : (int)numPos;
        if (end < 0) {
            end = 0;
        } else if (end > length) {
            end = length;
        }
    }


    return str.lastIndexOf(searchStr, end);
}
 
Example 2
Source Project: TencentKona-8   Source File: NativeArray.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.4.4.20 Array.prototype.filter ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return filtered array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray filter(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) {
        private long to = 0;
        private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) {
                result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val);
            }
            return true;
        }
    }.apply();
}
 
Example 3
Source Project: TencentKona-8   Source File: NativeFunction.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.3.4.4 Function.prototype.call (thisArg [ , arg1 [ , arg2, ... ] ] )
 *
 * @param self self reference
 * @param args arguments for call
 * @return result of call
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object call(final Object self, final Object... args) {
    checkCallable(self);

    final Object thiz = (args.length == 0) ? UNDEFINED : args[0];
    Object[] arguments;

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

    if (self instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)self, thiz, arguments);
    } else if (self instanceof JSObject) {
        return ((JSObject)self).call(thiz, arguments);
    }

    throw new AssertionError("should not reach here");
}
 
Example 4
Source Project: TencentKona-8   Source File: NativeMath.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.8.2.11 max(x)
 *
 * @param self  self reference
 * @param args  arguments
 *
 * @return the largest of the arguments, {@link Double#NEGATIVE_INFINITY} if no args given, or identity if one arg is given
 */
@Function(arity = 2, attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double max(final Object self, final Object... args) {
    switch (args.length) {
    case 0:
        return Double.NEGATIVE_INFINITY;
    case 1:
        return JSType.toNumber(args[0]);
    default:
        double res = JSType.toNumber(args[0]);
        for (int i = 1; i < args.length; i++) {
            res = Math.max(res, JSType.toNumber(args[i]));
        }
        return res;
    }
}
 
Example 5
Source Project: TencentKona-8   Source File: NativeObject.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * ECMA 15.2.4.3 Object.prototype.toLocaleString ( )
 *
 * @param self self reference
 * @return localized ToString
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toLocaleString(final Object self) {
    final Object obj = JSType.toScriptObject(self);
    if (obj instanceof ScriptObject) {
        final InvokeByName toStringInvoker = getTO_STRING();
        final ScriptObject sobj = (ScriptObject)obj;
        try {
            final Object toString = toStringInvoker.getGetter().invokeExact(sobj);

            if (Bootstrap.isCallable(toString)) {
                return toStringInvoker.getInvoker().invokeExact(toString, sobj);
            }
        } catch (final RuntimeException | Error e) {
            throw e;
        } catch (final Throwable t) {
            throw new RuntimeException(t);
        }

        throw typeError("not.a.function", "toString");
    }

    return ScriptRuntime.builtinObjectToString(self);
}
 
Example 6
Source Project: TencentKona-8   Source File: NativeArray.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 7
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.9 String.prototype.localeCompare (that)
 * @param self self reference
 * @param that comparison object
 * @return result of locale sensitive comparison operation between {@code self} and {@code that}
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {

    final String   str      = checkObjectToString(self);
    final Collator collator = Collator.getInstance(Global.getEnv()._locale);

    collator.setStrength(Collator.IDENTICAL);
    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);

    return collator.compare(str, JSType.toString(that));
}
 
Example 8
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.10 String.prototype.match (regexp)
 * @param self   self reference
 * @param regexp regexp expression
 * @return array of regexp matches
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static ScriptObject match(final Object self, final Object regexp) {

    final String str = checkObjectToString(self);

    NativeRegExp nativeRegExp;
    if (regexp == UNDEFINED) {
        nativeRegExp = new NativeRegExp("");
    } else {
        nativeRegExp = Global.toRegExp(regexp);
    }

    if (!nativeRegExp.getGlobal()) {
        return nativeRegExp.exec(str);
    }

    nativeRegExp.setLastIndex(0);

    int previousLastIndex = 0;
    final List<Object> matches = new ArrayList<>();

    Object result;
    while ((result = nativeRegExp.exec(str)) != null) {
        final int thisIndex = nativeRegExp.getLastIndex();
        if (thisIndex == previousLastIndex) {
            nativeRegExp.setLastIndex(thisIndex + 1);
            previousLastIndex = thisIndex + 1;
        } else {
            previousLastIndex = thisIndex;
        }
        matches.add(((ScriptObject)result).get(0));
    }

    if (matches.isEmpty()) {
        return null;
    }

    return new NativeArray(matches.toArray());
}
 
Example 9
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.12 String.prototype.search (regexp)
 *
 * @param self    self reference
 * @param string  string to search for
 * @return offset where match occurred
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static int search(final Object self, final Object string) {

    final String       str          = checkObjectToString(self);
    final NativeRegExp nativeRegExp = Global.toRegExp(string == UNDEFINED ? "" : string);

    return nativeRegExp.search(str);
}
 
Example 10
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.13 String.prototype.slice (start, end)
 *
 * @param self  self reference
 * @param start start position for slice
 * @param end   end position for slice
 * @return sliced out substring
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String slice(final Object self, final Object start, final Object end) {

    final String str      = checkObjectToString(self);
    if (end == UNDEFINED) {
        return slice(str, JSType.toInteger(start));
    }
    return slice(str, JSType.toInteger(start), JSType.toInteger(end));
}
 
Example 11
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.15 String.prototype.substring (start, end)
 *
 * @param self  self reference
 * @param start start position of substring
 * @param end   end position of substring
 * @return substring given start and end indexes
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String substring(final Object self, final Object start, final Object end) {

    final String str = checkObjectToString(self);
    if (end == UNDEFINED) {
        return substring(str, JSType.toInteger(start));
    }
    return substring(str, JSType.toInteger(start), JSType.toInteger(end));
}
 
Example 12
Source Project: TencentKona-8   Source File: NativeObject.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.4.5 Object.prototype.hasOwnProperty (V)
 *
 * @param self self reference
 * @param v property to check for
 * @return true if property exists in object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static boolean hasOwnProperty(final Object self, final Object v) {
    // Convert ScriptObjects to primitive with String.class hint
    // but no need to convert other primitives to string.
    final Object key = JSType.toPrimitive(v, String.class);
    final Object obj = Global.toObject(self);

    return obj instanceof ScriptObject && ((ScriptObject)obj).hasOwnProperty(key);
}
 
Example 13
Source Project: TencentKona-8   Source File: NativeMath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.8.2.15 round(x)
 *
 * @param self  self reference
 * @param x     argument
 *
 * @return x rounded
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static double round(final Object self, final Object x) {
    final double d = JSType.toNumber(x);
    if (Math.getExponent(d) >= 52) {
        return d;
    }
    return Math.copySign(Math.floor(d + 0.5), d);
}
 
Example 14
Source Project: TencentKona-8   Source File: NativeDataView.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 32-bit signed int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @param littleEndian (optional) flag indicating whether to read in little endian order
 * @return 32-bit signed int value at the byteOffset
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static int getInt32(final Object self, final Object byteOffset, final Object littleEndian) {
    try {
        return getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset));
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 15
Source Project: TencentKona-8   Source File: NativeDataView.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 32-bit unsigned int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @param littleEndian (optional) flag indicating whether to read in little endian order
 * @return 32-bit unsigned int value at the byteOffset
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static double getUint32(final Object self, final Object byteOffset, final Object littleEndian) {
    try {
        return 0xFFFFFFFFL & getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset));
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 16
Source Project: TencentKona-8   Source File: NativeArray.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.17 Array.prototype.some ( callbackfn [ , thisArg ] )
 *
 * @param self        self reference
 * @param callbackfn  callback function per element
 * @param thisArg     this argument
 * @return true if callback function returned true for any element in the array, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static boolean some(final Object self, final Object callbackfn, final Object thisArg) {
    return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) {
        private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER();

        @Override
        protected boolean forEach(final Object val, final double i) throws Throwable {
            return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self));
        }
    }.apply();
}
 
Example 17
Source Project: TencentKona-8   Source File: NativeString.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: String.prototype.trimRight ( )
 * @param self self reference
 * @return string trimmed right from whitespace
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static String trimRight(final Object self) {

    final String str = checkObjectToString(self);
    final int start = 0;
    int end   = str.length() - 1;

    while (end >= start && ScriptRuntime.isJSWhitespace(str.charAt(end))) {
        end--;
    }

    return str.substring(start, end + 1);
}
 
Example 18
Source Project: TencentKona-8   Source File: NativeDebug.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the ArrayData class for this ScriptObject
 * @param self self
 * @param obj script object to check
 * @return ArrayData class, or undefined if no ArrayData is present
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getArrayDataClass(final Object self, final Object obj) {
    try {
        return ((ScriptObject)obj).getArray().getClass();
    } catch (final ClassCastException e) {
        return ScriptRuntime.UNDEFINED;
    }
}
 
Example 19
Source Project: TencentKona-8   Source File: NativeDebug.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: get context, context utility
 *
 * @param self self reference
 * @return context
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getContext(final Object self) {
    final SecurityManager sm = System.getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new RuntimePermission(Context.NASHORN_GET_CONTEXT));
    }
    return Global.getThisContext();
}
 
Example 20
Source Project: TencentKona-8   Source File: NativeDebug.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the capacity of the event queue
 * @param self self reference
 * @return capacity of event queue as an integer
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object getEventQueueCapacity(final Object self) {
    final ScriptObject sobj = (ScriptObject)self;
    Integer cap;
    if (sobj.has(EVENT_QUEUE_CAPACITY)) {
        cap = JSType.toInt32(sobj.get(EVENT_QUEUE_CAPACITY));
    } else {
        setEventQueueCapacity(self, cap = RuntimeEvent.RUNTIME_EVENT_QUEUE_SIZE);
    }
    return cap;
}
 
Example 21
Source Project: TencentKona-8   Source File: NativeDebug.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a runtime event to the runtime event queue. The queue has a fixed
 * size {@link RuntimeEvent#RUNTIME_EVENT_QUEUE_SIZE} and the oldest
 * entry will be thrown out of the queue is about to overflow
 * @param self self reference
 * @param event event to add
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static void addRuntimeEvent(final Object self, final Object event) {
    final LinkedList<RuntimeEvent<?>> q = getEventQueue(self);
    final int cap = (Integer)getEventQueueCapacity(self);
    while (q.size() >= cap) {
        q.removeFirst();
    }
    q.addLast(getEvent(event));
}
 
Example 22
Source Project: TencentKona-8   Source File: NativeObject.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.3.10 Object.preventExtensions ( O )
 *
 * @param self self reference
 * @param obj  object, for which to set the internal extensible property to false
 * @return object
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object preventExtensions(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).preventExtensions();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).preventExtensions();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 23
Source Project: TencentKona-8   Source File: NativeObject.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.2.3.11 Object.isSealed ( O )
 *
 * @param self self reference
 * @param obj check whether an object is sealed
 * @return true if sealed, false otherwise
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static boolean isSealed(final Object self, final Object obj) {
    if (obj instanceof ScriptObject) {
        return ((ScriptObject)obj).isSealed();
    } else if (obj instanceof ScriptObjectMirror) {
        return ((ScriptObjectMirror)obj).isSealed();
    } else {
        throw notAnObject(obj);
    }
}
 
Example 24
Source Project: TencentKona-8   Source File: NativeDataView.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 32-bit float at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value float value to set
 * @param littleEndian (optional) flag indicating whether to write in little endian order
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 2)
public static Object setFloat32(final Object self, final Object byteOffset, final Object value, final Object littleEndian) {
    try {
        getBuffer(self, littleEndian).putFloat((int)JSType.toUint32(byteOffset), (float)JSType.toNumber(value));
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 25
Source Project: TencentKona-8   Source File: NativeFunction.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.3.4.3 Function.prototype.apply (thisArg, argArray)
 *
 * @param self   self reference
 * @param thiz   {@code this} arg for apply
 * @param array  array of argument for apply
 * @return result of apply
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object apply(final Object self, final Object thiz, final Object array) {
    checkCallable(self);

    final Object[] args = toApplyArgs(array);

    if (self instanceof ScriptFunction) {
        return ScriptRuntime.apply((ScriptFunction)self, thiz, args);
    } else if (self instanceof JSObject) {
        return ((JSObject)self).call(thiz, args);
    }
    throw new AssertionError("Should not reach here");
}
 
Example 26
Source Project: TencentKona-8   Source File: NativeDate.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.9.4.3 Date.UTC (year, month [, date [, hours [, minutes [, seconds [, ms ] ] ] ] ] )
 *
 * @param self self reference
 * @param args mandatory args are year, month. Optional are date, hours, minutes, seconds and milliseconds
 * @return a time clip according to the ECMA specification
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 7, where = Where.CONSTRUCTOR)
public static double UTC(final Object self, final Object... args) {
    final NativeDate nd = new NativeDate(0);
    final double[] d = convertCtorArgs(args);
    final double time = d == null ? Double.NaN : timeClip(makeDate(d));
    nd.setTime(time);
    return time;
}
 
Example 27
Source Project: TencentKona-8   Source File: NativeArray.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example 28
Source Project: TencentKona-8   Source File: NativeArray.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self self reference
 * @param args arguments
 * @return resulting NativeArray
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static NativeArray concat(final Object self, final Object... args) {
    final ArrayList<Object> list = new ArrayList<>();

    concatToList(list, Global.toObject(self));

    for (final Object obj : args) {
        concatToList(list, obj);
    }

    return new NativeArray(list.toArray());
}
 
Example 29
Source Project: TencentKona-8   Source File: NativeDataView.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 16-bit signed int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @param littleEndian (optional) flag indicating whether to read in little endian order
 * @return 16-bit signed int value at the byteOffset
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static int getInt16(final Object self, final Object byteOffset, final Object littleEndian) {
    try {
        return getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset));
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example 30
Source Project: TencentKona-8   Source File: NativeDataView.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 16-bit unsigned int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @param littleEndian (optional) flag indicating whether to read in little endian order
 * @return 16-bit unsigned int value at the byteOffset
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static int getUint16(final Object self, final Object byteOffset, final Object littleEndian) {
    try {
        return 0xFFFF & getBuffer(self, littleEndian).getShort(JSType.toInt32(byteOffset));
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}