Class ScriptArray

java.lang.Object
com.oracle.truffle.js.runtime.array.ScriptArray
Direct Known Subclasses:
DynamicArray, TypedArray

public abstract class ScriptArray extends Object
  • Field Details

    • EMPTY_OBJECT_ARRAY

      public static final Object[] EMPTY_OBJECT_ARRAY
  • Constructor Details

    • ScriptArray

      public ScriptArray()
  • Method Details

    • getElement

      public abstract Object getElement(JSDynamicObject object, long index)
    • getElementInBounds

      public abstract Object getElementInBounds(JSDynamicObject object, long index)
    • setElementImpl

      public abstract ScriptArray setElementImpl(JSDynamicObject object, long index, Object value, boolean strict)
    • setElement

      public final ScriptArray setElement(JSDynamicObject object, long index, Object value, boolean strict)
    • deleteElementImpl

      public abstract ScriptArray deleteElementImpl(JSDynamicObject object, long index, boolean strict)
    • deleteElement

      public final ScriptArray deleteElement(JSDynamicObject object, long index, boolean strict)
    • canDeleteElement

      public final boolean canDeleteElement(JSDynamicObject object, long index, boolean strict)
    • hasElement

      public abstract boolean hasElement(JSDynamicObject object, long index)
      Returns:
      true if array has an element (not a hole) at this index.
    • length

      public abstract long length(JSDynamicObject object)
    • lengthInt

      public abstract int lengthInt(JSDynamicObject object)
    • setLengthImpl

      public abstract ScriptArray setLengthImpl(JSDynamicObject object, long len, com.oracle.truffle.api.nodes.Node node, ScriptArray.SetLengthProfileAccess profile)
    • setLength

      public final ScriptArray setLength(JSDynamicObject object, long len, boolean strict, com.oracle.truffle.api.nodes.Node node, ScriptArray.SetLengthProfileAccess profile)
    • setLength

      public final ScriptArray setLength(JSDynamicObject object, long len, boolean strict)
    • firstElementIndex

      public abstract long firstElementIndex(JSDynamicObject object)
      First element index (inclusive).
    • lastElementIndex

      public abstract long lastElementIndex(JSDynamicObject object)
      Last element index (inclusive).
    • nextElementIndex

      public abstract long nextElementIndex(JSDynamicObject object, long index)
      Returns the next index. The index is guaranteed either to exist, or be MAX_SAFE_INTEGER. Reason for MAX_SAFE_INTEGER is: this array could be the prototype of another one; returning the length() of this array would be wrong, if the inheriting array is longer, but has a hole at length().
    • previousElementIndex

      public abstract long previousElementIndex(JSDynamicObject object, long index)
      Returns the previous index. The index is guaranteed either to exist, or be smaller than firstElementIndex().
    • isInBoundsFast

      public boolean isInBoundsFast(JSDynamicObject object, long index)
      Range check only, might be a hole depending on array type.
    • asIterable

      public Iterable<Object> asIterable(JSDynamicObject object)
    • toArray

      public final Object[] toArray(JSDynamicObject thisObj)
      Creates an Object[] from this array, of size array.length. Does not check the prototype chain, i.e. result can be wrong. Use JSToObjectArrayNode for more correct results. This is mostly used in tests, but also in a few places in Node.js.
    • createConstantEmptyArray

      public static AbstractConstantArray createConstantEmptyArray()
    • createConstantArray

      public static AbstractConstantArray createConstantArray(Object[] elements)
    • valueIsByte

      public static boolean valueIsByte(int value)
    • traceArrayTransition

      protected static final void traceArrayTransition(ScriptArray oldArray, ScriptArray newArray, long index, Object value)
    • traceWrite

      protected static final void traceWrite(String access, long index, Object value)
    • isHolesType

      public boolean isHolesType()
      Returns true if this array type could have hole values in it. Doesn't tell whether it actually HAS holes.
    • hasHoles

      public abstract boolean hasHoles(JSDynamicObject object)
      Returns true when this array actually has holes between firstElementIndex(JSDynamicObject) and lastElementIndex(JSDynamicObject). Implies isHolesType().
      See Also:
    • hasHolesOrUnused

      public boolean hasHolesOrUnused(JSDynamicObject object)
      Returns true when this array has any hole or unused elements between 0 and length(JSDynamicObject).
      See Also:
    • removeRangeImpl

      public abstract ScriptArray removeRangeImpl(JSDynamicObject object, long start, long end)
      This function deletes all elements in the range from [start..end[. This is equivalent to shifting the whole array, starting with element index end, by end-start positions to the left. Can be used by e.g. Array.prototype.splice;
    • removeRange

      public final ScriptArray removeRange(JSDynamicObject object, long start, long end)
    • removeRange

      public final ScriptArray removeRange(JSDynamicObject object, long start, long end, com.oracle.truffle.api.profiles.BranchProfile errorBranch)
    • shiftRangeImpl

      public ScriptArray shiftRangeImpl(JSDynamicObject object, long limit)
      This function shifts all elements in the range from [0..limit[. Depending on the underlying implementation, the shift operation might be zero-copy. Can be used by e.g. Array.prototype.shift;
    • shiftRange

      public final ScriptArray shiftRange(JSDynamicObject object, long from)
    • addRangeImpl

      public abstract ScriptArray addRangeImpl(JSDynamicObject object, long offset, int size)
      This method grows the array by adding more elements of a given size. An offset parameter can be used to specify where the new elements have to be added (starting from zero). The operation is equivalent to shifting (right) the whole array or its part as defined by the offset parameter.
      Parameters:
      offset - starting offset position
      size - size of the inserted empty array
      Returns:
      a ScriptArray instance with the new size
    • addRange

      public final ScriptArray addRange(JSDynamicObject object, long offset, int size)
    • ownPropertyKeys

      public List<Object> ownPropertyKeys(JSDynamicObject object)
    • ownPropertyKeysContiguous

      protected final List<Object> ownPropertyKeysContiguous(JSDynamicObject object)
    • ownPropertyKeysHoles

      protected final List<Object> ownPropertyKeysHoles(JSDynamicObject object)
    • makeRangeList

      public static List<Object> makeRangeList(long rangeStart, long rangeEnd)
    • makeMultiRangeList

      protected static List<Object> makeMultiRangeList(int total, long[] ranges)
    • nextPower

      protected static int nextPower(int length)
    • isSealed

      public boolean isSealed()
    • isFrozen

      public boolean isFrozen()
    • isLengthNotWritable

      public boolean isLengthNotWritable()
    • isExtensible

      public boolean isExtensible()
    • seal

      public abstract ScriptArray seal()
    • freeze

      public abstract ScriptArray freeze()
    • setLengthNotWritable

      public abstract ScriptArray setLengthNotWritable()
    • preventExtensions

      public abstract ScriptArray preventExtensions()
    • isInstance

      public final boolean isInstance(ScriptArray other)
    • cast

      public final ScriptArray cast(ScriptArray other)