有谁用过scriptable object的用法

类 IdScriptableObject
java.lang.Object
net.sourceforge.htmlunit.corejs.javascript.IdScriptableObject
所有已实现的接口:
java.io.Serializable, , , ,
直接已知子类:
, , , , , , , , , ,
public abstract class IdScriptableObject
implements
Base class for native object implementation that uses IdFunctionObject to
export its methods to script via .prototype object.
Any descendant should implement at least the following methods:
findInstanceIdInfo getInstanceIdName execIdCall methodArity
To define non-function properties, the descendant should override
getInstanceIdValue setInstanceIdValue to get/set property value and provide
its default attributes.
To customize initialization of constructor and prototype objects, descendant
may override scopeInit or fillConstructorProperties methods.
从类继承的字段&net.sourceforge.htmlunit.corejs.javascript.
从接口继承的字段&net.sourceforge.htmlunit.corejs.javascript.
构造器概要
构造器和说明
&prototype)&
限定符和类型
方法和说明
(int&maxPrototypeId)&
protected void
java.lang.Object&tag,
java.lang.String&name,
int&arity)&
protected java.lang.Object
(java.lang.String&name)&
protected void
(java.lang.String&name,
java.lang.Object&value)&
java.lang.Object&key,
Defines a property on an object.
(java.lang.String&name)
Removes a named property from the object.
java.lang.Object
java.lang.Object[]&args)
'thisObj' will be null if invoked as constructor, in which case instance
of Scriptable should be returned.
(int&maxPrototypeId,
boolean&sealed)&
protected void
protected int
(java.lang.String&name)
Map name to id of instance property.
protected int
(java.lang.String&name)&
java.lang.Object
(java.lang.String&name,
Returns the value of the named property or NOT_FOUND.
(java.lang.String&name)
Get the attributes of a named property.
protected java.lang.String
Map id back to property name it defines.
protected java.lang.Object
Get id value.
protected int
Get maximum id findInstanceIdInfo can generate.
java.lang.Object&id)&
(java.lang.String&name,
Returns true if the named property is defined.
protected static
Utility method to construct type error to indicate incompatible call when
converting script thisObj to a particular type is not possible.
protected void
(java.lang.Object&tag,
java.lang.String&name,
int&arity)&
java.lang.String&name,
java.lang.Object&value,
int&attributes)&
protected static int
(int&attributes,
(java.lang.String&name,
java.lang.Object&value)
Sets the value of the named property, creating it if need be.
(java.lang.String&name,
int&attributes)
Set the attributes of a named property.
protected void
Update the attributes of the given instance property.
protected void
java.lang.Object&value)
Set or delete id value.
从类继承的方法&net.sourceforge.htmlunit.corejs.javascript.
, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
从类继承的方法&java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
构造器详细资料
IdScriptableObject
public&IdScriptableObject()
IdScriptableObject
public&IdScriptableObject(&scope,
&prototype)
方法详细资料
defaultGet
protected final&java.lang.Object&defaultGet(java.lang.String&name)
defaultPut
protected final&void&defaultPut(java.lang.String&name,
java.lang.Object&value)
public&boolean&has(java.lang.String&name,
从类复制的说明:&
Returns true if the named property is defined.
&在接口中&
参数:name - the name of the propertystart - the object in which the lookup began
返回:true if and only if the property was found in the object另请参阅:,
public&java.lang.Object&get(java.lang.String&name,
从类复制的说明:&
Returns the value of the named property or NOT_FOUND.
If the property was created using defineProperty, the appropriate getter
method is called.
&在接口中&
参数:name - the name of the propertystart - the object in which the lookup began
返回:the value of the property (may be null), or NOT_FOUND另请参阅:
public&void&put(java.lang.String&name,
java.lang.Object&value)
从类复制的说明:&
Sets the value of the named property, creating it if need be.
If the property was created using defineProperty, the appropriate setter
method is called.
If the property's attributes include READONLY, no action is taken. This
method will actually set the property in the start object.
&在接口中&
参数:name - the name of the propertystart - the object whose property is being setvalue - value to set the property to另请参阅:,
public&void&delete(java.lang.String&name)
从类复制的说明:&
Removes a named property from the object.
If the property is not found, or it has the PERMANENT attribute, no
action is taken.
&在接口中&
参数:name - the name of the property另请参阅:,
getAttributes
public&int&getAttributes(java.lang.String&name)
从类复制的说明:&
Get the attributes of a named property.
The property is specified by name as defined for
参数:name - the identifier for the property
返回:the bitset of attributes另请参阅:,
setAttributes
public&void&setAttributes(java.lang.String&name,
int&attributes)
从类复制的说明:&
Set the attributes of a named property.
The property is specified by name as defined for
The possible attributes are READONLY, DONTENUM, and PERMANENT.
Combinations of attributes are expressed by the bitwise OR of attributes.
EMPTY is the state of no attributes set. Any unused bits are reserved for
future use.
参数:name - the name of the propertyattributes - the bitset of attributes另请参阅:,
getMaxInstanceId
protected&int&getMaxInstanceId()
Get maximum id findInstanceIdInfo can generate.
instanceIdInfo
protected static&int&instanceIdInfo(int&attributes,
findInstanceIdInfo
protected&int&findInstanceIdInfo(java.lang.String&name)
Map name to id of instance property. Should return 0 if not found or the
result of .
getInstanceIdName
protected&java.lang.String&getInstanceIdName(int&id)
Map id back to property name it defines.
getInstanceIdValue
protected&java.lang.Object&getInstanceIdValue(int&id)
Get id value. If id value is constant, descendant can call cacheIdValue
to store value in the permanent cache. Default implementation creates
IdFunctionObject instance for given id and cache its value
setInstanceIdValue
protected&void&setInstanceIdValue(int&id,
java.lang.Object&value)
Set or delete id value. If value == NOT_FOUND , the implementation should
make sure that the following getInstanceIdValue return NOT_FOUND.
setInstanceIdAttributes
protected&void&setInstanceIdAttributes(int&id,
Update the attributes of the given instance property. Classes which want
to support changing property attributes via Object.defineProperty must
override this method. The default implementation throws InternalError.
参数:id - the instance property idattr - the new attribute bitset
execIdCall
public&java.lang.Object&execIdCall(&f,
java.lang.Object[]&args)
'thisObj' will be null if invoked as constructor, in which case instance
of Scriptable should be returned.
&在接口中&
exportAsJSClass
public final&&exportAsJSClass(int&maxPrototypeId,
boolean&sealed)
hasPrototypeMap
public final&boolean&hasPrototypeMap()
activatePrototypeMap
public final&void&activatePrototypeMap(int&maxPrototypeId)
initPrototypeMethod
public final&void&initPrototypeMethod(java.lang.Object&tag,
java.lang.String&name,
int&arity)
initPrototypeConstructor
public final&void&initPrototypeConstructor(&f)
initPrototypeValue
public final&void&initPrototypeValue(int&id,
java.lang.String&name,
java.lang.Object&value,
int&attributes)
initPrototypeId
protected&void&initPrototypeId(int&id)
findPrototypeId
protected&int&findPrototypeId(java.lang.String&name)
fillConstructorProperties
protected&void&fillConstructorProperties(&ctor)
addIdFunctionProperty
protected&void&addIdFunctionProperty(&obj,
java.lang.Object&tag,
java.lang.String&name,
int&arity)
incompatibleCallError
protected static&&incompatibleCallError(&f)
Utility method to construct type error to indicate incompatible call when
converting script thisObj to a particular type is not possible. Possible
usage would be to have a private function like realThis:
private static NativeSomething realThis(Scriptable thisObj, IdFunctionObject f) {
if (!(thisObj instanceof NativeSomething))
throw incompatibleCallError(f);
return (NativeSomething) thisO
Note that although such function can be implemented universally via
java.lang.Class.isInstance(), it would be much more slower.
参数:f - function that is attempting to convert 'this' object.
返回:Scriptable object suitable for a check by the instanceof
java.lang.RuntimeException - if no more instanceof target can be found
defineOwnProperty
public&void&defineOwnProperty(&cx,
java.lang.Object&key,
从类复制的说明:&
Defines a property on an object.
参数:cx - the current Contextkey - the name/index of the propertydesc - the new property descriptor, as described in 8.6.1
getOwnPropertyDescriptor
protected&&getOwnPropertyDescriptor(&cx,
java.lang.Object&id)ScriptableObject (Rhino)
org.mozilla.javascript
Class ScriptableObject
java.lang.Object
org.mozilla.javascript.ScriptableObject
All Implemented Interfaces: java.io.Serializable, org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject,
Direct Known Subclasses: org.mozilla.javascript.IdScriptableObject
public abstract class ScriptableObjectextends java.lang.Objectimplements , java.io.Serializable, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.ConstProperties
This is the default implementation of the Scriptable interface. This
class provides convenient default behavior that makes it easier to
define host objects.
Various properties and methods of JavaScript objects can be conveniently
defined using methods of ScriptableObject.
Classes extending ScriptableObject must define the getClassName method.
Norris Boyd
See Also:,
static&int
&&&&&&&&&&&
static&int
&&&&&&&&&&Property attribute indicating property is not enumerated.
static&int
&&&&&&&&&&The empty property attribute.
static&int
&&&&&&&&&&Property attribute indicating property cannot be deleted.
static&int
&&&&&&&&&&Property attribute indicating assignment to this property is ignored.
static&int
&&&&&&&&&&Property attribute indicating that this is a const property that has not
been assigned yet.
&&&&&&&&&&&
&prototype)
&&&&&&&&&&&
&java.lang.Object
(java.lang.Object&key,
java.lang.Object&value)
&&&&&&&&&&Associate arbitrary application-specific value with this object.
&&&&&&&&&&Emulate the SpiderMonkey (and Firefox) feature of allowing
custom objects to avoid detection by normal "object detection"
code patterns.
static&java.lang.Object
java.lang.String&methodName,
java.lang.Object[]&args)
&&&&&&&&&&Call a method of an object.
static&java.lang.Object
java.lang.String&methodName,
java.lang.Object[]&args)
&&&&&&&&&&Call a method of an object.
static&void
java.lang.Class&clazz)
&&&&&&&&&&Defines JavaScript objects from a Java class that implements Scriptable.
static&void
java.lang.Class&clazz,
boolean&sealed)
&&&&&&&&&&Defines JavaScript objects from a Java class, optionally
allowing sealing.
static&java.lang.String
java.lang.Class&clazz,
boolean&sealed,
boolean&mapInheritance)
&&&&&&&&&&Defines JavaScript objects from a Java class, optionally
allowing sealing and mapping of Java inheritance to JavaScript
prototype-based inheritance.
(java.lang.String&name,
&&&&&&&&&&Reserves a definition spot for a const.
static&void
(&destination,
java.lang.String&propertyName)
&&&&&&&&&&Utility method to add properties to arbitrary Scriptable object.
(java.lang.String[]&names,
java.lang.Class&clazz,
int&attributes)
&&&&&&&&&&Search for names in a class, adding the resulting methods
as properties.
static&void
(&destination,
java.lang.String&propertyName,
java.lang.Object&value,
int&attributes)
&&&&&&&&&&Utility method to add properties to arbitrary Scriptable object.
(java.lang.String&propertyName,
java.lang.Class&clazz,
int&attributes)
&&&&&&&&&&Define a JavaScript property with getter and setter side effects.
(java.lang.String&propertyName,
java.lang.Object&value,
int&attributes)
&&&&&&&&&&Define a JavaScript property.
(java.lang.String&propertyName,
java.lang.Object&delegateTo,
java.lang.reflect.Method&getter,
java.lang.reflect.Method&setter,
int&attributes)
&&&&&&&&&&Define a JavaScript property.
(int&index)
&&&&&&&&&&Removes the indexed property from the object.
(java.lang.String&name)
&&&&&&&&&&Removes a named property from the object.
static&boolean
int&index)
&&&&&&&&&&Removes the property from an object or its prototype chain.
static&boolean
java.lang.String&name)
&&&&&&&&&&Removes the property from an object or its prototype chain.
protected &java.lang.Object
(java.lang.Object&value)
&&&&&&&&&&Custom == operator.
&java.lang.Object
(int&index,
&&&&&&&&&&Returns the value of the indexed property or NOT_FOUND.
&java.lang.Object
(java.lang.String&name,
&&&&&&&&&&Returns the value of the named property or NOT_FOUND.
&java.lang.Object[]
&&&&&&&&&&Returns an array of ids for the properties of the object.
&java.lang.Object
(java.lang.Object&key)
&&&&&&&&&&Get arbitrary application-specific value associated with this object.
(int&index)
&&&&&&&&&&Get the attributes of an indexed property.
(int&index,
&&&&&&&&&&Deprecated.&Use . The engine always
ignored the start argument.
(java.lang.String&name)
&&&&&&&&&&Get the attributes of a named property.
(java.lang.String&name,
&&&&&&&&&&Deprecated.&Use . The engine always
ignored the start argument.
abstract &java.lang.String
&&&&&&&&&&Return the name of the class.
java.lang.String&className)
&&&&&&&&&&Get the prototype for the named class.
&java.lang.Object
(java.lang.Class&typeHint)
&&&&&&&&&&Implements the [[DefaultValue]] internal method.
static&java.lang.Object
java.lang.Class&typeHint)
&&&&&&&&&&&
&&&&&&&&&&Get the Function.prototype property.
&java.lang.Object
(java.lang.String&name,
int&index,
boolean&isSetter)
&&&&&&&&&&Get the getter or setter for a given property.
&java.lang.Object[]
&&&&&&&&&&Returns an array of ids for the properties of the object.
&&&&&&&&&&Get the Object.prototype property.
&&&&&&&&&&Returns the parent (enclosing) scope of the object.
static&java.lang.Object
int&index)
&&&&&&&&&&Gets an indexed property from an object or any object in its prototype chain.
static&java.lang.Object
java.lang.String&name)
&&&&&&&&&&Gets a named property from an object or any object in its prototype chain.
static&java.lang.Object[]
&&&&&&&&&&Returns an array of all ids from an object and its prototypes.
&&&&&&&&&&Returns the prototype of the object.
&&&&&&&&&&Get the global scope.
static&java.lang.Object
java.lang.Object&key)
&&&&&&&&&&Get arbitrary application-specific value associated with the top scope
of the given scope.
(int&index,
&&&&&&&&&&Returns true if the property index is defined.
(java.lang.String&name,
&&&&&&&&&&Returns true if the named property is defined.
(&instance)
&&&&&&&&&&Implements the instanceof operator.
static&boolean
int&index)
&&&&&&&&&&Returns whether an indexed property is defined in an object or any object
in its prototype chain.
static&boolean
java.lang.String&name)
&&&&&&&&&&Returns whether a named property is defined in an object or any object
in its prototype chain.
(java.lang.String&name)
&&&&&&&&&&Returns true if the named property is defined as a const on this object.
protected &boolean
(java.lang.String&name,
int&index,
boolean&setter)
&&&&&&&&&&Returns whether a property is a getter or a setter
&&&&&&&&&&Return true if this object is sealed.
(int&index,
java.lang.Object&value)
&&&&&&&&&&Sets the value of the indexed property, creating it if need be.
(java.lang.String&name,
java.lang.Object&value)
&&&&&&&&&&Sets the value of the named property, creating it if need be.
(java.lang.String&name,
java.lang.Object&value)
&&&&&&&&&&Sets the value of the named const property, creating it if need be.
static&void
java.lang.String&name,
java.lang.Object&value)
&&&&&&&&&&Puts a named property in an object or in an object in its prototype chain.
static&void
int&index,
java.lang.Object&value)
&&&&&&&&&&Puts an indexed property in an object or in an object in its prototype chain.
static&void
java.lang.String&name,
java.lang.Object&value)
&&&&&&&&&&Puts a named property in an object or in an object in its prototype chain.
static&void
java.lang.String&name,
boolean&isConst)
&&&&&&&&&&If hasProperty(obj, name) would return true, then if the property that
was found is compatible with the new property, this method just returns.
&&&&&&&&&&Seal this object.
(int&index,
int&attributes)
&&&&&&&&&&Set the attributes of an indexed property.
(int&index,
int&attributes)
&&&&&&&&&&Deprecated.&Use .
The engine always ignored the start argument.
(java.lang.String&name,
int&attributes)
&&&&&&&&&&Set the attributes of a named property.
(java.lang.String&name,
int&attributes)
&&&&&&&&&&Deprecated.&Use .
The engine always ignored the start argument.
(java.lang.String&name,
int&index,
&getterOrSeter,
boolean&isSetter)
&&&&&&&&&&XXX: write docs.
&&&&&&&&&&Sets the parent (enclosing) scope of the object.
&&&&&&&&&&Sets the prototype of the object.
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public static final int EMPTY
The empty property attribute.
Used by getAttributes() and setAttributes().
See Also:,
public static final int READONLY
Property attribute indicating assignment to this property is ignored.
See Also:,
public static final int DONTENUM
Property attribute indicating property is not enumerated.
Only enumerated properties will be returned by getIds().
See Also:,
public static final int PERMANENT
Property attribute indicating property cannot be deleted.
See Also:,
UNINITIALIZED_CONST
public static final int UNINITIALIZED_CONST
Property attribute indicating that this is a const property that has not
been assigned yet.
The first 'const' assignment to the property will
clear this bit.
public static final int CONST
ScriptableObject
public ScriptableObject()
ScriptableObject
public ScriptableObject(&scope,
&prototype)
getClassName
public abstract java.lang.String getClassName()
Return the name of the class.
This is typically the same name as the constructor.
Classes extending ScriptableObject must implement this abstract
Specified by: in interface
public boolean has(java.lang.String&name,
Returns true if the named property is defined.
Specified by: in interface
Parameters:name - the name of the propertystart - the object in which the lookup began
Returns:true if and only if the property was found in the objectSee Also:,
public boolean has(int&index,
Returns true if the property index is defined.
Specified by: in interface
Parameters:index - the numeric index for the propertystart - the object in which the lookup began
Returns:true if and only if the property was found in the objectSee Also:,
public java.lang.Object get(java.lang.String&name,
Returns the value of the named property or NOT_FOUND.
If the property was created using defineProperty, the
appropriate getter method is called.
Specified by: in interface
Parameters:name - the name of the propertystart - the object in which the lookup began
Returns:the value of the property (may be null), or NOT_FOUNDSee Also:
public java.lang.Object get(int&index,
Returns the value of the indexed property or NOT_FOUND.
Specified by: in interface
Parameters:index - the numeric index for the propertystart - the object in which the lookup began
Returns:the value of the property (may be null), or NOT_FOUNDSee Also:
public void put(java.lang.String&name,
java.lang.Object&value)
Sets the value of the named property, creating it if need be.
If the property was created using defineProperty, the
appropriate setter method is called.
If the property's attributes include READONLY, no action is
This method will actually set the property in the start
Specified by: in interface
Parameters:name - the name of the propertystart - the object whose property is being setvalue - value to set the property toSee Also:,
public void put(int&index,
java.lang.Object&value)
Sets the value of the indexed property, creating it if need be.
Specified by: in interface
Parameters:index - the numeric index for the propertystart - the object whose property is being setvalue - value to set the property toSee Also:,
public void delete(java.lang.String&name)
Removes a named property from the object.
If the property is not found, or it has the PERMANENT attribute,
no action is taken.
Specified by: in interface
Parameters:name - the name of the propertySee Also:,
public void delete(int&index)
Removes the indexed property from the object.
If the property is not found, or it has the PERMANENT attribute,
no action is taken.
Specified by: in interface
Parameters:index - the numeric index for the propertySee Also:,
public void putConst(java.lang.String&name,
java.lang.Object&value)
Sets the value of the named const property, creating it if need be.
If the property was created using defineProperty, the
appropriate setter method is called.
If the property's attributes include READONLY, no action is
This method will actually set the property in the start
Specified by:putConst in interface org.mozilla.javascript.ConstProperties
Parameters:name - the name of the propertystart - the object whose property is being setvalue - value to set the property toSee Also:,
defineConst
public void defineConst(java.lang.String&name,
Description copied from interface: org.mozilla.javascript.ConstProperties
Reserves a definition spot for a const.
This will set up a definition
of the const property, but set its value to undefined.
The semantics of
the start parameter is the same as for putConst.
Specified by:defineConst in interface org.mozilla.javascript.ConstProperties
Parameters:name - The name of the property.start - The object whose property is being reserved.
public boolean isConst(java.lang.String&name)
Returns true if the named property is defined as a const on this object.
Specified by:isConst in interface org.mozilla.javascript.ConstProperties
Parameters:name -
Returns:true if the named property is defined as a const, false
otherwise.
getAttributes
public final int getAttributes(java.lang.String&name,
Deprecated.&Use . The engine always
ignored the start argument.
getAttributes
public final int getAttributes(int&index,
Deprecated.&Use . The engine always
ignored the start argument.
setAttributes
public final void setAttributes(java.lang.String&name,
int&attributes)
Deprecated.&Use .
The engine always ignored the start argument.
setAttributes
public void setAttributes(int&index,
int&attributes)
Deprecated.&Use .
The engine always ignored the start argument.
getAttributes
public int getAttributes(java.lang.String&name)
Get the attributes of a named property.
The property is specified by name
as defined for has.
Parameters:name - the identifier for the property
Returns:the bitset of attributes
- if the named property is not foundSee Also:,
getAttributes
public int getAttributes(int&index)
Get the attributes of an indexed property.
Parameters:index - the numeric index for the property
Returns:the bitset of attributes
- if the named property is not found
is not foundSee Also:,
setAttributes
public void setAttributes(java.lang.String&name,
int&attributes)
Set the attributes of a named property.
The property is specified by name
as defined for has.
The possible attributes are READONLY, DONTENUM,
and PERMANENT. Combinations of attributes
are expressed by the bitwise OR of attributes.
EMPTY is the state of no attributes set. Any unused
bits are reserved for future use.
Parameters:name - the name of the propertyattributes - the bitset of attributes
- if the named property is not foundSee Also:,
setAttributes
public void setAttributes(int&index,
int&attributes)
Set the attributes of an indexed property.
Parameters:index - the numeric index for the propertyattributes - the bitset of attributes
- if the named property is not foundSee Also:,
setGetterOrSetter
public void setGetterOrSetter(java.lang.String&name,
int&index,
&getterOrSeter,
boolean&isSetter)
XXX: write docs.
getGetterOrSetter
public java.lang.Object getGetterOrSetter(java.lang.String&name,
int&index,
boolean&isSetter)
Get the getter or setter for a given property. Used by __lookupGetter__
and __lookupSetter__.
Parameters:name - Name of the object. If nonnull, index must be 0.index - Index of the object. If nonzero, name must be null.isSetter - If true, return the setter, otherwise return the getter.
Returns:Null if the property does not exist. Otherwise returns either
the getter or the setter for the property, depending on
the value of isSetter (may be undefined if unset).
java.lang.IllegalArgumentException - if both name and index are nonnull
and nonzero respectively.
isGetterOrSetter
protected boolean isGetterOrSetter(java.lang.String&name,
int&index,
boolean&setter)
Returns whether a property is a getter or a setter
Parameters:name - property nameindex - property indexsetter - true to check for a setter, false for a getter
Returns:whether the property is a getter or a setter
getPrototype
getPrototype()
Returns the prototype of the object.
Specified by: in interface
Returns:the prototype
setPrototype
public void setPrototype(&m)
Sets the prototype of the object.
Specified by: in interface
Parameters:m - the prototype to set
getParentScope
getParentScope()
Returns the parent (enclosing) scope of the object.
Specified by: in interface
Returns:the parent scope
setParentScope
public void setParentScope(&m)
Sets the parent (enclosing) scope of the object.
Specified by: in interface
Parameters:m - the parent scope to set
public java.lang.Object[] getIds()
Returns an array of ids for the properties of the object.
Any properties with the attribute DONTENUM are not listed.
Specified by: in interface
Returns:an array of java.lang.Objects with an entry for every
listed property. Properties accessed via an integer index will
have a corresponding
Integer entry in the returned array. Properties accessed by
a String will have a String entry in the returned array.
public java.lang.Object[] getAllIds()
Returns an array of ids for the properties of the object.
All properties, even those with attribute DONTENUM, are listed.
Specified by:getAllIds in interface org.mozilla.javascript.debug.DebuggableObject
Returns:an array of java.lang.Objects with an entry for every
listed property. Properties accessed via an integer index will
have a corresponding
Integer entry in the returned array. Properties accessed by
a String will have a String entry in the returned array.
getDefaultValue
public java.lang.Object getDefaultValue(java.lang.Class&typeHint)
Implements the [[DefaultValue]] internal method.
Note that the toPrimitive conversion is a no-op for
every type other than Object, for which [[DefaultValue]]
is called. See ECMA 9.1.
A hint of null means "no hint".
Specified by: in interface
Parameters:typeHint - the type hint
Returns:the default value for the object
See ECMA 8.6.2.6.
getDefaultValue
public static java.lang.Object getDefaultValue(&object,
java.lang.Class&typeHint)
hasInstance
public boolean hasInstance(&instance)
Implements the instanceof operator.
This operator has been proposed to ECMA.
Specified by: in interface
Parameters:instance - The value that appeared on the LHS of the instanceof
Returns:true if "this" appears in value's prototype chain
avoidObjectDetection
public boolean avoidObjectDetection()
Emulate the SpiderMonkey (and Firefox) feature of allowing
custom objects to avoid detection by normal "object detection"
code patterns. This is used to implement document.all.
See https://bugzilla.mozilla.org/show_bug.cgi?id=412247.
This is an analog to JOF_DETECTING from SpiderM see
https://bugzilla.mozilla.org/show_bug.cgi?id=248549.
Other than this special case, embeddings should return false.
Returns:true if this object should avoid object detectionSince:
equivalentValues
protected java.lang.Object equivalentValues(java.lang.Object&value)
Custom == operator.
Must return
if this object does not
have custom equality operator for the given value,
Boolean.TRUE if this object is equivalent to value,
Boolean.FALSE if this object is not equivalent to
The default implementation returns Boolean.TRUE
if this == value or
otherwise.
It indicates that by default custom equality is available only if
value is this in which case true is returned.
defineClass
public static void defineClass(&scope,
java.lang.Class&clazz)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.reflect.InvocationTargetException
Defines JavaScript objects from a Java class that implements Scriptable.
If the given class has a method
static void init(Context cx, Scriptable scope, boolean sealed);
or its compatibility form
static void init(Scriptable scope);
then it is invoked and no further initialization is done.
However, if no such a method is found, then the class's constructors and
methods are used to initialize a class in the following manner.
First, the zero-parameter constructor of the class is called to
create the prototype. If no such constructor exists,
is thrown.
Next, all methods are scanned for special prefixes that indicate that they
have special meaning for defining JavaScript objects.
These special prefixes are
jsFunction_ for a JavaScript function
jsStaticFunction_ for a JavaScript function that
is a property of the constructor
jsGet_ for a getter of a JavaScript property
jsSet_ for a setter of a JavaScript property
jsConstructor for a JavaScript function that
is the constructor
If the method's name begins with "jsFunction_", a JavaScript function
is created with a name formed from the rest of the Java method name
following "jsFunction_". So a Java method named "jsFunction_foo" will
define a JavaScript method "foo". Calling this JavaScript function
will cause the Java method to be called. The parameters of the method
must be of number and types as defined by the FunctionObject class.
The JavaScript function is then added as a property
of the prototype.
If the method's name begins with "jsStaticFunction_", it is handled
similarly except that the resulting JavaScript function is added as a
property of the constructor object. The Java method must be static.
If the method's name begins with "jsGet_" or "jsSet_", the method is
considered to define a property. Accesses to the defined property
will result in calls to these getter and setter methods. If no
setter is defined, the property is defined as READONLY.
If the method's name is "jsConstructor", the method is
considered to define the body of the constructor. Only one
method of this name may be defined.
If no method is found that can serve as constructor, a Java
constructor will be selected to serve as the JavaScript
constructor in the following manner. If the class has only one
Java constructor, that constructor is used to define
the JavaScript constructor. If the the class has two constructors,
one must be the zero-argument constructor (otherwise an
would have already been thrown
when the prototype was to be created). In this case
the Java constructor with one or more parameters will be used
to define the JavaScript constructor. If the class has three
or more constructors, an
will be thrown.
Finally, if there is a method
static void finishInit(Scriptable scope, FunctionObject constructor,
Scriptable prototype)
it will be called to finish any initialization. The scope
argument will be passed, along with the newly created constructor and
the newly created prototype.
Parameters:scope - The scope in which to define the constructor.clazz - The Java class to use to define the JavaScript objects
and properties.
java.lang.IllegalAccessException - if access is not available
to a reflected class member
java.lang.InstantiationException - if unable to instantiate
the named class
java.lang.reflect.InvocationTargetException - if an exception is thrown
during execution of methods of the named classSee Also:,
defineClass
public static void defineClass(&scope,
java.lang.Class&clazz,
boolean&sealed)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.reflect.InvocationTargetException
Defines JavaScript objects from a Java class, optionally
allowing sealing.
Similar to defineClass(Scriptable scope, Class clazz)
except that sealing is allowed. An object that is sealed cannot have
properties added or removed. Note that sealing is not allowed in
the current ECMA/ISO language specification, but is likely for
the next version.
Parameters:scope - The scope in which to define the constructor.clazz - The Java class to use to define the JavaScript objects
and properties. The class must implement Scriptable.sealed - Whether or not to create sealed standard objects that
cannot be modified.
java.lang.IllegalAccessException - if access is not available
to a reflected class member
java.lang.InstantiationException - if unable to instantiate
the named class
java.lang.reflect.InvocationTargetException - if an exception is thrown
during execution of methods of the named classSince:
defineClass
public static java.lang.String defineClass(&scope,
java.lang.Class&clazz,
boolean&sealed,
boolean&mapInheritance)
throws java.lang.IllegalAccessException,
java.lang.InstantiationException,
java.lang.reflect.InvocationTargetException
Defines JavaScript objects from a Java class, optionally
allowing sealing and mapping of Java inheritance to JavaScript
prototype-based inheritance.
Similar to defineClass(Scriptable scope, Class clazz)
except that sealing and inheritance mapping are allowed. An object
that is sealed cannot have properties added or removed. Note that
sealing is not allowed in the current ECMA/ISO language specification,
but is likely for the next version.
Parameters:scope - The scope in which to define the constructor.clazz - The Java class to use to define the JavaScript objects
and properties. The class must implement Scriptable.sealed - Whether or not to create sealed standard objects that
cannot be modified.mapInheritance - Whether or not to map Java inheritance to
JavaScript prototype-based inheritance.
Returns:the class name for the prototype of the specified class
java.lang.IllegalAccessException - if access is not available
to a reflected class member
java.lang.InstantiationException - if unable to instantiate
the named class
java.lang.reflect.InvocationTargetException - if an exception is thrown
during execution of methods of the named classSince:
defineProperty
public void defineProperty(java.lang.String&propertyName,
java.lang.Object&value,
int&attributes)
Define a JavaScript property.
Creates the property with an initial value and sets its attributes.
Parameters:propertyName - the name of the property to define.value - the initial value of the propertyattributes - the attributes of the JavaScript propertySee Also:
defineProperty
public static void defineProperty(&destination,
java.lang.String&propertyName,
java.lang.Object&value,
int&attributes)
Utility method to add properties to arbitrary Scriptable object.
If destination is instance of ScriptableObject, calls
defineProperty there, otherwise calls put in destination
ignoring attributes
defineConstProperty
public static void defineConstProperty(&destination,
java.lang.String&propertyName)
Utility method to add properties to arbitrary Scriptable object.
If destination is instance of ScriptableObject, calls
defineProperty there, otherwise calls put in destination
ignoring attributes
defineProperty
public void defineProperty(java.lang.String&propertyName,
java.lang.Class&clazz,
int&attributes)
Define a JavaScript property with getter and setter side effects.
If the setter is not found, the attribute READONLY is added to
the given attributes.
The getter must be a method with zero parameters, and the setter, if
found, must be a method with one parameter.
Parameters:propertyName - the name of the property to define. This name
also affects the name of the setter and getter
to search for. If the propertyId is "foo", then
clazz will be searched for "getFoo"
and "setFoo" methods.clazz - the Java class to search for the getter and setterattributes - the attributes of the JavaScript propertySee Also:
defineProperty
public void defineProperty(java.lang.String&propertyName,
java.lang.Object&delegateTo,
java.lang.reflect.Method&getter,
java.lang.reflect.Method&setter,
int&attributes)
Define a JavaScript property.
Use this method only if you wish to define getters and setters for
a given property in a ScriptableObject. To create a property without
special getter or setter side effects, use
defineProperty(String,int).
If setter is null, the attribute READONLY is added to
the given attributes.
Several forms of getters or setters are allowed. In all cases the
type of the value parameter can be any one of the following types:
Object, String, boolean, Scriptable, byte, short, int, long, float,
or double. The runtime will perform appropriate conversions based
upon the type of the parameter (see description in FunctionObject).
The first forms are nonstatic methods of the class referred to
by 'this':
Object getFoo();
void setFoo(SomeType value);
Next are static methods that the object whose
property is being accessed is passed in as an extra argument:
static Object getFoo(Scriptable obj);
static void setFoo(Scriptable obj, SomeType value);
Finally, it is possible to delegate to another object entirely using
the delegateTo parameter. In this case the methods are
nonstatic methods of the class delegated to, and the object whose
property is being accessed is passed in as an extra argument:
Object getFoo(Scriptable obj);
void setFoo(Scriptable obj, SomeType value);
Parameters:propertyName - the name of the property to define.delegateTo - an object to call the getter and setter methods on,
or null, depending on the form used above.getter - the method to invoke to get the value of the propertysetter - the method to invoke to set the value of the propertyattributes - the attributes of the JavaScript property
defineFunctionProperties
public void defineFunctionProperties(java.lang.String[]&names,
java.lang.Class&clazz,
int&attributes)
Search for names in a class, adding the resulting methods
as properties.
Uses reflection to find the methods of the given names. Then
FunctionObjects are constructed from the methods found, and
are added to this object as properties with the given names.
Parameters:names - the names of the Methods to add as function propertiesclazz - the class to search for the Methodsattributes - the attributes of the new propertiesSee Also:
getObjectPrototype
public static
getObjectPrototype(&scope)
Get the Object.prototype property.
See ECMA 15.2.4.
getFunctionPrototype
public static
getFunctionPrototype(&scope)
Get the Function.prototype property.
See ECMA 15.3.4.
getClassPrototype
public static
getClassPrototype(&scope,
java.lang.String&className)
Get the prototype for the named class.
For example, getClassPrototype(s, "Date") will first
walk up the parent chain to find the outermost scope, then will
search that scope for the Date constructor, and then will
return Date.prototype. If any of the lookups fail, or
the prototype is not a JavaScript object, then null will
be returned.
Parameters:scope - an object in the scope chainclassName - the name of the constructor
Returns:the prototype for the named class, or null if it
cannot be found.
getTopLevelScope
public static
getTopLevelScope(&obj)
Get the global scope.
Walks the parent scope chain to find an object with a null
parent scope (the global object).
Parameters:obj - a JavaScript object
Returns:the corresponding global scope
sealObject
public void sealObject()
Seal this object.
A sealed object may not have properties added or removed. Once
an object is sealed it may not be unsealed.
public final boolean isSealed()
Return true if this object is sealed.
It is an error to attempt to add or remove properties to
a sealed object.
Returns:true if sealed, false otherwise.Since:
getProperty
public static java.lang.Object getProperty(&obj,
java.lang.String&name)
Gets a named property from an object or any object in its prototype chain.
Searches the prototype chain for a property named name.
Parameters:obj - a JavaScript objectname - a property name
Returns:the value of a property with name name found in
obj or any object in its prototype chain, or
Scriptable.NOT_FOUND if not foundSince:
getProperty
public static java.lang.Object getProperty(&obj,
int&index)
Gets an indexed property from an object or any object in its prototype chain.
Searches the prototype chain for a property with integral index
index. Note that if you wish to look for properties with numerical
but non-integral indicies, you should use getProperty(Scriptable,String) with
the string value of the index.
Parameters:obj - a JavaScript objectindex - an integral index
Returns:the value of a property with index index found in
obj or any object in its prototype chain, or
Scriptable.NOT_FOUND if not foundSince:
hasProperty
public static boolean hasProperty(&obj,
java.lang.String&name)
Returns whether a named property is defined in an object or any object
in its prototype chain.
Searches the prototype chain for a property named name.
Parameters:obj - a JavaScript objectname - a property name
Returns:the true if property was foundSince:
redefineProperty
public static void redefineProperty(&obj,
java.lang.String&name,
boolean&isConst)
If hasProperty(obj, name) would return true, then if the property that
was found is compatible with the new property, this method just returns.
If the property is not compatible, then an exception is thrown.
A property redefinition is incompatible if the first definition was a
const declaration or if this one is.
They are compatible only if neither
was const.
hasProperty
public static boolean hasProperty(&obj,
int&index)
Returns whether an indexed property is defined in an object or any object
in its prototype chain.
Searches the prototype chain for a property with index index.
Parameters:obj - a JavaScript objectindex - a property index
Returns:the true if property was foundSince:
putProperty
public static void putProperty(&obj,
java.lang.String&name,
java.lang.Object&value)
Puts a named property in an object or in an object in its prototype chain.
Searches for the named property in the prototype chain. If it is found,
the value of the property in obj is changed through a call
prototype passing obj as the start argument.
This allows the prototype to veto the property setting in case the
prototype defines the property with [[ReadOnly]] attribute. If the
property is not found, it is added in obj.
Parameters:obj - a JavaScript objectname - a property namevalue - any JavaScript value accepted by Scriptable.putSince:
putConstProperty
public static void putConstProperty(&obj,
java.lang.String&name,
java.lang.Object&value)
Puts a named property in an object or in an object in its prototype chain.
Searches for the named property in the prototype chain. If it is found,
the value of the property in obj is changed through a call
prototype passing obj as the start argument.
This allows the prototype to veto the property setting in case the
prototype defines the property with [[ReadOnly]] attribute. If the
property is not found, it is added in obj.
Parameters:obj - a JavaScript objectname - a property namevalue - any JavaScript value accepted by Scriptable.putSince:
putProperty
public static void putProperty(&obj,
int&index,
java.lang.Object&value)
Puts an indexed property in an object or in an object in its prototype chain.
Searches for the indexed property in the prototype chain. If it is found,
the value of the property in obj is changed through a call
on the prototype
passing obj as the start argument. This allows
the prototype to veto the property setting in case the prototype defines
the property with [[ReadOnly]] attribute. If the property is not found,
it is added in obj.
Parameters:obj - a JavaScript objectindex - a property indexvalue - any JavaScript value accepted by Scriptable.putSince:
deleteProperty
public static boolean deleteProperty(&obj,
java.lang.String&name)
Removes the property from an object or its prototype chain.
Searches for a property with name in obj or
its prototype chain. If it is found, the object's delete
method is called.
Parameters:obj - a JavaScript objectname - a property name
Returns:true if the property doesn't exist or was successfully removedSince:
deleteProperty
public static boolean deleteProperty(&obj,
int&index)
Removes the property from an object or its prototype chain.
Searches for a property with index in obj or
its prototype chain. If it is found, the object's delete
method is called.
Parameters:obj - a JavaScript objectindex - a property index
Returns:true if the property doesn't exist or was successfully removedSince:
getPropertyIds
public static java.lang.Object[] getPropertyIds(&obj)
Returns an array of all ids from an object and its prototypes.
Parameters:obj - a JavaScript object
Returns:an array of all ids from all object in the prototype chain.
If a given id occurs multiple times in the prototype chain,
it will occur only once in this list.Since:
callMethod
public static java.lang.Object callMethod(&obj,
java.lang.String&methodName,
java.lang.Object[]&args)
Call a method of an object.
Parameters:obj - the JavaScript objectmethodName - the name of the function propertyargs - the arguments for the callSee Also:
callMethod
public static java.lang.Object callMethod(&cx,
java.lang.String&methodName,
java.lang.Object[]&args)
Call a method of an object.
Parameters:cx - the Context object associated with the current thread.obj - the JavaScript objectmethodName - the name of the function propertyargs - the arguments for the call
getAssociatedValue
public final java.lang.Object getAssociatedValue(java.lang.Object&key)
Get arbitrary application-specific value associated with this object.
Parameters:key - key object to select particular value.See Also:
getTopScopeValue
public static java.lang.Object getTopScopeValue(&scope,
java.lang.Object&key)
Get arbitrary application-specific value associated with the top scope
of the given scope.
The method first calls
and then searches the prototype chain of the top scope for the first
object containing the associated value with the given key.
Parameters:scope - the starting scope.key - key object to select particular value.See Also:
associateValue
public final java.lang.Object associateValue(java.lang.Object&key,
java.lang.Object&value)
Associate arbitrary application-specific value with this object.
Value can only be associated with the given object and key only once.
The method ignores any subsequent attempts to change the already
associated value.
The associated values are not serialized.
Parameters:key - key object to select particular value.value - the value to associate
Returns:the passed value if the method is called first time for the
given key or old value for any subsequent calls.See Also:

我要回帖

更多关于 swfobject.js用法 的文章

 

随机推荐