Class DynamicObject.GetNode

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

public abstract static class DynamicObject.GetNode extends Node
Gets the value of a property or returns a default value if no such property exists.

Specialized return type variants are available for when a primitive result is expected.

Since:
25.1
See Also:
  • Method Details

    • execute

      public abstract Object execute(DynamicObject receiver, Object key, Object defaultValue)
      Gets the value of an existing property or returns the provided default value if no such property exists.

      Usage examples:

      Simple use of DynamicObject.GetNode with a pre-interned symbol key.

      abstract static class GetSimpleNode extends Node {
          abstract Object execute(DynamicObject receiver, Object key);
      
          @Specialization
          static Object doCached(MyDynamicObjectSubclass receiver, Symbol key,
                          @Cached DynamicObject.GetNode getNode) {
              return getNode.execute(receiver, key, NULL_VALUE);
          }
      }
      

      Simple use of DynamicObject.GetNode with a string key cached by equality.

      abstract static class GetStringKeyNode extends Node {
          abstract Object execute(DynamicObject receiver, Object key);
      
          @Specialization(guards = "equalNode.execute(key, cachedKey, UTF_16)", limit = "3")
          static Object doCached(MyDynamicObjectSubclass receiver, TruffleString key,
                          @Cached("key") TruffleString cachedKey,
                          @Cached TruffleString.EqualNode equalNode,
                          @Cached DynamicObject.GetNode getNode) {
              return getNode.execute(receiver, cachedKey, NULL_VALUE);
          }
      }
      
      Parameters:
      key - the property key, compared by identity (==), not equality (equals). See DynamicObject for more information.
      defaultValue - value to be returned if the property does not exist
      Returns:
      the property's value if it exists, else defaultValue.
      Since:
      25.1
    • executeInt

      public abstract int executeInt(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException
      Gets the value of an existing property or returns the provided default value if no such property exists.
      Parameters:
      key - the property key, compared by identity (==), not equality (equals). See DynamicObject for more information.
      defaultValue - the value to be returned if the property does not exist
      Returns:
      the property's value if it exists, else defaultValue.
      Throws:
      UnexpectedResultException - if the value (or default value if the property is missing) is not an int
      Since:
      25.1
      See Also:
    • executeLong

      public abstract long executeLong(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException
      Gets the value of an existing property or returns the provided default value if no such property exists.
      Parameters:
      key - the property key, compared by identity (==), not equality (equals). See DynamicObject for more information.
      defaultValue - the value to be returned if the property does not exist
      Returns:
      the property's value if it exists, else defaultValue.
      Throws:
      UnexpectedResultException - if the value (or default value if the property is missing) is not an long
      Since:
      25.1
      See Also:
    • executeDouble

      public abstract double executeDouble(DynamicObject receiver, Object key, Object defaultValue) throws UnexpectedResultException
      Gets the value of an existing property or returns the provided default value if no such property exists.
      Parameters:
      key - the property key, compared by identity (==), not equality (equals). See DynamicObject for more information.
      defaultValue - the value to be returned if the property does not exist
      Returns:
      the property's value if it exists, else defaultValue.
      Throws:
      UnexpectedResultException - if the value (or default value if the property is missing) is not an double
      Since:
      25.1
      See Also:
    • create

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

      public static DynamicObject.GetNode getUncached()
      Since:
      25.1