public class JSObject extends JSValue
IllegalStateException
.
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
asJavaObject()
Casts the current JavaScript object to
将当前的JavaScript对象转换为java.lang.Object类型。 java.lang.Object type.
|
JSObject |
asObject()
Casts the current JavaScript object to
将当前的JavaScript对象转换为JSObject类型。 JSObject type.
|
JSContext |
getContext()
Returns JavaScript execution context associated with the current JavaScript object.
返回与当前JavaScript对象关联的JavaScript执行上下文。 |
java.util.List<java.lang.String> |
getOwnPropertyNames()
Returns a list containing the names of the properties of this object, excluding properties from prototype objects.
返回一个列表,其中包含此对象的属性名称,但原型对象中的属性除外。 |
JSValue |
getProperty(java.lang.String name)
Returns value of specified JavaScript object's property with the given
返回具有给定名称的指定JavaScript对象的属性的值。 name .
|
java.util.List<java.lang.String> |
getPropertyNames()
Returns a list containing the names of the properties of this object, including properties from prototype objects.
返回一个列表,其中包含该对象的属性名称,包括原型对象的属性。 |
boolean |
hasProperty(java.lang.String name)
Checks whether JavaScript object has property or function with the given
检查JavaScript对象是否具有具有给定名称的属性或函数。 name .
|
boolean |
isJavaObject()
Indicates whether JavaScript value is a Java object.
指示JavaScript值是否为Java对象。 |
boolean |
isObject()
Indicates whether JavaScript value is an object.
指示JavaScript值是否为对象。 |
boolean |
removeProperty(java.lang.String name)
Removes property with the given
在当前JavaScript对象中删除具有给定名称的属性,如果成功删除该属性,则返回true。 name in the current JavaScript object and returns
true if the property was successfully removed.
|
boolean |
setProperty(int index, java.lang.Object value)
Sets a new property with the given
使用给定索引设置一个新属性,或修改当前JavaScript对象中现有的索引,如果具有给定索引的属性已成功创建或更新,则返回true。 index or modifies existing one in the current JavaScript object and returns
true if the property with the given
index was created or updated successfully.
|
boolean |
setProperty(java.lang.String name, java.lang.Object value)
Sets a new property with the given
使用给定名称设置新属性或修改当前JavaScript对象中的现有属性,如果具有给定名称的属性已成功创建或更新,则返回true。 name or modifies existing one in the current JavaScript object and returns
true if the property with the given
name was created or updated successfully.
|
java.lang.String |
toJSONString()
Returns text representation of JavaScript object.
返回JavaScript对象的文本表示形式。 |
java.lang.String |
toString() |
asArray, asBoolean, asBooleanObject, asFunction, asNumber, asNumberObject, asString, asStringObject, getBooleanValue, getNumberValue, getStringValue, isArray, isBoolean, isBooleanObject, isFunction, isNull, isNumber, isNumberObject, isString, isStringObject, isUndefined
public java.util.List<java.lang.String> getPropertyNames()
java.lang.IllegalStateException
- when object is already disposed or invalid.
public java.util.List<java.lang.String> getOwnPropertyNames()
java.lang.IllegalStateException
- when object is already disposed or invalid.
public boolean hasProperty(java.lang.String name)
name
.
name
- string that represents name of the property or function. Cannot be
null
or empty.
-表示属性或函数名称的字符串。不能为空。
true
if object has property with given
name
.
如果对象具有给定的属性。
java.lang.IllegalArgumentException
- when
name
is null or empty.
java.lang.IllegalStateException
- when object is already disposed or invalid.
public JSValue getProperty(java.lang.String name)
name
. The
name
parameter represents name of the current JavaScript object property or function.
name
- string that represents name of the property or function. Cannot be
null
or empty.
-表示属性或函数名称的字符串。不能为空。
name
. If object doesn't have this key, the return value represent 'undefined' value. See
JSValue.isUndefined()
.
具有给定的JavaScript对象属性的值。如果对象没有此键,则返回值表示“未定义”值。请参阅。
java.lang.IllegalArgumentException
- when
name
is null or empty.
java.lang.IllegalStateException
- when object is already disposed or invalid.
public boolean setProperty(java.lang.String name, java.lang.Object value)
name
or modifies existing one in the current JavaScript object and returns
true
if the property with the given
name
was created or updated successfully.
The name
parameter represents JavaScript object's property name. Via the property name you can access its value
. The value
can be one of the following types: String, Boolean, Integer, Long, Short, Byte, Double, Float, Object[], int, boolean, long, short, byte, double, float, Object, JSONString, JSFunctionCallback.
As a property value you can set an instance of java.lang.Object
type. In this case the Java object will be automatically converted/wrapped into JavaScript object. You can access and invoke all Java object's public methods and fields (including the inherited ones) directly from JavaScript code.
Important security note: injecting Java objects is a powerful feature that might present a security risk for your application. JavaScript code can access public fields and methods of the injected Java object including Java Reflection API (e.g. Object.getClass()
method). An untrusted JavaScript code on the loaded web page could allow an attacker to execute any Java code with permissions of Java process. For example, if you inject File
object into JavaScript code, JavaScript will get access to the local file system.
name
- string that represents name of the property. Cannot be
null
or empty.
-代表属性名称的字符串。不能为空。
value
- a new value associated with the property with the given
name
. Cannot be
null
or
JSObject
with a different JavaScript context.
-与具有给定的属性相关联的新值。不能为或具有其他JavaScript上下文。
true
when property with
name
was created or updated successfully.
创建或更新属性成功的时间。
java.lang.IllegalArgumentException
- when
name
is null or empty.
java.lang.IllegalArgumentException
- when
value
is null or represents
JSObject
with a different JavaScript context.
java.lang.IllegalStateException
- when object is already disposed or invalid.
public boolean setProperty(int index, java.lang.Object value)
index
or modifies existing one in the current JavaScript object and returns
true
if the property with the given
index
was created or updated successfully.
The index
parameter represents JavaScript object's property index. Via the property index you can access its value
. The value
can be one of the following types: String, Boolean, Integer, Long, Short, Byte, Double, Float, Object[], int, boolean, long, short, byte, double, float, Object, JSONString, JSFunctionCallback.
As a property value you can set an instance of java.lang.Object
type. In this case the Java object will be automatically converted/wrapped into JavaScript object. You can call Java object's public methods directly from JavaScript code.
index
- int that represents index of the property.
-表示属性索引的int。
value
- a new value associated with the property with the given
index
. Cannot be
null
or
JSObject
with a different JavaScript context.
-与具有给定的属性相关联的新值。不能为或具有其他JavaScript上下文。
true
when property with
index
was created or updated successfully.
创建或更新属性成功的时间。
java.lang.IllegalArgumentException
- when
index
is negative.
java.lang.IllegalArgumentException
- when
value
is null or represents
JSObject
with a different JavaScript context.
java.lang.IllegalStateException
- when object is already disposed or invalid.
public boolean removeProperty(java.lang.String name)
name
in the current JavaScript object and returns
true
if the property was successfully removed. Once you remove key, it will not be available in the current JavaScript object anymore.
name
- string that represents name of the property or function. Cannot be
null
or empty.
-表示属性或函数名称的字符串。不能为空。
true
if the property was successfully removed.
如果该属性已成功删除。
java.lang.IllegalArgumentException
- when
name
is null or empty.
java.lang.IllegalStateException
- when object is already disposed or invalid.
public JSContext getContext()
public java.lang.String toJSONString()
java.lang.IllegalStateException
- when object has circular fields aka 'obj.field = obj'
java.lang.IllegalStateException
- when object has been already disposed
public boolean isObject()
JSValue
true
, then the value can be casted to
JSObject
type. For example:
if (value.isObject()) { JSObject object = value.asObject(); }
public boolean isJavaObject()
JSValue
true
, then the value can be casted to
Object
type. For example:
if (value.isJavaObject()) { Object object = value.asJavaObject(); }
isJavaObject
in class
JSValue
true
when JavaScript value is an object.
当JavaScript值是一个对象时。
public JSObject asObject()
JSValue
JSObject
type. If the current object doesn't represent an object (e.g. it's a primitive value), the
IllegalStateException
error is thrown.
public java.lang.Object asJavaObject()
JSValue
java.lang.Object
type. If the current object doesn't represent a Java object, the
IllegalStateException
error is thrown.
asJavaObject
in class
JSValue
public java.lang.String toString()
toString
in class
java.lang.Object