Java Code Examples for jdk.nashorn.internal.runtime.JSType#MAX_UINT
The following examples show how to use
jdk.nashorn.internal.runtime.JSType#MAX_UINT .
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: NativeArray.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
/** * ECMA 15.4.4.7 Array.prototype.push (args...) * * @param self self reference * @param args arguments to push * @return array length after pushes */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object push(final Object self, final Object... args) { try { final ScriptObject sobj = (ScriptObject)self; if (bulkable(sobj) && sobj.getArray().length() + args.length <= JSType.MAX_UINT) { final ArrayData newData = sobj.getArray().push(true, args); sobj.setArray(newData); return JSType.toNarrowestNumber(newData.length()); } long len = JSType.toUint32(sobj.getLength()); for (final Object element : args) { sobj.set(len++, element, CALLSITE_STRICT); } sobj.set("length", len, CALLSITE_STRICT); return JSType.toNarrowestNumber(len); } catch (final ClassCastException | NullPointerException e) { throw typeError(Context.getGlobal(), e, "not.an.object", ScriptRuntime.safeToString(self)); } }
Example 2
Source File: NativeArray.java From nashorn with GNU General Public License v2.0 | 6 votes |
/** * ECMA 15.4.4.7 Array.prototype.push (args...) * * @param self self reference * @param args arguments to push * @return array after pushes */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object push(final Object self, final Object... args) { try { final ScriptObject sobj = (ScriptObject)self; if (bulkable(sobj)) { if (sobj.getArray().length() + args.length <= JSType.MAX_UINT) { final ArrayData newData = sobj.getArray().push(true, args); sobj.setArray(newData); return newData.length(); } //fallthru } long len = JSType.toUint32(sobj.getLength()); for (final Object element : args) { sobj.set(len++, element, true); } sobj.set("length", len, true); return len; } catch (final ClassCastException | NullPointerException e) { throw typeError("not.an.object", ScriptRuntime.safeToString(self)); } }
Example 3
Source File: NativeString.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 4
Source File: NativeString.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 5
Source File: NativeString.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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 Object 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); }
Example 6
Source File: NativeArray.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * ECMA 15.4.4.7 Array.prototype.push (args...) * * @param self self reference * @param args arguments to push * @return array after pushes */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object push(final Object self, final Object... args) { try { final ScriptObject sobj = (ScriptObject)self; if (bulkable(sobj)) { if (sobj.getArray().length() + args.length <= JSType.MAX_UINT) { final ArrayData newData = sobj.getArray().push(true, args); sobj.setArray(newData); return newData.length(); } //fallthru } long len = JSType.toUint32(sobj.getLength()); for (final Object element : args) { sobj.set(len++, element, true); } sobj.set("length", len, true); return len; } catch (final ClassCastException | NullPointerException e) { throw typeError("not.an.object", ScriptRuntime.safeToString(self)); } }
Example 7
Source File: NativeString.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 8
Source File: NativeArray.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
/** * 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)); } }
Example 9
Source File: NativeArray.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * 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)); } }
Example 10
Source File: NativeArray.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 ((ScriptObject) self).getArray().length() & JSType.MAX_UINT; } return 0; }
Example 11
Source File: NativeUint32Array.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override protected double getDoubleImpl(final int key) { return getIntImpl(key) & JSType.MAX_UINT; }
Example 12
Source File: NativeUint32Array.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override protected double getDoubleImpl(final int key) { return getIntImpl(key) & JSType.MAX_UINT; }
Example 13
Source File: NativeArray.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public Object getLength() { return getArray().length() & JSType.MAX_UINT; }
Example 14
Source File: NativeArray.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public Object getLength() { return getArray().length() & JSType.MAX_UINT; }
Example 15
Source File: NativeArray.java From openjdk-8 with GNU General Public License v2.0 | 3 votes |
/** * ECMA 15.4.2.2 new Array (len) * * Specialized constructor for one long 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 */ @SpecializedConstructor public static Object construct(final boolean newObj, final Object self, final long length) { if (length >= 0L && length <= JSType.MAX_UINT) { return new NativeArray(length); } return construct(newObj, self, new Object[]{length}); }
Example 16
Source File: NativeArray.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * ECMA 15.4.2.2 new Array (len) * * Specialized constructor for one long 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 long length) { if (length >= 0L && length <= JSType.MAX_UINT) { return new NativeArray(length); } return construct(newObj, self, new Object[]{length}); }
Example 17
Source File: NativeArray.java From hottub with GNU General Public License v2.0 | 3 votes |
/** * ECMA 15.4.2.2 new Array (len) * * Specialized constructor for one long 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 long length) { if (length >= 0L && length <= JSType.MAX_UINT) { return new NativeArray(length); } return construct(newObj, self, new Object[]{length}); }
Example 18
Source File: NativeArray.java From jdk8u60 with GNU General Public License v2.0 | 3 votes |
/** * ECMA 15.4.2.2 new Array (len) * * Specialized constructor for one long 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 long length) { if (length >= 0L && length <= JSType.MAX_UINT) { return new NativeArray(length); } return construct(newObj, self, new Object[]{length}); }
Example 19
Source File: ArrayIndex.java From openjdk-8-source with GNU General Public License v2.0 | 2 votes |
/** * Convert an index to a long value. This basically amounts to ANDing it * with {@link JSType#MAX_UINT}, as the maximum array index in JavaScript * is 0xfffffffe * * @param index index to convert to long form * @return index as uint32 in a long */ public static long toLongIndex(final int index) { return index & JSType.MAX_UINT; }
Example 20
Source File: ArrayIndex.java From nashorn with GNU General Public License v2.0 | 2 votes |
/** * Convert an index to a long value. This basically amounts to ANDing it * with {@link JSType#MAX_UINT}, as the maximum array index in JavaScript * is 0xfffffffe * * @param index index to convert to long form * @return index as uint32 in a long */ public static long toLongIndex(final int index) { return index & JSType.MAX_UINT; }