Java Code Examples for jdk.nashorn.internal.runtime.arrays.ArrayData#ensure()
The following examples show how to use
jdk.nashorn.internal.runtime.arrays.ArrayData#ensure() .
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 openjdk-8-source with GNU General Public License v2.0 | 6 votes |
NativeArray(final Object[] array) { this(ArrayData.allocate(array.length)); ArrayData arrayData = this.getArray(); arrayData.ensure(array.length - 1); for (int index = 0; index < array.length; index++) { final Object value = array[index]; if (value == ScriptRuntime.EMPTY) { arrayData = arrayData.delete(index); } else { arrayData = arrayData.set(index, value, false); } } this.setArray(arrayData); }
Example 2
Source File: NativeArray.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
NativeArray(final Object[] array) { this(ArrayData.allocate(array.length)); ArrayData arrayData = this.getArray(); arrayData.ensure(array.length - 1); for (int index = 0; index < array.length; index++) { final Object value = array[index]; if (value == ScriptRuntime.EMPTY) { arrayData = arrayData.delete(index); } else { arrayData = arrayData.set(index, value, false); } } this.setArray(arrayData); }
Example 3
Source File: NativeArray.java From nashorn with GNU General Public License v2.0 | 6 votes |
NativeArray(final Object[] array) { this(ArrayData.allocate(array.length)); ArrayData arrayData = this.getArray(); arrayData.ensure(array.length - 1); for (int index = 0; index < array.length; index++) { final Object value = array[index]; if (value == ScriptRuntime.EMPTY) { arrayData = arrayData.delete(index); } else { arrayData = arrayData.set(index, value, false); } } this.setArray(arrayData); }
Example 4
Source File: JSONParser.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 5
Source File: JSONParser.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 6
Source File: JSONParser.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 7
Source File: JSONParser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 8
Source File: JSONParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 9
Source File: JSONParser.java From hottub with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 10
Source File: JSONParser.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
private static ArrayData addArrayElement(final ArrayData arrayData, final int index, final Object value) { final long oldLength = arrayData.length(); final long longIndex = ArrayIndex.toLongIndex(index); ArrayData newArrayData = arrayData; if (longIndex >= oldLength) { newArrayData = newArrayData.ensure(longIndex); if (longIndex > oldLength) { newArrayData = newArrayData.delete(oldLength, longIndex - 1); } } return newArrayData.set(index, value, false); }
Example 11
Source File: ScriptObject.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Numeric length setter for length property * * @param newLength new length to set */ public final void setLength(final long newLength) { ArrayData data = getArray(); final long arrayLength = data.length(); if (newLength == arrayLength) { return; } if (newLength > arrayLength) { data = data.ensure(newLength - 1); if (data.canDelete(arrayLength, newLength - 1, false)) { data = data.delete(arrayLength, newLength - 1); } setArray(data); return; } if (newLength < arrayLength) { long actualLength = newLength; // Check for numeric keys in property map and delete them or adjust length, depending on whether // they're defined as configurable. See ES5 #15.4.5.2 if (getMap().containsArrayKeys()) { for (long l = arrayLength - 1; l >= newLength; l--) { final FindProperty find = findProperty(JSType.toString(l), false); if (find != null) { if (find.getProperty().isConfigurable()) { deleteOwnProperty(find.getProperty()); } else { actualLength = l + 1; break; } } } } setArray(data.shrink(actualLength)); data.setLength(actualLength); } }