Package org.htmlunit.javascript
Class HtmlUnitScriptable
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ScriptableObject
-
- org.htmlunit.javascript.HtmlUnitScriptable
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,org.htmlunit.corejs.javascript.ConstProperties
,org.htmlunit.corejs.javascript.debug.DebuggableObject
,org.htmlunit.corejs.javascript.Scriptable
,org.htmlunit.corejs.javascript.SymbolScriptable
- Direct Known Subclasses:
AbstractList
,AbstractRange
,Atomics
,AudioBuffer
,AudioListener
,AudioParam
,BarProp
,Blob
,Cache
,CacheStorage
,CanvasGradient
,CanvasPattern
,CanvasRenderingContext2D
,CaretPosition
,ClientRect
,ClientRectList
,Collator
,Credential
,CredentialsContainer
,Crypto
,CryptoKey
,CSS
,CSSRule
,CSSRuleList
,CSSStyleDeclaration
,CustomElementRegistry
,DataTransfer
,DataTransferItem
,DataTransferItemList
,DateTimeFormat
,DOMError
,DOMException
,DOMImplementation
,DOMMatrixReadOnly
,DOMParser
,DOMPointReadOnly
,DOMRectReadOnly
,DOMStringList
,DOMStringMap
,DOMTokenList
,Event
,EventTarget
,External
,FileList
,FileSystem
,FileSystemDirectoryReader
,FileSystemEntry
,FontFace
,FormData
,Gamepad
,GamepadButton
,Geolocation
,GeolocationCoordinates
,GeolocationPosition
,GeolocationPositionError
,Headers
,History
,HTMLOptionsCollection
,IDBCursor
,IDBFactory
,IDBIndex
,IDBKeyRange
,IDBObjectStore
,IdleDeadline
,ImageBitmap
,ImageBitmapRenderingContext
,ImageData
,InputDeviceCapabilities
,IntersectionObserver
,IntersectionObserverEntry
,Intl
,KeyframeEffect
,Location
,MediaDeviceInfo
,MediaError
,MediaKeys
,MediaKeyStatusMap
,MediaKeySystemAccess
,MediaList
,MessageChannel
,MIDIInputMap
,MIDIOutputMap
,MimeType
,MutationObserver
,MutationRecord
,NamedNodeMap
,Navigator
,Netscape
,NodeFilter
,NodeIterator
,NumberFormat
,Path2D
,PaymentAddress
,PerformanceEntry
,PerformanceNavigation
,PerformanceObserver
,PerformanceObserverEntryList
,PerformanceTiming
,PeriodicSyncManager
,PeriodicWave
,Permissions
,Presentation
,ProxyAutoConfig
,PushManager
,PushSubscription
,PushSubscriptionOptions
,ReadableStream
,Request
,Response
,RTCCertificate
,RTCIceCandidate
,RTCSessionDescription
,RTCStatsReport
,Selection
,SimpleArray
,SpeechSynthesisVoice
,Storage
,StorageManager
,StyleMedia
,StyleSheet
,StyleSheetList
,SubtleCrypto
,SVGAngle
,SVGAnimatedAngle
,SVGAnimatedBoolean
,SVGAnimatedEnumeration
,SVGAnimatedInteger
,SVGAnimatedLength
,SVGAnimatedLengthList
,SVGAnimatedNumber
,SVGAnimatedNumberList
,SVGAnimatedPreserveAspectRatio
,SVGAnimatedRect
,SVGAnimatedString
,SVGAnimatedTransformList
,SVGLength
,SVGLengthList
,SVGMatrix
,SVGNumber
,SVGNumberList
,SVGPoint
,SVGPointList
,SVGPreserveAspectRatio
,SVGRect
,SVGStringList
,SVGTransform
,SVGTransformList
,SVGUnitTypes
,SyncManager
,TextDecoder
,TextEncoder
,TextMetrics
,TextTrackCueList
,TimeRanges
,Touch
,TouchList
,TreeWalker
,URL
,URLSearchParams
,V8BreakIterator
,ValidityState
,VideoPlaybackQuality
,WebGL2RenderingContext
,WebGLActiveInfo
,WebGLBuffer
,WebGLFramebuffer
,WebGLProgram
,WebGLQuery
,WebGLRenderbuffer
,WebGLRenderingContext
,WebGLSampler
,WebGLShader
,WebGLShaderPrecisionFormat
,WebGLSync
,WebGLTexture
,WebGLTransformFeedback
,WebGLUniformLocation
,WebGLVertexArrayObject
,WebkitSpeechGrammar
,WebkitSpeechGrammarList
,XMLSerializer
,XPathEvaluator
,XPathExpression
,XPathNSResolver
,XPathResult
,XSLTProcessor
public class HtmlUnitScriptable extends org.htmlunit.corejs.javascript.ScriptableObject implements java.lang.Cloneable
Base class for Rhino host objects in HtmlUnit (not bound to a DOM node).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
className_
private DomNode
domNode_
private static org.apache.commons.logging.Log
LOG
-
Constructor Summary
Constructors Constructor Description HtmlUnitScriptable()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlUnitScriptable
clone()
protected java.lang.Object
equivalentValues(java.lang.Object value)
java.lang.Object
get(java.lang.String name, org.htmlunit.corejs.javascript.Scriptable start)
Gets a named property from the object.BrowserVersion
getBrowserVersion()
Gets the browser version currently used.java.lang.String
getClassName()
Returns the JavaScript class name.java.lang.Object
getDefaultValue(java.lang.Class<?> hint)
Returns the JavaScript default value of this object.DomNode
getDomNodeOrDie()
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.DomNode
getDomNodeOrNull()
Returns the DOM node that corresponds to this JavaScript object or null if a node hasn't been set.org.htmlunit.corejs.javascript.Scriptable
getPrototype(java.lang.Class<? extends HtmlUnitScriptable> javaScriptClass)
Gets the prototype object for the given host class.protected HtmlUnitScriptable
getScriptableFor(java.lang.Object object)
Returns the JavaScript object that corresponds to the specified object.protected org.htmlunit.corejs.javascript.Scriptable
getStartingScope()
Gets the scriptable used at starting scope for the execution of current script.Window
getWindow()
Gets the window that is the top scope for this object.protected static Window
getWindow(org.htmlunit.corejs.javascript.Scriptable s)
Gets the window that is the top scope for the specified object.protected java.lang.Object
getWithPreemption(java.lang.String name)
Called byget(String, Scriptable)
to allow retrieval of the property before the prototype chain is searched.boolean
has(int index, org.htmlunit.corejs.javascript.Scriptable start)
boolean
hasInstance(org.htmlunit.corejs.javascript.Scriptable instance)
protected void
initParentScope(DomNode domNode, HtmlUnitScriptable scriptable)
Initialize the parent scope of a newly created scriptable.HtmlUnitScriptable
makeScriptableFor(DomNode domNode)
Builds a new the JavaScript object that corresponds to the specified object.void
put(java.lang.String name, org.htmlunit.corejs.javascript.Scriptable start, java.lang.Object value)
void
setClassName(java.lang.String className)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the class name.void
setDomNode(DomNode domNode)
Sets the DOM node that corresponds to this JavaScript object.void
setDomNode(DomNode domNode, boolean assignScriptObject)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the DOM node that corresponds to this JavaScript object.void
setParentScope(org.htmlunit.corejs.javascript.Scriptable m)
protected java.lang.Object
setupPromise(org.apache.commons.lang3.function.FailableSupplier<java.lang.Object,java.io.IOException> resolver)
protected java.lang.Object
setupRejectedPromise(java.util.function.Supplier<java.lang.Object> resolver)
-
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
-
-
-
Field Detail
-
LOG
private static final org.apache.commons.logging.Log LOG
-
domNode_
private DomNode domNode_
-
className_
private java.lang.String className_
-
-
Method Detail
-
getClassName
public java.lang.String getClassName()
Returns the JavaScript class name.- Specified by:
getClassName
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Specified by:
getClassName
in classorg.htmlunit.corejs.javascript.ScriptableObject
- Returns:
- the JavaScript class name
-
setClassName
public void setClassName(java.lang.String className)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the class name.- Parameters:
className
- the class name.
-
setParentScope
public void setParentScope(org.htmlunit.corejs.javascript.Scriptable m)
- Specified by:
setParentScope
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
setParentScope
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
put
public void put(java.lang.String name, org.htmlunit.corejs.javascript.Scriptable start, java.lang.Object value)
- Specified by:
put
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
put
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
get
public java.lang.Object get(java.lang.String name, org.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 utilitygetWithPreemption(String)
.- Specified by:
get
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
get
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
getWithPreemption
protected java.lang.Object getWithPreemption(java.lang.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
-
has
public boolean has(int index, org.htmlunit.corejs.javascript.Scriptable start)
- Specified by:
has
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
has
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
getDomNodeOrDie
public DomNode getDomNodeOrDie()
Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.- Returns:
- the DOM node
-
getDomNodeOrNull
public DomNode getDomNodeOrNull()
Returns the DOM node that corresponds to this JavaScript object or null if a node hasn't been set.- 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
public void setDomNode(DomNode domNode, boolean assignScriptObject)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Sets the DOM node that corresponds to this JavaScript object.- Parameters:
domNode
- the DOM nodeassignScriptObject
- If true, callsetScriptObject
on domNode
-
getScriptableFor
protected HtmlUnitScriptable getScriptableFor(java.lang.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.
-
makeScriptableFor
public HtmlUnitScriptable 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, HtmlUnitScriptable scriptable)
Initialize the parent scope of a newly created scriptable.- Parameters:
domNode
- the DOM node for the script objectscriptable
- the script object to initialize
-
getPrototype
public org.htmlunit.corejs.javascript.Scriptable getPrototype(java.lang.Class<? extends HtmlUnitScriptable> javaScriptClass)
Gets the prototype object for the given host class.- Parameters:
javaScriptClass
- the host class- Returns:
- the prototype
-
getDefaultValue
public java.lang.Object getDefaultValue(java.lang.Class<?> hint)
Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.- Specified by:
getDefaultValue
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
getDefaultValue
in classorg.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 java.lang.RuntimeException
Gets the window that is the top scope for this object.- Returns:
- the window associated with this object
- Throws:
java.lang.RuntimeException
- if the window cannot be found, which should never occur
-
getWindow
protected static Window getWindow(org.htmlunit.corejs.javascript.Scriptable s) throws java.lang.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:
java.lang.RuntimeException
- if the window cannot be found, which should never occur
-
getStartingScope
protected org.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(org.htmlunit.html.HtmlPage, org.htmlunit.corejs.javascript.Function, org.htmlunit.corejs.javascript.Scriptable, java.lang.Object[], org.htmlunit.html.DomNode)
orJavaScriptEngine.execute(org.htmlunit.html.HtmlPage, org.htmlunit.corejs.javascript.Scriptable, java.lang.String, java.lang.String, int)
.
-
getBrowserVersion
public BrowserVersion getBrowserVersion()
Gets the browser version currently used.- Returns:
- the browser version
-
hasInstance
public boolean hasInstance(org.htmlunit.corejs.javascript.Scriptable instance)
- Specified by:
hasInstance
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
hasInstance
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
equivalentValues
protected java.lang.Object equivalentValues(java.lang.Object value)
- Overrides:
equivalentValues
in classorg.htmlunit.corejs.javascript.ScriptableObject
-
clone
public HtmlUnitScriptable clone()
- Overrides:
clone
in classjava.lang.Object
-
setupPromise
protected java.lang.Object setupPromise(org.apache.commons.lang3.function.FailableSupplier<java.lang.Object,java.io.IOException> resolver)
-
setupRejectedPromise
protected java.lang.Object setupRejectedPromise(java.util.function.Supplier<java.lang.Object> resolver)
-
-