Class HtmlUnitScriptable

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
All Implemented Interfaces:
Serializable, 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 Cloneable
Base class for Rhino host objects in HtmlUnit (not bound to a DOM node).
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
     
    private DomNode
     
    private static final org.apache.commons.logging.Log
     

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected Object
    get(String name, org.htmlunit.corejs.javascript.Scriptable start)
    Gets a named property from the object.
    Gets the browser version currently used.
    Returns the JavaScript class name.
    Returns the JavaScript default value of this object.
    Returns the DOM node that corresponds to this JavaScript object or throw an exception if one cannot be found.
    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(Class<? extends HtmlUnitScriptable> javaScriptClass)
    Gets the prototype object for the given host class.
    Returns the JavaScript object that corresponds to the specified object.
    protected org.htmlunit.corejs.javascript.Scriptable
    Gets the scriptable used at starting scope for the execution of current script.
    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 Object
    Called by get(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
    Initialize the parent scope of a newly created scriptable.
    Builds a new the JavaScript object that corresponds to the specified object.
    void
    put(String name, org.htmlunit.corejs.javascript.Scriptable start, Object value)
    void
    setClassName(String className)
    INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
    Sets the class name.
    void
    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 Object
    setupPromise(org.apache.commons.lang3.function.FailableSupplier<Object,IOException> resolver)
     
    protected Object
     

    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

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG

      private static final org.apache.commons.logging.Log LOG
    • domNode_

      private DomNode domNode_
    • className_

      private String className_
  • Constructor Details

    • HtmlUnitScriptable

      public HtmlUnitScriptable()
  • Method Details

    • getClassName

      public String getClassName()
      Returns the JavaScript class name.
      Specified by:
      getClassName in interface org.htmlunit.corejs.javascript.Scriptable
      Specified by:
      getClassName in class org.htmlunit.corejs.javascript.ScriptableObject
      Returns:
      the JavaScript class name
    • setClassName

      public void setClassName(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 interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      setParentScope in class org.htmlunit.corejs.javascript.ScriptableObject
    • put

      public void put(String name, org.htmlunit.corejs.javascript.Scriptable start, Object value)
      Specified by:
      put in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      put in class org.htmlunit.corejs.javascript.ScriptableObject
    • get

      public Object get(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 utility getWithPreemption(String).
      Specified by:
      get in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      get in class org.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
    • has

      public boolean has(int index, org.htmlunit.corejs.javascript.Scriptable start)
      Specified by:
      has in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      has in class org.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 node
      assignScriptObject - If true, call setScriptObject on domNode
    • getScriptableFor

      protected HtmlUnitScriptable 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 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 object
      scriptable - the script object to initialize
    • getPrototype

      public org.htmlunit.corejs.javascript.Scriptable getPrototype(Class<? extends HtmlUnitScriptable> javaScriptClass)
      Gets the prototype object for the given host class.
      Parameters:
      javaScriptClass - the host class
      Returns:
      the prototype
    • 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 org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getDefaultValue in class org.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(org.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 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) or JavaScriptEngine.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 interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      hasInstance in class org.htmlunit.corejs.javascript.ScriptableObject
    • equivalentValues

      protected Object equivalentValues(Object value)
      Overrides:
      equivalentValues in class org.htmlunit.corejs.javascript.ScriptableObject
    • clone

      public HtmlUnitScriptable clone()
      Overrides:
      clone in class Object
    • setupPromise

      protected Object setupPromise(org.apache.commons.lang3.function.FailableSupplier<Object,IOException> resolver)
    • setupRejectedPromise

      protected Object setupRejectedPromise(Supplier<Object> resolver)