- java.lang.Object
-
- jdk.nashorn.api.scripting.AbstractJSObject
-
- jdk.nashorn.api.scripting.ScriptObjectMirror
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Object
call(Object thiz, Object... args)
Call this object as a JavaScript function.Object
callMember(String functionName, Object... args)
Call member functionvoid
clear()
Removes all of the mappings from this map (optional operation).boolean
containsKey(Object key)
Returnstrue
if this map contains a mapping for the specified key.boolean
containsValue(Object value)
Returnstrue
if this map maps one or more keys to the specified value.boolean
delete(Object key)
Delete a property from this object.Set<Map.Entry<String,Object>>
entrySet()
Returns aSet
view of the mappings contained in this map.boolean
equals(Object other)
Indicates whether some other object is "equal to" this one.Object
eval(String s)
Evaluate a JavaScript expression.ScriptObjectMirror
freeze()
ECMA 15.2.39 - freeze implementation.Object
get(Object key)
Returns the value to which this map maps the specified key.String
getClassName()
ECMA [[Class]] propertyObject
getDefaultValue(Class<?> hint)
Implements this object's[[DefaultValue]]
method as per ECMAScript 5.1 section 8.6.2.Object
getMember(String name)
Retrieves a named member of this JavaScript object.String[]
getOwnKeys(boolean all)
return an array of own property keys associated with the object.Object
getOwnPropertyDescriptor(String key)
ECMA 8.12.1 [[GetOwnProperty]] (P)Object
getProto()
Return the __proto__ of this object.Object
getSlot(int index)
Retrieves an indexed member of this JavaScript object.int
hashCode()
Returns a hash code value for the object.boolean
hasMember(String name)
Does this object have a named member?boolean
hasSlot(int slot)
Does this object have a indexed property?static boolean
identical(Object obj1, Object obj2)
Are the given objects mirrors to same underlying object?boolean
isArray()
Is this an array object?boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.boolean
isExtensible()
Check if this script object is extensibleboolean
isFrozen()
Check whether this script object is frozenboolean
isFunction()
Is this a function object?boolean
isInstance(Object instance)
Checking whether the given object is an instance of 'this' object.boolean
isSealed()
Check whether this script object is sealedboolean
isStrictFunction()
Is this a 'use strict' function object?static boolean
isUndefined(Object obj)
Utility to check if given object is ECMAScript undefined valueSet<String>
keySet()
Returns the set of all property names of this object.Object
newObject(Object... args)
Call this 'constructor' JavaScript function to create a new object.ScriptObjectMirror
preventExtensions()
Flag this script object as non extensibleObject
put(String key, Object value)
Set a named value.void
putAll(Map<? extends String,? extends Object> map)
Adds all the mappings in a givenMap
to thisBindings
.Object
remove(Object key)
Removes the mapping for this key from this map if it is present (optional operation).void
removeMember(String name)
Remove a named member from this JavaScript objectScriptObjectMirror
seal()
ECMAScript 15.2.3.8 - seal implementationvoid
setIndexedPropertiesToExternalArrayData(ByteBuffer buf)
Nashorn extension: setIndexedPropertiesToExternalArrayData.void
setMember(String name, Object value)
Set a named member in this JavaScript objectvoid
setProto(Object proto)
Set the __proto__ of this object.void
setSlot(int index, Object value)
Set an indexed member in this JavaScript objectint
size()
Returns the number of key-value mappings in this map.<T> T
to(Class<T> type)
Utility to convert this script object to the given type.double
toNumber()
Deprecated.String
toString()
Returns a string representation of the object.static Object
unwrap(Object obj, Object homeGlobal)
Unwrap a script object mirror if needed.static Object[]
unwrapArray(Object[] args, Object homeGlobal)
Unwrap an array of script object mirrors if needed.Collection<Object>
values()
Returns the set of all property values of this object.static Object
wrap(Object obj, Object homeGlobal)
Make a script object mirror on given object if needed.static Object[]
wrapArray(Object[] args, Object homeGlobal)
Wrap an array of object to script object mirrors if needed.static Object
wrapAsJSONCompatible(Object obj, Object homeGlobal)
Make a script object mirror on given object if needed.-
Methods inherited from class jdk.nashorn.api.scripting.AbstractJSObject
getDefaultValue, isInstanceOf
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, entry, forEach, getOrDefault, merge, of, of, of, of, of, of, of, of, of, of, of, ofEntries, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Method Detail
-
equals
public boolean equals(Object other)
Description copied from class:Object
Indicates whether some other object is "equal to" this one.The
equals
method implements an equivalence relation on non-null object references:- It is reflexive: for any non-null reference value
x
,x.equals(x)
should returntrue
. - It is symmetric: for any non-null reference values
x
andy
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any non-null reference values
x
,y
, andz
, ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
. - It is consistent: for any non-null reference values
x
andy
, multiple invocations ofx.equals(y)
consistently returntrue
or consistently returnfalse
, provided no information used inequals
comparisons on the objects is modified. - For any non-null reference value
x
,x.equals(null)
should returnfalse
.
The
equals
method for classObject
implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference valuesx
andy
, this method returnstrue
if and only ifx
andy
refer to the same object (x == y
has the valuetrue
).Note that it is generally necessary to override the
hashCode
method whenever this method is overridden, so as to maintain the general contract for thehashCode
method, which states that equal objects must have equal hash codes. - It is reflexive: for any non-null reference value
-
hashCode
public int hashCode()
Description copied from class:Object
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided byHashMap
.The general contract of
hashCode
is:- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
hashCode
method must consistently return the same integer, provided no information used inequals
comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals(Object)
method, then calling thehashCode
method on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal
according to the
Object.equals(java.lang.Object)
method, then calling thehashCode
method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class
Object
does return distinct integers for distinct objects. (The hashCode may or may not be implemented as some function of an object's memory address at some point in time.)- Specified by:
hashCode
in interfaceMap<String,Object>
- Overrides:
hashCode
in classObject
- Returns:
- a hash code value for this object.
- See Also:
Object.equals(java.lang.Object)
,System.identityHashCode(java.lang.Object)
- Whenever it is invoked on the same object more than once during
an execution of a Java application, the
-
toString
public String toString()
Description copied from class:Object
Returns a string representation of the object. In general, thetoString
method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.The
toString
method for classObject
returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@
', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:getClass().getName() + '@' + Integer.toHexString(hashCode())
-
call
public Object call(Object thiz, 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 interfaceJSObject
- Overrides:
call
in classAbstractJSObject
- Parameters:
thiz
- 'this' object to be passed to the function. This may be null.args
- arguments to method- Returns:
- result of call
-
newObject
public Object newObject(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 interfaceJSObject
- Overrides:
newObject
in classAbstractJSObject
- Parameters:
args
- arguments to method- Returns:
- result of constructor call
-
eval
public Object eval(String s)
Description copied from interface:JSObject
Evaluate a JavaScript expression.- Specified by:
eval
in interfaceJSObject
- Overrides:
eval
in classAbstractJSObject
- Parameters:
s
- JavaScript expression to evaluate- Returns:
- evaluation result
-
callMember
public Object callMember(String functionName, Object... args)
Call member function- Parameters:
functionName
- function nameargs
- arguments- Returns:
- return value of function
-
getMember
public Object getMember(String name)
Description copied from interface:JSObject
Retrieves a named member of this JavaScript object.- Specified by:
getMember
in interfaceJSObject
- Overrides:
getMember
in classAbstractJSObject
- Parameters:
name
- of member- Returns:
- member
-
getSlot
public Object getSlot(int index)
Description copied from interface:JSObject
Retrieves an indexed member of this JavaScript object.- Specified by:
getSlot
in interfaceJSObject
- Overrides:
getSlot
in classAbstractJSObject
- Parameters:
index
- index slot to retrieve- Returns:
- member
-
hasMember
public boolean hasMember(String name)
Description copied from interface:JSObject
Does this object have a named member?- Specified by:
hasMember
in interfaceJSObject
- Overrides:
hasMember
in classAbstractJSObject
- Parameters:
name
- name of member- Returns:
- true if this object has a member of the given name
-
hasSlot
public boolean hasSlot(int slot)
Description copied from interface:JSObject
Does this object have a indexed property?- Specified by:
hasSlot
in interfaceJSObject
- Overrides:
hasSlot
in classAbstractJSObject
- Parameters:
slot
- index to check- Returns:
- true if this object has a slot
-
removeMember
public void removeMember(String name)
Description copied from interface:JSObject
Remove a named member from this JavaScript object- Specified by:
removeMember
in interfaceJSObject
- Overrides:
removeMember
in classAbstractJSObject
- Parameters:
name
- name of the member
-
setMember
public void setMember(String name, Object value)
Description copied from interface:JSObject
Set a named member in this JavaScript object- Specified by:
setMember
in interfaceJSObject
- Overrides:
setMember
in classAbstractJSObject
- Parameters:
name
- name of the membervalue
- value of the member
-
setSlot
public void setSlot(int index, Object value)
Description copied from interface:JSObject
Set an indexed member in this JavaScript object- Specified by:
setSlot
in interfaceJSObject
- Overrides:
setSlot
in classAbstractJSObject
- Parameters:
index
- index of the member slotvalue
- value of the member
-
setIndexedPropertiesToExternalArrayData
public void setIndexedPropertiesToExternalArrayData(ByteBuffer buf)
Nashorn extension: setIndexedPropertiesToExternalArrayData. set indexed properties be exposed from a given nio ByteBuffer.- Parameters:
buf
- external buffer - should be a nio ByteBuffer
-
isInstance
public boolean isInstance(Object instance)
Description copied from interface:JSObject
Checking whether the given object is an instance of 'this' object.- Specified by:
isInstance
in interfaceJSObject
- Overrides:
isInstance
in classAbstractJSObject
- Parameters:
instance
- instance to check- Returns:
- true if the given 'instance' is an instance of this 'function' object
-
getClassName
public String getClassName()
Description copied from interface:JSObject
ECMA [[Class]] property- Specified by:
getClassName
in interfaceJSObject
- Overrides:
getClassName
in classAbstractJSObject
- 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 interfaceJSObject
- Overrides:
isFunction
in classAbstractJSObject
- Returns:
- if this mirror wraps a ECMAScript function instance
-
isStrictFunction
public boolean isStrictFunction()
Description copied from interface:JSObject
Is this a 'use strict' function object?- Specified by:
isStrictFunction
in interfaceJSObject
- Overrides:
isStrictFunction
in classAbstractJSObject
- Returns:
- true if this mirror represents a ECMAScript 'use strict' function
-
isArray
public boolean isArray()
Description copied from interface:JSObject
Is this an array object?- Specified by:
isArray
in interfaceJSObject
- Overrides:
isArray
in classAbstractJSObject
- Returns:
- if this mirror wraps a ECMAScript array object
-
clear
public void clear()
Description copied from interface:Map
Removes all of the mappings from this map (optional operation). The map will be empty after this call returns.
-
containsKey
public boolean containsKey(Object key)
Description copied from interface:Bindings
Returnstrue
if this map contains a mapping for the specified key. More formally, returnstrue
if and only if this map contains a mapping for a keyk
such that(key==null ? k==null : key.equals(k))
. (There can be at most one such mapping.)- Specified by:
containsKey
in interfaceBindings
- Specified by:
containsKey
in interfaceMap<String,Object>
- Parameters:
key
- key whose presence in this map is to be tested.- Returns:
true
if this map contains a mapping for the specified key.
-
containsValue
public boolean containsValue(Object value)
Description copied from interface:Map
Returnstrue
if this map maps one or more keys to the specified value. More formally, returnstrue
if and only if this map contains at least one mapping to a valuev
such thatObjects.equals(value, v)
. This operation will probably require time linear in the map size for most implementations of theMap
interface.- Specified by:
containsValue
in interfaceMap<String,Object>
- Parameters:
value
- value whose presence in this map is to be tested- Returns:
true
if this map maps one or more keys to the specified value
-
entrySet
public Set<Map.Entry<String,Object>> entrySet()
Description copied from interface:Map
Returns aSet
view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation, or through thesetValue
operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove
,Set.remove
,removeAll
,retainAll
andclear
operations. It does not support theadd
oraddAll
operations.
-
get
public Object get(Object key)
Description copied from interface:Bindings
Returns the value to which this map maps the specified key. Returnsnull
if the map contains no mapping for this key. A return value ofnull
does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull
. ThecontainsKey
operation may be used to distinguish these two cases.More formally, if this map contains a mapping from a key
k
to a valuev
such that(key==null ? k==null : key.equals(k))
, then this method returnsv
; otherwise it returnsnull
. (There can be at most one such mapping.)
-
isEmpty
public boolean isEmpty()
Description copied from interface:Map
Returnstrue
if this map contains no key-value mappings.
-
keySet
public Set<String> keySet()
Description copied from interface:JSObject
Returns the set of all property names of this object.
-
put
public Object put(String key, Object value)
Description copied from interface:Bindings
Set a named value.- Specified by:
put
in interfaceBindings
- Specified by:
put
in interfaceMap<String,Object>
- Parameters:
key
- The name associated with the value.value
- The value associated with the name.- Returns:
- The value previously associated with the given name. Returns null if no value was previously associated with the name.
-
putAll
public void putAll(Map<? extends String,? extends Object> map)
Description copied from interface:Bindings
Adds all the mappings in a givenMap
to thisBindings
.
-
remove
public Object remove(Object key)
Description copied from interface:Bindings
Removes the mapping for this key from this map if it is present (optional operation). More formally, if this map contains a mapping from keyk
to valuev
such that(key==null ? k==null : key.equals(k))
, that mapping is removed. (The map can contain at most one such mapping.)Returns the value to which the map previously associated the key, or
null
if the map contained no mapping for this key. (Anull
return can also indicate that the map previously associatednull
with the specified key if the implementation supportsnull
values.) The map will not contain a mapping for the specified key once the call returns.
-
delete
public boolean delete(Object key)
Delete a property from this object.- Parameters:
key
- the property to be deleted- Returns:
- if the delete was successful or not
-
size
public int size()
Description copied from interface:Map
Returns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
.
-
values
public Collection<Object> values()
Description copied from interface:JSObject
Returns the set of all property values of this object.
-
getProto
public Object getProto()
Return the __proto__ of this object.- Returns:
- __proto__ object.
-
setProto
public void setProto(Object proto)
Set the __proto__ of this object.- Parameters:
proto
- new proto for this object
-
getOwnPropertyDescriptor
public Object getOwnPropertyDescriptor(String key)
ECMA 8.12.1 [[GetOwnProperty]] (P)- Parameters:
key
- property key- Returns:
- Returns the Property Descriptor of the named own property of this object, or undefined if absent.
-
getOwnKeys
public String[] getOwnKeys(boolean all)
return an array of own property keys associated with the object.- Parameters:
all
- True if to include non-enumerable keys.- Returns:
- Array of keys.
-
preventExtensions
public ScriptObjectMirror preventExtensions()
Flag this script object as non extensible- Returns:
- the object after being made non extensible
-
isExtensible
public boolean isExtensible()
Check if this script object is extensible- Returns:
- true if extensible
-
seal
public ScriptObjectMirror seal()
ECMAScript 15.2.3.8 - seal implementation- Returns:
- the sealed script object
-
isSealed
public boolean isSealed()
Check whether this script object is sealed- Returns:
- true if sealed
-
freeze
public ScriptObjectMirror freeze()
ECMA 15.2.39 - freeze implementation. Freeze this script object- Returns:
- the frozen script object
-
isFrozen
public boolean isFrozen()
Check whether this script object is frozen- Returns:
- true if frozen
-
isUndefined
public static boolean isUndefined(Object obj)
Utility to check if given object is ECMAScript undefined value- Parameters:
obj
- object to check- Returns:
- true if 'obj' is ECMAScript undefined value
-
to
public <T> T to(Class<T> type)
Utility to convert this script object to the given type.- Type Parameters:
T
- destination type to convert to- Parameters:
type
- destination type to convert to- Returns:
- converted object
-
wrap
public static Object wrap(Object obj, Object homeGlobal)
Make a script object mirror on given object if needed.- Parameters:
obj
- object to be wrapped/convertedhomeGlobal
- global to which this object belongs.- Returns:
- wrapped/converted object
-
wrapAsJSONCompatible
public static Object wrapAsJSONCompatible(Object obj, Object homeGlobal)
Make a script object mirror on given object if needed. The created wrapper will implement the JavaList
interface ifobj
is a JavaScriptArray
object; this is compatible with Java JSON libraries expectations. Arrays retrieved through its properties (transitively) will also implement the list interface.- Parameters:
obj
- object to be wrapped/convertedhomeGlobal
- global to which this object belongs.- Returns:
- wrapped/converted object
-
unwrap
public static Object unwrap(Object obj, Object homeGlobal)
Unwrap a script object mirror if needed.- Parameters:
obj
- object to be unwrappedhomeGlobal
- global to which this object belongs- Returns:
- unwrapped object
-
wrapArray
public static Object[] wrapArray(Object[] args, Object homeGlobal)
Wrap an array of object to script object mirrors if needed.- Parameters:
args
- array to be unwrappedhomeGlobal
- global to which this object belongs- Returns:
- wrapped array
-
unwrapArray
public static Object[] unwrapArray(Object[] args, Object homeGlobal)
Unwrap an array of script object mirrors if needed.- Parameters:
args
- array to be unwrappedhomeGlobal
- global to which this object belongs- Returns:
- unwrapped array
-
identical
public static boolean identical(Object obj1, Object obj2)
Are the given objects mirrors to same underlying object?- Parameters:
obj1
- first objectobj2
- second object- Returns:
- true if obj1 and obj2 are identical script objects or mirrors of it.
-
toNumber
@Deprecated public double toNumber()
Deprecated.Description copied from class:AbstractJSObject
Returns this object's numeric value.- Specified by:
toNumber
in interfaceJSObject
- Overrides:
toNumber
in classAbstractJSObject
- Returns:
- this object's numeric value.
-
getDefaultValue
public Object getDefaultValue(Class<?> hint)
Description copied from interface:JSObject
Implements this object's[[DefaultValue]]
method as per ECMAScript 5.1 section 8.6.2.- Specified by:
getDefaultValue
in interfaceJSObject
- Parameters:
hint
- the type hint. Should be eithernull
,Number.class
orString.class
.- Returns:
- this object's default value.
-
-