Class AbstractJSObject

  • All Implemented Interfaces:
    JSObject
    Direct Known Subclasses:
    ScriptObjectMirror

    public abstract class AbstractJSObject
    extends java.lang.Object
    implements JSObject
    This is the base class for nashorn ScriptObjectMirror class. This class can also be subclassed by an arbitrary Java class. Nashorn will treat objects of such classes just like nashorn script objects. Usual nashorn operations like obj[i], obj.foo, obj.func(), delete obj.foo will be delegated to appropriate method call of this class.
    Since:
    1.8u40
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractJSObject()
      The default constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      java.lang.Object call​(java.lang.Object thiz, java.lang.Object... args)
      Call this object as a JavaScript function.
      java.lang.Object eval​(java.lang.String s)
      Evaluate a JavaScript expression.
      java.lang.String getClassName()
      ECMA [[Class]] property
      static java.lang.Object getDefaultValue​(JSObject jsobj, java.lang.Class<?> hint)
      Deprecated.
      java.lang.Object getMember​(java.lang.String name)
      Retrieves a named member of this JavaScript object.
      java.lang.Object getSlot​(int index)
      Retrieves an indexed member of this JavaScript object.
      boolean hasMember​(java.lang.String name)
      Does this object have a named member?
      boolean hasSlot​(int slot)
      Does this object have a indexed property?
      boolean isArray()
      Is this an array object?
      boolean isFunction()
      Is this a function object?
      boolean isInstance​(java.lang.Object instance)
      Checking whether the given object is an instance of 'this' object.
      boolean isInstanceOf​(java.lang.Object clazz)
      Checking whether this object is an instance of the given 'clazz' object.
      boolean isStrictFunction()
      Is this a 'use strict' function object?
      java.util.Set<java.lang.String> keySet()
      Returns the set of all property names of this object.
      java.lang.Object newObject​(java.lang.Object... args)
      Call this 'constructor' JavaScript function to create a new object.
      void removeMember​(java.lang.String name)
      Remove a named member from this JavaScript object
      void setMember​(java.lang.String name, java.lang.Object value)
      Set a named member in this JavaScript object
      void setSlot​(int index, java.lang.Object value)
      Set an indexed member in this JavaScript object
      double toNumber()
      Deprecated.
      use JSObject.getDefaultValue(Class) with Number hint instead.
      java.util.Collection<java.lang.Object> values()
      Returns the set of all property values of this object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractJSObject

        public AbstractJSObject()
        The default constructor.
    • Method Detail

      • call

        public java.lang.Object call​(java.lang.Object thiz,
                                     java.lang.Object... args)
        Description copied from interface: JSObject
        Call this object as a JavaScript function. This is equivalent to 'func.apply(thiz, args)' in JavaScript.
        Specified by:
        call in interface JSObject
        Parameters:
        thiz - 'this' object to be passed to the function. This may be null.
        args - arguments to method
        Returns:
        result of call
        Implementation Requirements:
        This implementation always throws UnsupportedOperationException
      • newObject

        public java.lang.Object newObject​(java.lang.Object... args)
        Description copied from interface: JSObject
        Call this 'constructor' JavaScript function to create a new object. This is equivalent to 'new func(arg1, arg2...)' in JavaScript.
        Specified by:
        newObject in interface JSObject
        Parameters:
        args - arguments to method
        Returns:
        result of constructor call
        Implementation Requirements:
        This implementation always throws UnsupportedOperationException
      • eval

        public java.lang.Object eval​(java.lang.String s)
        Description copied from interface: JSObject
        Evaluate a JavaScript expression.
        Specified by:
        eval in interface JSObject
        Parameters:
        s - JavaScript expression to evaluate
        Returns:
        evaluation result
        Implementation Requirements:
        This imlementation always throws UnsupportedOperationException
      • getMember

        public java.lang.Object getMember​(java.lang.String name)
        Description copied from interface: JSObject
        Retrieves a named member of this JavaScript object.
        Specified by:
        getMember in interface JSObject
        Parameters:
        name - of member
        Returns:
        member
        Implementation Requirements:
        This implementation always returns null
      • getSlot

        public java.lang.Object getSlot​(int index)
        Description copied from interface: JSObject
        Retrieves an indexed member of this JavaScript object.
        Specified by:
        getSlot in interface JSObject
        Parameters:
        index - index slot to retrieve
        Returns:
        member
        Implementation Requirements:
        This implementation always returns null
      • hasMember

        public boolean hasMember​(java.lang.String name)
        Description copied from interface: JSObject
        Does this object have a named member?
        Specified by:
        hasMember in interface JSObject
        Parameters:
        name - name of member
        Returns:
        true if this object has a member of the given name
        Implementation Requirements:
        This implementation always returns false
      • hasSlot

        public boolean hasSlot​(int slot)
        Description copied from interface: JSObject
        Does this object have a indexed property?
        Specified by:
        hasSlot in interface JSObject
        Parameters:
        slot - index to check
        Returns:
        true if this object has a slot
        Implementation Requirements:
        This implementation always returns false
      • removeMember

        public void removeMember​(java.lang.String name)
        Description copied from interface: JSObject
        Remove a named member from this JavaScript object
        Specified by:
        removeMember in interface JSObject
        Parameters:
        name - name of the member
        Implementation Requirements:
        This implementation is a no-op
      • setMember

        public void setMember​(java.lang.String name,
                              java.lang.Object value)
        Description copied from interface: JSObject
        Set a named member in this JavaScript object
        Specified by:
        setMember in interface JSObject
        Parameters:
        name - name of the member
        value - value of the member
        Implementation Requirements:
        This implementation is a no-op
      • setSlot

        public void setSlot​(int index,
                            java.lang.Object value)
        Description copied from interface: JSObject
        Set an indexed member in this JavaScript object
        Specified by:
        setSlot in interface JSObject
        Parameters:
        index - index of the member slot
        value - value of the member
        Implementation Requirements:
        This implementation is a no-op
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Description copied from interface: JSObject
        Returns the set of all property names of this object.
        Specified by:
        keySet in interface JSObject
        Returns:
        set of property names
        Implementation Requirements:
        This implementation returns empty set
      • values

        public java.util.Collection<java.lang.Object> values()
        Description copied from interface: JSObject
        Returns the set of all property values of this object.
        Specified by:
        values in interface JSObject
        Returns:
        set of property values.
        Implementation Requirements:
        This implementation returns empty set
      • isInstance

        public boolean isInstance​(java.lang.Object instance)
        Description copied from interface: JSObject
        Checking whether the given object is an instance of 'this' object.
        Specified by:
        isInstance in interface JSObject
        Parameters:
        instance - instance to check
        Returns:
        true if the given 'instance' is an instance of this 'function' object
        Implementation Requirements:
        This implementation always returns false
      • isInstanceOf

        public boolean isInstanceOf​(java.lang.Object clazz)
        Description copied from interface: JSObject
        Checking whether this object is an instance of the given 'clazz' object.
        Specified by:
        isInstanceOf in interface JSObject
        Parameters:
        clazz - clazz to check
        Returns:
        true if this object is an instance of the given 'clazz'
      • getClassName

        public java.lang.String getClassName()
        Description copied from interface: JSObject
        ECMA [[Class]] property
        Specified by:
        getClassName in interface JSObject
        Returns:
        ECMA [[Class]] property value of this object
      • isFunction

        public boolean isFunction()
        Description copied from interface: JSObject
        Is this a function object?
        Specified by:
        isFunction in interface JSObject
        Returns:
        if this mirror wraps a ECMAScript function instance
        Implementation Requirements:
        This implementation always returns false
      • isStrictFunction

        public boolean isStrictFunction()
        Description copied from interface: JSObject
        Is this a 'use strict' function object?
        Specified by:
        isStrictFunction in interface JSObject
        Returns:
        true if this mirror represents a ECMAScript 'use strict' function
        Implementation Requirements:
        This implementation always returns false
      • isArray

        public boolean isArray()
        Description copied from interface: JSObject
        Is this an array object?
        Specified by:
        isArray in interface JSObject
        Returns:
        if this mirror wraps a ECMAScript array object
        Implementation Requirements:
        This implementation always returns false
      • toNumber

        @Deprecated
        public double toNumber()
        Deprecated.
        use JSObject.getDefaultValue(Class) with Number hint instead.
        Returns this object's numeric value.
        Specified by:
        toNumber in interface JSObject
        Returns:
        this object's numeric value.
      • getDefaultValue

        @Deprecated
        public static java.lang.Object getDefaultValue​(JSObject jsobj,
                                                       java.lang.Class<?> hint)
        Deprecated.
        When passed an AbstractJSObject, invokes its JSObject.getDefaultValue(Class) method. When passed any other JSObject, it will obtain its [[DefaultValue]] method as per ECMAScript 5.1 section 8.6.2.
        Parameters:
        jsobj - the JSObject whose [[DefaultValue]] is obtained.
        hint - the type hint. Should be either null, Number.class or String.class.
        Returns:
        this object's default value.
        Throws:
        java.lang.UnsupportedOperationException - if the conversion can't be performed. The engine will convert this exception into a JavaScript TypeError.