Class DynamicObject.GetKeyArrayNode

java.lang.Object
com.oracle.truffle.api.nodes.Node
com.oracle.truffle.api.object.DynamicObject.GetKeyArrayNode
All Implemented Interfaces:
NodeInterface, Cloneable
Enclosing class:
DynamicObject

public abstract static class DynamicObject.GetKeyArrayNode extends Node
Gets a snapshot of the object's property keys, in insertion order.
Since:
25.1
See Also:
  • Method Details

    • execute

      public abstract Object[] execute(DynamicObject receiver)
      Gets a snapshot of the object's property keys, in insertion order. The returned array may have been cached and must not be mutated. Properties with a HiddenKey are not included.

      Usage example:

      The example below shows how the returned keys array could be translated to an interop array for use with InteropLibrary.
      @ExportMessage
      Object getMembers(boolean includeInternal,
                      @Cached DynamicObject.GetKeyArrayNode getKeyArrayNode) {
          return new Keys(getKeyArrayNode.execute(this));
      }
      
      @ExportLibrary(InteropLibrary.class)
      static final class Keys implements TruffleObject {
      
          @CompilationFinal(dimensions = 1) final Object[] keys;
      
          Keys(Object[] keys) {
              this.keys = keys;
          }
      
          @ExportMessage
          boolean hasArrayElements() {
              return true;
          }
      
          @ExportMessage
          Object readArrayElement(long index) throws InvalidArrayIndexException {
              if (!isArrayElementReadable(index)) {
                  throw InvalidArrayIndexException.create(index);
              }
              return keys[(int) index];
          }
      
          @ExportMessage
          long getArraySize() {
              return keys.length;
          }
      
          @ExportMessage
          boolean isArrayElementReadable(long index) {
              return index >= 0 && index < keys.length;
          }
      }
      
      Returns:
      a read-only array of the object's property keys. Do not modify.
    • create

      public static DynamicObject.GetKeyArrayNode create()
      Since:
      25.1
    • getUncached

      public static DynamicObject.GetKeyArrayNode getUncached()
      Since:
      25.1