Class PrototypeObjectType

  • All Implemented Interfaces:
    java.io.Serializable
    Direct Known Subclasses:
    EnumType, FunctionType, RecordType

    public class PrototypeObjectType
    extends ObjectType
    The object type represents instances of JavaScript objects such as Object, Date, Function.

    Objects in JavaScript are unordered collections of properties. Each property consists of a name, a value and a set of attributes.

    Each instance has an implicit prototype property ([[Prototype]]) pointing to an object instance, which itself has an implicit property, thus forming a chain.

    A class begins life with no name. Later, a name may be provided once it can be inferred. Note that the name in this case is strictly for debugging purposes. Looking up type name references goes through the JSTypeRegistry.

    See Also:
    Serialized Form
    • Method Detail

      • removeProperty

        public boolean removeProperty​(java.lang.String name)
        Description copied from class: ObjectType
        Removes the declared or inferred property from this ObjectType.
        Overrides:
        removeProperty in class ObjectType
        Parameters:
        name - the property's name
        Returns:
        true if the property was removed successfully. False if the property did not exist, or could not be removed.
      • setPropertyJSDocInfo

        public void setPropertyJSDocInfo​(java.lang.String propertyName,
                                         JSDocInfo info)
        Description copied from class: ObjectType
        Sets the docInfo for the specified property from the JSDocInfo on its definition.
        Overrides:
        setPropertyJSDocInfo in class ObjectType
        info - JSDocInfo for the property definition. May be null.
      • setPropertyNode

        public void setPropertyNode​(java.lang.String propertyName,
                                    Node defSite)
        Description copied from class: ObjectType
        Sets the node where the property was defined.
        Overrides:
        setPropertyNode in class ObjectType
      • matchesNumberContext

        public boolean matchesNumberContext()
        Description copied from class: JSType
        This predicate is used to test whether a given type can appear in a numeric context, such as an operand of a multiply operator.
        Overrides:
        matchesNumberContext in class JSType
      • matchesStringContext

        public boolean matchesStringContext()
        Description copied from class: JSType
        This predicate is used to test whether a given type can appear in a String context, such as an operand of a string concat (+) operator. All types have at least the potential for converting to String. When we add externally defined types, such as a browser OM, we may choose to add types that do not automatically convert to String.
        Overrides:
        matchesStringContext in class JSType
      • matchesSymbolContext

        public boolean matchesSymbolContext()
        Description copied from class: JSType
        This predicate is used to test whether a given type can appear in a symbol context such as property access.
        Overrides:
        matchesSymbolContext in class JSType
      • unboxesTo

        public final JSType unboxesTo()
        Description copied from class: JSType
        Turn an object type to its corresponding scalar type.
        Overrides:
        unboxesTo in class JSType
        Returns:
        the unboxed type or null if this type does not unbox.
      • matchesObjectContext

        public boolean matchesObjectContext()
        Description copied from class: JSType
        This predicate is used to test whether a given type can appear in an Object context, such as the expression in a with statement. Most types we will encounter, except notably null, have at least the potential for converting to Object. Host defined objects can get peculiar.
        Overrides:
        matchesObjectContext in class JSType
      • getConstructor

        public FunctionType getConstructor()
        Description copied from class: ObjectType
        Gets this object's constructor.
        Specified by:
        getConstructor in class ObjectType
        Returns:
        this object's constructor or null if it is a native object (constructed natively v.s. by instantiation of a function)
      • getTemplateParamCount

        public final int getTemplateParamCount()
        Description copied from class: JSType
        Return the number of template parameters declared for this type.

        In general, this value corresponds to the number of `@template` declarations on the type definition. It does not include template parameters from superclasses or superinterfaces.

        Overrides:
        getTemplateParamCount in class JSType
      • getReferenceName

        public java.lang.String getReferenceName()
        Description copied from class: ObjectType
        Gets the reference name for this object. This includes named types like constructors, prototypes, and enums. It notably does not include literal types like strings and booleans and structural types.

        Returning an empty string means something different than returning null. An empty string may indicate an anonymous constructor, which we treat differently than a literal type without a reference name. e.g. in InstanceObjectType.appendTo(TypeStringBuilder)

        Specified by:
        getReferenceName in class ObjectType
        Returns:
        the object's name or null if this is an anonymous object
      • isAnonymous

        public boolean isAnonymous()
      • isNativeObjectType

        public boolean isNativeObjectType()
        Whether this is a built-in object.
        Overrides:
        isNativeObjectType in class ObjectType
      • getCtorImplementedInterfaces

        public java.lang.Iterable<ObjectType> getCtorImplementedInterfaces()
        Description copied from class: ObjectType
        Gets the interfaces implemented by the ctor associated with this type. Intended to be overridden by subclasses.
        Overrides:
        getCtorImplementedInterfaces in class ObjectType
      • getCtorExtendedInterfaces

        public java.lang.Iterable<ObjectType> getCtorExtendedInterfaces()
        Description copied from class: ObjectType
        Gets the interfaces extended by the interface associated with this type. Intended to be overridden by subclasses.
        Overrides:
        getCtorExtendedInterfaces in class ObjectType
      • matchConstraint

        public void matchConstraint​(JSType constraint)
        Description copied from class: JSType
        Modify this type so that it matches the specified type. This is useful for reverse type-inference, where we want to infer that an object literal matches its constraint (much like how the java compiler does reverse-inference to figure out generics).
        Overrides:
        matchConstraint in class JSType
      • matchRecordTypeConstraint

        public void matchRecordTypeConstraint​(ObjectType constraintObj)