Skip to content

Commit

Permalink
more concrete return values
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 10, 2024
1 parent 1d854c4 commit 54e8dbb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
31 changes: 7 additions & 24 deletions src/main/java/org/htmlunit/javascript/host/dom/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.htmlunit.ElementNotFoundException;
import org.htmlunit.HttpHeader;
import org.htmlunit.Page;
import org.htmlunit.SgmlPage;
Expand Down Expand Up @@ -521,25 +520,9 @@ public XPathNSResolver createNSResolver(final Node nodeResolver) {
* @return the new text node or NOT_FOUND if there is an error
*/
@JsxFunction
public Object createTextNode(final String newData) {
try {
final DomNode domNode = new DomText(getDomNodeOrDie().getPage(), newData);
final HtmlUnitScriptable jsElement = makeScriptableFor(domNode);

if (jsElement == NOT_FOUND) {
if (LOG.isDebugEnabled()) {
LOG.debug("createTextNode(" + newData
+ ") cannot return a result as there isn't a JavaScript object for the DOM node "
+ domNode.getClass().getName());
}
}
return jsElement;
}
catch (final ElementNotFoundException expected) {
// Just fall through - result is already set to NOT_FOUND
}

return NOT_FOUND;
public HtmlUnitScriptable createTextNode(final String newData) {
final DomNode domNode = new DomText(getDomNodeOrDie().getPage(), newData);
return makeScriptableFor(domNode);
}

/**
Expand Down Expand Up @@ -673,7 +656,7 @@ else if (element instanceof HtmlSvg) {
* @return the new HTML element, or NOT_FOUND if the tag is not supported
*/
@JsxFunction
public Object createElementNS(final String namespaceURI, final String qualifiedName) {
public HtmlUnitScriptable createElementNS(final String namespaceURI, final String qualifiedName) {
if ("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul".equals(namespaceURI)) {
throw JavaScriptEngine.reportRuntimeError("XUL not available");
}
Expand Down Expand Up @@ -718,7 +701,7 @@ public HTMLCollection getElementsByTagName(final String tagName) {
* @return a live NodeList of found elements in the order they appear in the tree
*/
@JsxFunction
public Object getElementsByTagNameNS(final Object namespaceURI, final String localName) {
public HTMLCollection getElementsByTagNameNS(final Object namespaceURI, final String localName) {
final HTMLCollection elements = new HTMLCollection(getDomNodeOrDie(), false);
elements.setIsMatchingPredicate(
(Predicate<DomNode> & Serializable)
Expand Down Expand Up @@ -1225,7 +1208,7 @@ private static org.w3c.dom.traversal.NodeFilter createFilterWrapper(final Script
* @return a new TreeWalker
*/
@JsxFunction
public Object createTreeWalker(final Node root, final double whatToShow, final Scriptable filter,
public TreeWalker createTreeWalker(final Node root, final double whatToShow, final Scriptable filter,
boolean expandEntityReferences) throws DOMException {

// seems that Rhino doesn't like long as parameter type
Expand Down Expand Up @@ -1660,7 +1643,7 @@ public int getChildElementCount() {
* @return the element for the specified x coordinate and the specified y coordinate
*/
@JsxFunction
public Object elementFromPoint(final int x, final int y) {
public HtmlUnitScriptable elementFromPoint(final int x, final int y) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/htmlunit/javascript/host/dom/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ protected void remove() {
* @return the removed child node
*/
@JsxFunction
public Object removeChild(final Object childObject) {
public Node removeChild(final Object childObject) {
if (!(childObject instanceof Node)) {
return null;
}
Expand Down
17 changes: 1 addition & 16 deletions src/test/java/org/htmlunit/archunit/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,29 +276,13 @@ public boolean test(final JavaClass javaClass) {
.and().doNotHaveFullName("org.htmlunit.javascript.host.Storage.getItem(java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.Window.setInterval(org.htmlunit.corejs.javascript.Context, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.Scriptable, [Ljava.lang.Object;, org.htmlunit.corejs.javascript.Function)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.Window.setTimeout(org.htmlunit.corejs.javascript.Context, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.Scriptable, [Ljava.lang.Object;, org.htmlunit.corejs.javascript.Function)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.canvas.IntersectionObserver.takeRecords()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.css.CSSRuleList.item(int)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.css.StyleSheetList.item(int)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.createElement(java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.createElementNS(java.lang.String, java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.createTextNode(java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.createTreeWalker(org.htmlunit.javascript.host.dom.Node, double, org.htmlunit.corejs.javascript.Scriptable, boolean)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.elementFromPoint(int, int)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Document.getElementsByTagNameNS(java.lang.Object, java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.NodeList.item(java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLCanvasElement.getContext(java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLCollection.item(java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLCollection.namedItem(java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLDocument.open(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLFormControlsCollection.namedItem(java.lang.String)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLMediaElement.play()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLOptionsCollection.item(int)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLSelectElement.item(int)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.RowContainer.insertRow(java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.intl.V8BreakIterator.resolvedOptions()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.media.BaseAudioContext.decodeAudioData(org.htmlunit.corejs.javascript.typedarrays.NativeArrayBuffer, org.htmlunit.corejs.javascript.Function, org.htmlunit.corejs.javascript.Function)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.media.MediaDevices.getUserMedia()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.performance.Performance.now()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.performance.PerformanceNavigation.toJSON()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.worker.DedicatedWorkerGlobalScope.setInterval(org.htmlunit.corejs.javascript.Context, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.Scriptable, [Ljava.lang.Object;, org.htmlunit.corejs.javascript.Function)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.worker.DedicatedWorkerGlobalScope.setTimeout(org.htmlunit.corejs.javascript.Context, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.Scriptable, [Ljava.lang.Object;, org.htmlunit.corejs.javascript.Function)")
Expand All @@ -307,6 +291,7 @@ public boolean test(final JavaClass javaClass) {
.should().haveRawReturnType(String.class)
.orShould().haveRawReturnType("int")
.orShould().haveRawReturnType("long")
.orShould().haveRawReturnType("double")
.orShould().haveRawReturnType("boolean")
.orShould().haveRawReturnType("void")
.orShould().haveRawReturnType(isAssignableToScriptable);
Expand Down

0 comments on commit 54e8dbb

Please sign in to comment.