Java Code Examples for net.sourceforge.htmlunit.corejs.javascript.Scriptable#getPrototype()
The following examples show how to use
net.sourceforge.htmlunit.corejs.javascript.Scriptable#getPrototype() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecursiveFunctionObject.java From htmlunit with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final Object object = super.call(cx, scope, thisObj, args); if (object instanceof Scriptable) { final Scriptable result = (Scriptable) object; if (result.getPrototype() == null) { final Scriptable proto = getClassPrototype(); if (result != proto) { result.setPrototype(proto); } } if (result.getParentScope() == null) { final Scriptable parent = getParentScope(); if (result != parent) { result.setParentScope(parent); } } } return object; }
Example 2
Source File: CSSStyleDeclaration.java From htmlunit with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { if (this != start) { return super.get(name, start); } Scriptable prototype = getPrototype(); while (prototype != null) { final Object value = prototype.get(name, start); if (value != Scriptable.NOT_FOUND) { return value; } prototype = prototype.getPrototype(); } final Definition style = StyleAttributes.getDefinition(name, getBrowserVersion()); if (style != null) { return getStyleAttribute(style); } return super.get(name, start); }
Example 3
Source File: HTMLDocument.java From htmlunit with Apache License 2.0 | 6 votes |
/** * Returns the current document instance, using <tt>thisObj</tt> as a hint. * @param thisObj a hint as to the current document (may be the prototype when function is used without "this") * @return the current document instance */ private static HTMLDocument getDocument(final Scriptable thisObj) { // if function is used "detached", then thisObj is the top scope (ie Window), not the real object // cf unit test DocumentTest#testDocumentWrite_AssignedToVar // may be the prototype too // cf DocumentTest#testDocumentWrite_AssignedToVar2 if (thisObj instanceof HTMLDocument && thisObj.getPrototype() instanceof HTMLDocument) { return (HTMLDocument) thisObj; } if (thisObj instanceof DocumentProxy && thisObj.getPrototype() instanceof HTMLDocument) { return (HTMLDocument) ((DocumentProxy) thisObj).getDelegee(); } final Window window = getWindow(thisObj); if (window.getBrowserVersion().hasFeature(HTMLDOCUMENT_FUNCTION_DETACHED)) { return (HTMLDocument) window.getDocument(); } throw Context.reportRuntimeError("Function can't be used detached from document"); }
Example 4
Source File: RecursiveFunctionObject.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final Object object = super.call(cx, scope, thisObj, args); if (object instanceof Scriptable) { final Scriptable result = (Scriptable) object; if (result.getPrototype() == null) { final Scriptable proto = getClassPrototype(); if (result != proto) { result.setPrototype(proto); } } if (result.getParentScope() == null) { final Scriptable parent = getParentScope(); if (result != parent) { result.setParentScope(parent); } } } return object; }
Example 5
Source File: CSSStyleDeclaration.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { if (this != start) { return super.get(name, start); } Scriptable prototype = getPrototype(); while (prototype != null) { final Object value = prototype.get(name, start); if (value != Scriptable.NOT_FOUND) { return value; } prototype = prototype.getPrototype(); } final Definition style = StyleAttributes.getDefinition(name, getBrowserVersion()); if (style != null) { return getStyleAttribute(style); } return super.get(name, start); }
Example 6
Source File: HTMLDocument.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * Returns the current document instance, using <tt>thisObj</tt> as a hint. * @param thisObj a hint as to the current document (may be the prototype when function is used without "this") * @return the current document instance */ private static HTMLDocument getDocument(final Scriptable thisObj) { // if function is used "detached", then thisObj is the top scope (ie Window), not the real object // cf unit test DocumentTest#testDocumentWrite_AssignedToVar // may be the prototype too // cf DocumentTest#testDocumentWrite_AssignedToVar2 if (thisObj instanceof HTMLDocument && thisObj.getPrototype() instanceof HTMLDocument) { return (HTMLDocument) thisObj; } if (thisObj instanceof DocumentProxy && thisObj.getPrototype() instanceof HTMLDocument) { return (HTMLDocument) ((DocumentProxy) thisObj).getDelegee(); } final Window window = getWindow(thisObj); if (window.getBrowserVersion().hasFeature(HTMLDOCUMENT_FUNCTION_DETACHED)) { return (HTMLDocument) window.getDocument(); } throw Context.reportRuntimeError("Function can't be used detached from document"); }