Java Code Examples for jdk.nashorn.internal.runtime.JSType#toNarrowestNumber()
The following examples show how to use
jdk.nashorn.internal.runtime.JSType#toNarrowestNumber() .
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 TencentKona-8 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 openjdk-jdk8u 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 3
Source File: NativeArray.java From openjdk-jdk8u-backup 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 4
Source File: NativeArray.java From openjdk-jdk9 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 5
Source File: NativeArray.java From hottub 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 6
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 7
Source File: NativeArray.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] ) * * @param self self reference * @param items items for unshift * @return unshifted array */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object unshift(final Object self, final Object... items) { 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()); if (items == null) { return ScriptRuntime.UNDEFINED; } if (bulkable(sobj)) { sobj.getArray().shiftRight(items.length); for (int j = 0; j < items.length; j++) { sobj.setArray(sobj.getArray().set(j, items[j], true)); } } else { for (long k = len; k > 0; k--) { final long from = k - 1; final long to = k + items.length - 1; if (sobj.has(from)) { final Object fromValue = sobj.get(from); sobj.set(to, fromValue, CALLSITE_STRICT); } else { sobj.delete(to, true); } } for (int j = 0; j < items.length; j++) { sobj.set(j, items[j], CALLSITE_STRICT); } } final long newLength = len + items.length; sobj.set("length", newLength, CALLSITE_STRICT); return JSType.toNarrowestNumber(newLength); }
Example 8
Source File: NativeArray.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] ) * * @param self self reference * @param items items for unshift * @return unshifted array */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object unshift(final Object self, final Object... items) { 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()); if (items == null) { return ScriptRuntime.UNDEFINED; } if (bulkable(sobj)) { sobj.getArray().shiftRight(items.length); for (int j = 0; j < items.length; j++) { sobj.setArray(sobj.getArray().set(j, items[j], true)); } } else { for (long k = len; k > 0; k--) { final long from = k - 1; final long to = k + items.length - 1; if (sobj.has(from)) { final Object fromValue = sobj.get(from); sobj.set(to, fromValue, CALLSITE_STRICT); } else { sobj.delete(to, true); } } for (int j = 0; j < items.length; j++) { sobj.set(j, items[j], CALLSITE_STRICT); } } final long newLength = len + items.length; sobj.set("length", newLength, CALLSITE_STRICT); return JSType.toNarrowestNumber(newLength); }
Example 9
Source File: NativeArray.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] ) * * @param self self reference * @param items items for unshift * @return unshifted array */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object unshift(final Object self, final Object... items) { 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()); if (items == null) { return ScriptRuntime.UNDEFINED; } if (bulkable(sobj)) { sobj.getArray().shiftRight(items.length); for (int j = 0; j < items.length; j++) { sobj.setArray(sobj.getArray().set(j, items[j], true)); } } else { for (long k = len; k > 0; k--) { final long from = k - 1; final long to = k + items.length - 1; if (sobj.has(from)) { final Object fromValue = sobj.get(from); sobj.set(to, fromValue, CALLSITE_STRICT); } else { sobj.delete(to, true); } } for (int j = 0; j < items.length; j++) { sobj.set(j, items[j], CALLSITE_STRICT); } } final long newLength = len + items.length; sobj.set("length", newLength, CALLSITE_STRICT); return JSType.toNarrowestNumber(newLength); }
Example 10
Source File: NativeArray.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] ) * * @param self self reference * @param items items for unshift * @return unshifted array */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object unshift(final Object self, final Object... items) { 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()); if (items == null) { return ScriptRuntime.UNDEFINED; } if (bulkable(sobj)) { sobj.getArray().shiftRight(items.length); for (int j = 0; j < items.length; j++) { sobj.setArray(sobj.getArray().set(j, items[j], true)); } } else { for (long k = len; k > 0; k--) { final long from = k - 1; final long to = k + items.length - 1; if (sobj.has(from)) { final Object fromValue = sobj.get(from); sobj.set(to, fromValue, CALLSITE_STRICT); } else { sobj.delete(to, true); } } for (int j = 0; j < items.length; j++) { sobj.set(j, items[j], CALLSITE_STRICT); } } final long newLength = len + items.length; sobj.set("length", newLength, CALLSITE_STRICT); return JSType.toNarrowestNumber(newLength); }
Example 11
Source File: NativeArray.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] ) * * @param self self reference * @param items items for unshift * @return unshifted array */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object unshift(final Object self, final Object... items) { 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()); if (items == null) { return ScriptRuntime.UNDEFINED; } if (bulkable(sobj)) { sobj.getArray().shiftRight(items.length); for (int j = 0; j < items.length; j++) { sobj.setArray(sobj.getArray().set(j, items[j], true)); } } else { for (long k = len; k > 0; k--) { final long from = k - 1; final long to = k + items.length - 1; if (sobj.has(from)) { final Object fromValue = sobj.get(from); sobj.set(to, fromValue, CALLSITE_STRICT); } else { sobj.delete(to, true); } } for (int j = 0; j < items.length; j++) { sobj.set(j, items[j], CALLSITE_STRICT); } } final long newLength = len + items.length; sobj.set("length", newLength, CALLSITE_STRICT); return JSType.toNarrowestNumber(newLength); }
Example 12
Source File: NativeArray.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
/** * ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] ) * * @param self self reference * @param items items for unshift * @return unshifted array */ @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) public static Object unshift(final Object self, final Object... items) { 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()); if (items == null) { return ScriptRuntime.UNDEFINED; } if (bulkable(sobj)) { sobj.getArray().shiftRight(items.length); for (int j = 0; j < items.length; j++) { sobj.setArray(sobj.getArray().set(j, items[j], true)); } } else { for (long k = len; k > 0; k--) { final long from = k - 1; final long to = k + items.length - 1; if (sobj.has(from)) { final Object fromValue = sobj.get(from); sobj.set(to, fromValue, CALLSITE_STRICT); } else { sobj.delete(to, true); } } for (int j = 0; j < items.length; j++) { sobj.set(j, items[j], CALLSITE_STRICT); } } final long newLength = len + items.length; sobj.set("length", newLength, CALLSITE_STRICT); return JSType.toNarrowestNumber(newLength); }