jdk.nashorn.internal.objects.annotations.SpecializedFunction Java Examples

The following examples show how to use jdk.nashorn.internal.objects.annotations.SpecializedFunction. 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 check out the related API usage on the sidebar.
Example #1
Source File: NativeDataView.java    From jdk8u_nashorn with 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
 */
@SpecializedFunction
public static double getUint32(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return JSType.toUint32(getBuffer(self, littleEndian).getInt(JSType.toInt32(byteOffset)));
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #2
Source File: NativeString.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.13 String.prototype.slice (start, end) specialized for two int parameters
 *
 * @param self  self reference
 * @param start start position for slice
 * @param end   end position for slice
 * @return sliced out substring
 */
@SpecializedFunction
public static Object slice(final Object self, final int start, final int end) {

    final String str = checkObjectToString(self);
    final int len    = str.length();

    final int from = (start < 0) ? Math.max(len + start, 0) : Math.min(start, len);
    final int to   = (end < 0)   ? Math.max(len + end, 0)   : Math.min(end, len);

    return str.substring(Math.min(from, to), to);
}
 
Example #3
Source File: NativeDataView.java    From openjdk-jdk8u with 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
 */
@SpecializedFunction
public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return 0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #4
Source File: NativeString.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.13 String.prototype.slice (start, end) specialized for two int parameters
 *
 * @param self  self reference
 * @param start start position for slice
 * @param end   end position for slice
 * @return sliced out substring
 */
@SpecializedFunction
public static String slice(final Object self, final int start, final int end) {

    final String str = checkObjectToString(self);
    final int len    = str.length();

    final int from = start < 0 ? Math.max(len + start, 0) : Math.min(start, len);
    final int to   = end < 0   ? Math.max(len + end, 0)   : Math.min(end, len);

    return str.substring(Math.min(from, to), to);
}
 
Example #5
Source File: NativeArray.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.2.2 new Array (len)
 *
 * Specialized constructor for one double argument (length)
 *
 * @param newObj was the new operator used to instantiate this array
 * @param self   self reference
 * @param length array length
 * @return the new NativeArray
 */
@SpecializedFunction(isConstructor=true)
public static NativeArray construct(final boolean newObj, final Object self, final double length) {
    final long uint32length = JSType.toUint32(length);

    if (uint32length == length) {
        return new NativeArray(uint32length);
    }

    return construct(newObj, self, new Object[]{length});
}
 
Example #6
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.2.2 new Array (len)
 *
 * Specialized constructor for one double argument (length)
 *
 * @param newObj was the new operator used to instantiate this array
 * @param self   self reference
 * @param length array length
 * @return the new NativeArray
 */
@SpecializedFunction(isConstructor=true)
public static NativeArray construct(final boolean newObj, final Object self, final double length) {
    final long uint32length = JSType.toUint32(length);

    if (uint32length == length) {
        return new NativeArray(uint32length);
    }

    return construct(newObj, self, new Object[]{length});
}
 
Example #7
Source File: NativeDataView.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 8-bit unsigned int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value byte value to set
 * @return undefined
 */
@SpecializedFunction
public static Object setUint8(final Object self, final int byteOffset, final int value) {
    try {
        getBuffer(self).put(byteOffset, (byte)value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #8
Source File: NativeDataView.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 32-bit signed int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value int value to set
 * @param littleEndian (optional) flag indicating whether to write in little endian order
 * @return undefined
 */
@SpecializedFunction
public static Object setInt32(final Object self, final int byteOffset, final int value, final boolean littleEndian) {
    try {
        getBuffer(self, littleEndian).putInt(byteOffset, value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #9
Source File: NativeString.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.15 String.prototype.substring (start, end) specialized for int start and end parameters
 *
 * @param self  self reference
 * @param start start position of substring
 * @param end   end position of substring
 * @return substring given start and end indexes
 */
@SpecializedFunction
public static String substring(final Object self, final int start, final int end) {
    final String str = checkObjectToString(self);
    final int len = str.length();
    final int validStart = start < 0 ? 0 : start > len ? len : start;
    final int validEnd   = end < 0 ? 0 : end > len ? len : end;

    if (validStart < validEnd) {
        return str.substring(validStart, validEnd);
    }
    return str.substring(validEnd, validStart);
}
 
Example #10
Source File: NativeDataView.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 16-bit signed int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value short value to set
 * @return undefined
 */
@SpecializedFunction
public static Object setInt16(final Object self, final int byteOffset, final int value) {
    try {
        getBuffer(self, false).putShort(byteOffset, (short)value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #11
Source File: NativeDataView.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 32-bit signed int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value int value to set
 * @return undefined
 */
@SpecializedFunction
public static Object setInt32(final Object self, final int byteOffset, final int value) {
    try {
        getBuffer(self, false).putInt(byteOffset, value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #12
Source File: NativeDataView.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 32-bit unsigned int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value int value to set
 * @param littleEndian (optional) flag indicating whether to write in little endian order
 * @return undefined
 */
@SpecializedFunction
public static Object setUint32(final Object self, final int byteOffset, final long value, final boolean littleEndian) {
    try {
        getBuffer(self, littleEndian).putInt(byteOffset, (int)value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #13
Source File: NativeDataView.java    From openjdk-jdk8u with 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
 */
@SpecializedFunction
public static Object setFloat32(final Object self, final int byteOffset, final double value, final boolean littleEndian) {
    try {
        getBuffer(self, littleEndian).putFloat(byteOffset, (float)value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #14
Source File: NativeDataView.java    From jdk8u_nashorn with 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
 */
@SpecializedFunction
public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return 0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #15
Source File: NativeDataView.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 64-bit float at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value double value to set
 * @param littleEndian (optional) flag indicating whether to write in little endian order
 * @return undefined
 */
@SpecializedFunction
public static Object setFloat64(final Object self, final int byteOffset, final double value, final boolean littleEndian) {
    try {
        getBuffer(self, littleEndian).putDouble(byteOffset, value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #16
Source File: NativeString.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.5.4.15 String.prototype.substring (start, end) specialized for int start and end parameters
 *
 * @param self  self reference
 * @param start start position of substring
 * @param end   end position of substring
 * @return substring given start and end indexes
 */
@SpecializedFunction
public static String substring(final Object self, final int start, final int end) {
    final String str = checkObjectToString(self);
    final int len = str.length();
    final int validStart = start < 0 ? 0 : start > len ? len : start;
    final int validEnd   = end < 0 ? 0 : end > len ? len : end;

    if (validStart < validEnd) {
        return str.substring(validStart, validEnd);
    }
    return str.substring(validEnd, validStart);
}
 
Example #17
Source File: NativeDataView.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 32-bit float value 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 float value at the byteOffset
 */
@SpecializedFunction
public static double getFloat32(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return getBuffer(self, littleEndian).getFloat(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #18
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SpecializedFunction.LinkLogic getLinkLogic(final Class<? extends LinkLogic> clazz) {
    if (clazz == PushLinkLogic.class) {
        return PushLinkLogic.INSTANCE;
    } else if (clazz == PopLinkLogic.class) {
        return PopLinkLogic.INSTANCE;
    } else if (clazz == ConcatLinkLogic.class) {
        return ConcatLinkLogic.INSTANCE;
    }
    return null;
}
 
Example #19
Source File: NativeDataView.java    From openjdk-jdk8u-backup with 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
 */
@SpecializedFunction
public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return 0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #20
Source File: NativeDataView.java    From TencentKona-8 with 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
 * @return 32-bit signed int value at the byteOffset
 */
@SpecializedFunction
public static int getInt32(final Object self, final int byteOffset) {
    try {
        return getBuffer(self, false).getInt(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #21
Source File: NativeDataView.java    From TencentKona-8 with 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
 */
@SpecializedFunction
public static int getUint16(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return 0xFFFF & getBuffer(self, littleEndian).getShort(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #22
Source File: NativeDataView.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 8-bit unsigned int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @return 8-bit unsigned int value at the byteOffset
 */
@SpecializedFunction
public static int getUint8(final Object self, final int byteOffset) {
    try {
        return 0xFF & getBuffer(self).get(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #23
Source File: NativeDataView.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Set 32-bit signed int at the given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to write at
 * @param value int value to set
 * @return undefined
 */
@SpecializedFunction
public static Object setInt32(final Object self, final int byteOffset, final int value) {
    try {
        getBuffer(self, false).putInt(byteOffset, value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #24
Source File: NativeDataView.java    From jdk8u60 with 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
 */
@SpecializedFunction
public static int getInt16(final Object self, final int byteOffset, final boolean littleEndian) {
    try {
        return getBuffer(self, littleEndian).getShort(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #25
Source File: NativeDataView.java    From openjdk-jdk8u with 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
 * @return undefined
 */
@SpecializedFunction
public static Object setFloat32(final Object self, final int byteOffset, final double value) {
    try {
        getBuffer(self, false).putFloat(byteOffset, (float)value);
        return UNDEFINED;
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #26
Source File: NativeDataView.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get 8-bit unsigned int from given byteOffset
 *
 * @param self DataView object
 * @param byteOffset byte offset to read from
 * @return 8-bit unsigned int value at the byteOffset
 */
@SpecializedFunction
public static int getUint8(final Object self, final int byteOffset) {
    try {
        return 0xFF & getBuffer(self).get(byteOffset);
    } catch (final IllegalArgumentException iae) {
        throw rangeError(iae, "dataview.offset");
    }
}
 
Example #27
Source File: NativeDataView.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Specialized version of DataView constructor
 *
 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param arrBuf underlying ArrayBuffer storage object
 * @param offset in bytes from the start of the ArrayBuffer
 * @param length is the number of bytes from the offset that this DataView will reference
 * @return newly constructed DataView object
 */
@SpecializedFunction(isConstructor=true)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) {
    if (!(arrBuf instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }
    return new NativeDataView((NativeArrayBuffer) arrBuf, offset, length);
}
 
Example #28
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 3 votes vote down vote up
/**
 * ECMA 15.4.2.2 new Array (len)
 *
 * Specialized constructor for one integer argument (length)
 *
 * @param newObj was the new operator used to instantiate this array
 * @param self   self reference
 * @param length array length
 * @return the new NativeArray
 */
@SpecializedFunction(isConstructor=true)
public static NativeArray construct(final boolean newObj, final Object self, final int length) {
    if (length >= 0) {
        return new NativeArray(length);
    }

    return construct(newObj, self, new Object[]{length});
}
 
Example #29
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * ECMA 15.4.4.4 Array.prototype.concat ( [ item1 [ , item2 [ , ... ] ] ] )
 *
 * @param self self reference
 * @param arg argument
 * @return resulting NativeArray
 */
@SpecializedFunction(linkLogic=ConcatLinkLogic.class)
public static NativeArray concat(final Object self, final long arg) {
    final ContinuousArrayData newData = getContinuousArrayDataCCE(self, Long.class).copy(); //get at least a long array data copy of this data
    newData.fastPush(arg); //add a long at the end
    return new NativeArray(newData);
}
 
Example #30
Source File: NativeDataView.java    From jdk8u_nashorn with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Specialized version of DataView constructor
 *
 * @param newObj if this constructor was invoked with 'new' or not
 * @param self   constructor function object
 * @param arrBuf underlying ArrayBuffer storage object
 * @param offset in bytes from the start of the ArrayBuffer
 * @param length is the number of bytes from the offset that this DataView will reference
 * @return newly constructed DataView object
 */
@SpecializedFunction(isConstructor=true)
public static NativeDataView constructor(final boolean newObj, final Object self, final Object arrBuf, final int offset, final int length) {
    if (!(arrBuf instanceof NativeArrayBuffer)) {
        throw typeError("not.an.arraybuffer.in.dataview");
    }
    return new NativeDataView((NativeArrayBuffer) arrBuf, offset, length);
}