com.gargoylesoftware.htmlunit.javascript
Class SimpleScriptable

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable
Direct Known Subclasses:
ActiveXObject, ActiveXObjectImpl, ArrayBuffer, ArrayBufferView, BoxObject, CanvasRenderingContext2D, ClientRect, ClipboardData, Console, Coordinates, CSSRule, CSSRuleList, CSSStyleDeclaration, CSSStyleSheet, CSSValue, DOMException, DOMImplementation, DOMParser, DOMStringMap, DOMTokenList, Enumerator, Event, External, Geolocation, History, HTMLOptionsCollection, Location, MediaList, MimeType, NamedNodeMap, Namespace, NamespaceCollection, Navigator, Netscape, Node, NodeFilter, NodeList, OfflineResourceList, Popup, Position, Range, Screen, Selection, SimpleArray, StaticNodeList, Storage, StorageList, StyleSheetList, SVGAngle, SVGMatrix, SVGRect, TextRange, TreeWalker, WebSocket, Window, XMLDOMParseError, XMLHttpRequest, XMLSerializer, XPathEvaluator, XPathNSResolver, XPathResult, XSLTemplate, XSLTProcessor

public class SimpleScriptable
extends net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
implements Cloneable

Base class for Rhino host objects in HtmlUnit.

Version:
$Revision: 8373 $
Author:
Mike Bowler, David K. Taylor, Marc Guillemot, Chris Erskine, Daniel Gredler, Ahmed Ashour, Ronald Brill
See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
SimpleScriptable()
           
 
Method Summary
 SimpleScriptable clone()
          
 void defineFunctionProperties(String[] names, Class<?> clazz, int attributes)
           Same as base implementation, but includes all methods inherited from super classes as well.
 void defineProperty(String propertyName, Class<?> clazz, int attributes)
           Same as base implementation, but includes all methods inherited from super classes as well.
protected  Object equivalentValues(Object value)
          
 Object get(String name, net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
          Gets a named property from the object.
 BrowserVersion getBrowserVersion()
          Gets the browser version currently used.
 String getClassName()
          Returns the JavaScript class name.
 Object getDefaultValue(Class<?> hint)
          Returns the JavaScript default value of this object.
<N extends DomNode>
N
getDomNodeOrDie()
          Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.
<N extends DomNode>
N
getDomNodeOrNull()
          Returns the DOM node that corresponds to this JavaScript object or null if a node hasn't been set.
protected  net.sourceforge.htmlunit.corejs.javascript.Scriptable getPrototype(Class<? extends SimpleScriptable> javaScriptClass)
          Gets the prototype object for the given host class.
protected  SimpleScriptable getScriptableFor(Object object)
          Returns the JavaScript object that corresponds to the specified object.
protected  net.sourceforge.htmlunit.corejs.javascript.Scriptable getStartingScope()
          Gets the scriptable used at starting scope for the execution of current script.
protected  org.apache.commons.collections.Transformer getTransformerScriptableFor()
          Gets a transformer getting the scriptable element for an HtmlElement.
 Window getWindow()
          Gets the window that is the top scope for this object.
protected static Window getWindow(net.sourceforge.htmlunit.corejs.javascript.Scriptable s)
          Gets the window that is the top scope for the specified object.
protected  Object getWithPreemption(String name)
          Called by get(String, Scriptable) to allow retrieval of the property before the prototype chain is searched.
 boolean hasInstance(net.sourceforge.htmlunit.corejs.javascript.Scriptable instance)
          
protected  void initParentScope(DomNode domNode, SimpleScriptable scriptable)
          Initialize the parent scope of a newly created scriptable.
protected  boolean isReadOnlySettable(String name, Object value)
           
 SimpleScriptable makeScriptableFor(DomNode domNode)
          Builds a new the JavaScript object that corresponds to the specified object.
 void setCaseSensitive(boolean caseSensitive)
          Sets case sensitivity of all properties of this scriptable.
 void setDomNode(DomNode domNode)
          Sets the DOM node that corresponds to this JavaScript object.
protected  void setDomNode(DomNode domNode, boolean assignScriptObject)
          Sets the DOM node that corresponds to this JavaScript object.
 void setHtmlElement(HtmlElement htmlElement)
          Sets the HTML element that corresponds to this JavaScript object.
 void setParentScope(net.sourceforge.htmlunit.corejs.javascript.Scriptable m)
          
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleScriptable

public SimpleScriptable()
Method Detail

get

public Object get(String name,
                  net.sourceforge.htmlunit.corejs.javascript.Scriptable start)
Gets a named property from the object. Normally HtmlUnit objects don't need to overwrite this method as properties are defined on the prototypes from the XML configuration. In some cases where "content" of object has priority compared to the properties consider using utility getWithPreemption(String). For fallback case just implement ScriptableWithFallbackGetter.

Specified by:
get in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
get in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getWithPreemption

protected Object getWithPreemption(String name)

Called by get(String, Scriptable) to allow retrieval of the property before the prototype chain is searched.

IMPORTANT: This method is invoked *very* often by Rhino. If you override this method, the implementation needs to be as fast as possible!

Parameters:
name - the property name
Returns:
Scriptable.NOT_FOUND if not found

getClassName

public String getClassName()
Returns the JavaScript class name.

Specified by:
getClassName in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Specified by:
getClassName in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
Returns:
the JavaScript class name

getDomNodeOrDie

public <N extends DomNode> N getDomNodeOrDie()
                                  throws IllegalStateException
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.

Type Parameters:
N - the node type
Returns:
the DOM node
Throws:
IllegalStateException - If the DOM node could not be found.

getDomNodeOrNull

public <N extends DomNode> N getDomNodeOrNull()
Returns the DOM node that corresponds to this JavaScript object or null if a node hasn't been set.

Type Parameters:
N - the node type
Returns:
the DOM node or null

setDomNode

public void setDomNode(DomNode domNode)
Sets the DOM node that corresponds to this JavaScript object.

Parameters:
domNode - the DOM node

setDomNode

protected void setDomNode(DomNode domNode,
                          boolean assignScriptObject)
Sets the DOM node that corresponds to this JavaScript object.

Parameters:
domNode - the DOM node
assignScriptObject - If true, call setScriptObject on domNode

setHtmlElement

public void setHtmlElement(HtmlElement htmlElement)
Sets the HTML element that corresponds to this JavaScript object.

Parameters:
htmlElement - the HTML element

getScriptableFor

protected SimpleScriptable getScriptableFor(Object object)
Returns the JavaScript object that corresponds to the specified object. New JavaScript objects will be created as needed. If a JavaScript object cannot be created for a domNode then NOT_FOUND will be returned.

Parameters:
object - a DomNode or a WebWindow
Returns:
the JavaScript object or NOT_FOUND

makeScriptableFor

public SimpleScriptable makeScriptableFor(DomNode domNode)
Builds a new the JavaScript object that corresponds to the specified object.

Parameters:
domNode - the DOM node for which a JS object should be created
Returns:
the JavaScript object

initParentScope

protected void initParentScope(DomNode domNode,
                               SimpleScriptable scriptable)
Initialize the parent scope of a newly created scriptable.

Parameters:
domNode - the DOM node for the script object
scriptable - the script object to initialize

getPrototype

protected net.sourceforge.htmlunit.corejs.javascript.Scriptable getPrototype(Class<? extends SimpleScriptable> javaScriptClass)
Gets the prototype object for the given host class.

Parameters:
javaScriptClass - the host class
Returns:
the prototype

getTransformerScriptableFor

protected org.apache.commons.collections.Transformer getTransformerScriptableFor()
Gets a transformer getting the scriptable element for an HtmlElement.

Returns:
the transformer

getDefaultValue

public Object getDefaultValue(Class<?> hint)
Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.

Specified by:
getDefaultValue in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
getDefaultValue in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
Parameters:
hint - a hint as to the format of the default value (ignored in this case)
Returns:
the default value

getWindow

public Window getWindow()
                 throws RuntimeException
Gets the window that is the top scope for this object.

Returns:
the window associated with this object
Throws:
RuntimeException - if the window cannot be found, which should never occur

getWindow

protected static Window getWindow(net.sourceforge.htmlunit.corejs.javascript.Scriptable s)
                           throws RuntimeException
Gets the window that is the top scope for the specified object.

Parameters:
s - the JavaScript object whose associated window is to be returned
Returns:
the window associated with the specified JavaScript object
Throws:
RuntimeException - if the window cannot be found, which should never occur

getStartingScope

protected net.sourceforge.htmlunit.corejs.javascript.Scriptable getStartingScope()
Gets the scriptable used at starting scope for the execution of current script.

Returns:
the scope as defined in JavaScriptEngine.callFunction(com.gargoylesoftware.htmlunit.html.HtmlPage, net.sourceforge.htmlunit.corejs.javascript.Function, net.sourceforge.htmlunit.corejs.javascript.Scriptable, java.lang.Object[], com.gargoylesoftware.htmlunit.html.DomNode) or JavaScriptEngine.execute(com.gargoylesoftware.htmlunit.html.HtmlPage, java.lang.String, java.lang.String, int).

defineProperty

public void defineProperty(String propertyName,
                           Class<?> clazz,
                           int attributes)
Same as base implementation, but includes all methods inherited from super classes as well.

Overrides:
defineProperty in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

defineFunctionProperties

public void defineFunctionProperties(String[] names,
                                     Class<?> clazz,
                                     int attributes)
Same as base implementation, but includes all methods inherited from super classes as well.

Overrides:
defineFunctionProperties in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

getBrowserVersion

public BrowserVersion getBrowserVersion()
Gets the browser version currently used.

Returns:
the browser version

hasInstance

public boolean hasInstance(net.sourceforge.htmlunit.corejs.javascript.Scriptable instance)

Specified by:
hasInstance in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
hasInstance in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

equivalentValues

protected Object equivalentValues(Object value)

Overrides:
equivalentValues in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

clone

public SimpleScriptable clone()

Overrides:
clone in class Object

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Sets case sensitivity of all properties of this scriptable.

Parameters:
caseSensitive - case sensitive or no

isReadOnlySettable

protected boolean isReadOnlySettable(String name,
                                     Object value)
Overrides:
isReadOnlySettable in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject

setParentScope

public void setParentScope(net.sourceforge.htmlunit.corejs.javascript.Scriptable m)

Specified by:
setParentScope in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
setParentScope in class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject


Copyright © 2002–2013 Gargoyle Software Inc.. All rights reserved.