Interface JSObject
- All Known Implementing Classes:
AbstractJSObject, ScriptObjectMirror
public interface JSObject
This interface can be implemented 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 interface.
- Since:
- 1.8u40
-
Method Summary
Modifier and TypeMethodDescriptionCall this object as a JavaScript function.Evaluate a JavaScript expression.ECMA [[Class]] propertydefault ObjectgetDefaultValue(Class<?> hint) Implements this object's[[DefaultValue]]method as per ECMAScript 5.1 section 8.6.2.Retrieves a named member of this JavaScript object.getSlot(int index) Retrieves an indexed member of this JavaScript object.booleanDoes this object have a named member?booleanhasSlot(int slot) Does this object have a indexed property?booleanisArray()Is this an array object?booleanIs this a function object?booleanisInstance(Object instance) Checking whether the given object is an instance of 'this' object.booleanisInstanceOf(Object clazz) Checking whether this object is an instance of the given 'clazz' object.booleanIs this a 'use strict' function object?keySet()Returns the set of all property names of this object.Call this 'constructor' JavaScript function to create a new object.voidremoveMember(String name) Remove a named member from this JavaScript objectvoidSet a named member in this JavaScript objectvoidSet an indexed member in this JavaScript objectdefault doubletoNumber()Deprecated.values()Returns the set of all property values of this object.
-
Method Details
-
call
-
newObject
-
eval
-
getMember
Retrieves a named member of this JavaScript object.- Parameters:
name- of member- Returns:
- member
- Throws:
NullPointerException- if name is null
-
getSlot
Retrieves an indexed member of this JavaScript object.- Parameters:
index- index slot to retrieve- Returns:
- member
-
hasMember
Does this object have a named member?- Parameters:
name- name of member- Returns:
- true if this object has a member of the given name
-
hasSlot
boolean hasSlot(int slot) Does this object have a indexed property?- Parameters:
slot- index to check- Returns:
- true if this object has a slot
-
removeMember
Remove a named member from this JavaScript object- Parameters:
name- name of the member- Throws:
NullPointerException- if name is null
-
setMember
Set a named member in this JavaScript object- Parameters:
name- name of the membervalue- value of the member- Throws:
NullPointerException- if name is null
-
setSlot
Set an indexed member in this JavaScript object- Parameters:
index- index of the member slotvalue- value of the member
-
keySet
-
values
Collection<Object> values()Returns the set of all property values of this object.- Returns:
- set of property values.
-
isInstance
Checking whether the given object is an instance of 'this' object.- Parameters:
instance- instance to check- Returns:
- true if the given 'instance' is an instance of this 'function' object
-
isInstanceOf
Checking whether this object is an instance of the given 'clazz' object.- Parameters:
clazz- clazz to check- Returns:
- true if this object is an instance of the given 'clazz'
-
getClassName
-
isFunction
boolean isFunction()Is this a function object?- Returns:
- if this mirror wraps a ECMAScript function instance
-
isStrictFunction
boolean isStrictFunction()Is this a 'use strict' function object?- Returns:
- true if this mirror represents a ECMAScript 'use strict' function
-
isArray
boolean isArray()Is this an array object?- Returns:
- if this mirror wraps a ECMAScript array object
-
toNumber
Deprecated.usegetDefaultValue(Class)withNumberhint instead.Returns this object's numeric value.- Returns:
- this object's numeric value.
-
getDefaultValue
Implements this object's[[DefaultValue]]method as per ECMAScript 5.1 section 8.6.2.- Parameters:
hint- the type hint. Should be eithernull,Number.classorString.class.- Returns:
- this object's default value.
- Throws:
UnsupportedOperationException- if the conversion can't be performed. The engine will convert this exception into a JavaScriptTypeError.
-
getDefaultValue(Class)withNumberhint instead.