Class DynamicObject.GetPropertyFlagsNode
java.lang.Object
com.oracle.truffle.api.nodes.Node
com.oracle.truffle.api.object.DynamicObject.GetPropertyFlagsNode
- All Implemented Interfaces:
NodeInterface, Cloneable
- Enclosing class:
DynamicObject
Gets the property flags associated with the requested property key.
- Since:
- 25.1
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Node
Node.Child, Node.Children -
Method Summary
Modifier and TypeMethodDescriptioncreate()abstract intexecute(DynamicObject receiver, Object key, int defaultValue) Gets the property flags associated with the requested property key.Methods inherited from class Node
accept, adoptChildren, atomic, atomic, copy, deepCopy, getChildren, getCost, getDebugProperties, getDescription, getEncapsulatingSourceSection, getLock, getParent, getRootNode, getSourceSection, insert, insert, isAdoptable, isSafelyReplaceableBy, notifyInserted, onReplace, replace, replace, reportPolymorphicSpecialize, reportReplace, toString
-
Method Details
-
execute
Gets the property flags associated with the requested property key. Returns thedefaultValueif the object contains no such property. If the property exists but no flags were explicitly set, returns the default of 0.Convenience method equivalent to:
abstract static class GetPropertyEquivalentNode extends Node { abstract void execute(DynamicObject receiver, Object key); @Specialization int doGeneric(MyDynamicObjectSubclass receiver, Symbol key, int defaultValue, @Cached DynamicObject.GetPropertyNode getPropertyNode) { Property property = getPropertyNode.execute(receiver, key); return property != null ? property.getFlags() : defaultValue; } }Usage example:
Implementing read-only property check in writeMember:
Member name equality check omitted for brevity.static final int READ_ONLY = 1; static final int MISSING = -1; static final int FROZEN = 1; @ExportMessage void writeMember(String member, Object value, @Cached @Shared DynamicObject.GetShapeFlagsNode getShapeFlagsNode, @Cached @Shared DynamicObject.GetPropertyFlagsNode getPropertyFlagsNode, @Cached DynamicObject.PutNode putNode) throws UnknownIdentifierException, UnsupportedMessageException { if ((getShapeFlagsNode.execute(this) & FROZEN) == FROZEN) { throw UnsupportedMessageException.create(); } int flags = getPropertyFlagsNode.execute(this, member, MISSING); if (flags == MISSING) { throw UnknownIdentifierException.create(member); } else if ((flags & READ_ONLY) == READ_ONLY) { throw UnsupportedMessageException.create(); } putNode.execute(this, member, value); } @ExportMessage boolean isMemberModifiable(String member, @Cached @Shared DynamicObject.GetShapeFlagsNode getShapeFlagsNode, @Cached @Shared DynamicObject.GetPropertyFlagsNode getPropertyFlagsNode) { if ((getShapeFlagsNode.execute(this) & FROZEN) == FROZEN) { return false; } int flags = getPropertyFlagsNode.execute(this, member, MISSING); return flags != MISSING && (flags & READ_ONLY) == 0; } @ExportMessage boolean isMemberInsertable(String member, @Cached @Shared DynamicObject.GetShapeFlagsNode getShapeFlagsNode, @Cached @Shared DynamicObject.GetPropertyFlagsNode getPropertyFlagsNode) { if ((getShapeFlagsNode.execute(this) & FROZEN) == FROZEN) { return false; } return getPropertyFlagsNode.execute(this, member, MISSING) == MISSING; }- Parameters:
key- the property key, compared by identity (==), not equality (equals). SeeDynamicObjectfor more information.defaultValue- value to return if no such property exists- Returns:
- the property flags if the property exists, else
defaultValue - See Also:
-
create
- Since:
- 25.1
-
getUncached
- Since:
- 25.1
-