10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.runtime.arrays;
27
28 import java.lang.invoke.MethodHandle;
29 import java.nio.ByteBuffer;
30 import jdk.nashorn.internal.runtime.GlobalObject;
31 import jdk.nashorn.internal.runtime.JSType;
32 import jdk.nashorn.internal.runtime.PropertyDescriptor;
33
34 /**
35 * ArrayData - abstraction for wrapping array elements
36 */
37 public abstract class ArrayData {
38
39 /** Minimum chunk size for underlying arrays */
40 protected static final int CHUNK_SIZE = 16;
41
42 /** Mask for getting a chunk */
43 protected static final int CHUNK_MASK = CHUNK_SIZE - 1;
44
45 /**
46 * Immutable empty array to get ScriptObjects started.
47 */
48 public static final ArrayData EMPTY_ARRAY = new NoTypeArrayData();
49
50 /**
382 * Returns if element at specific index range can be deleted or not.
383 *
384 * @param fromIndex the start index
385 * @param toIndex the end index
386 * @param strict are we in strict mode
387 *
388 * @return true if range can be deleted
389 */
390 public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) {
391 return true;
392 }
393
394 /**
395 * Returns property descriptor for element at a given index
396 *
397 * @param global the global object
398 * @param index the index
399 *
400 * @return property descriptor for element
401 */
402 public PropertyDescriptor getDescriptor(final GlobalObject global, final int index) {
403 return global.newDataDescriptor(getObject(index), true, true, true);
404 }
405
406 /**
407 * Delete an array value at the given index, substituting
408 * for an undefined
409 *
410 * @param index the index
411 * @return new array data (or same)
412 */
413 public abstract ArrayData delete(int index);
414
415 /**
416 * Delete a given range from this array;
417 *
418 * @param fromIndex from index (inclusive)
419 * @param toIndex to index (inclusive)
420 *
421 * @return new ArrayData after deletion
422 */
|
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.nashorn.internal.runtime.arrays;
27
28 import java.lang.invoke.MethodHandle;
29 import java.nio.ByteBuffer;
30 import jdk.nashorn.internal.objects.Global;
31 import jdk.nashorn.internal.runtime.JSType;
32 import jdk.nashorn.internal.runtime.PropertyDescriptor;
33
34 /**
35 * ArrayData - abstraction for wrapping array elements
36 */
37 public abstract class ArrayData {
38
39 /** Minimum chunk size for underlying arrays */
40 protected static final int CHUNK_SIZE = 16;
41
42 /** Mask for getting a chunk */
43 protected static final int CHUNK_MASK = CHUNK_SIZE - 1;
44
45 /**
46 * Immutable empty array to get ScriptObjects started.
47 */
48 public static final ArrayData EMPTY_ARRAY = new NoTypeArrayData();
49
50 /**
382 * Returns if element at specific index range can be deleted or not.
383 *
384 * @param fromIndex the start index
385 * @param toIndex the end index
386 * @param strict are we in strict mode
387 *
388 * @return true if range can be deleted
389 */
390 public boolean canDelete(final long fromIndex, final long toIndex, final boolean strict) {
391 return true;
392 }
393
394 /**
395 * Returns property descriptor for element at a given index
396 *
397 * @param global the global object
398 * @param index the index
399 *
400 * @return property descriptor for element
401 */
402 public PropertyDescriptor getDescriptor(final Global global, final int index) {
403 return global.newDataDescriptor(getObject(index), true, true, true);
404 }
405
406 /**
407 * Delete an array value at the given index, substituting
408 * for an undefined
409 *
410 * @param index the index
411 * @return new array data (or same)
412 */
413 public abstract ArrayData delete(int index);
414
415 /**
416 * Delete a given range from this array;
417 *
418 * @param fromIndex from index (inclusive)
419 * @param toIndex to index (inclusive)
420 *
421 * @return new ArrayData after deletion
422 */
|