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 3bbdb15 commit 9cb00d0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 29 deletions.
19 changes: 10 additions & 9 deletions src/main/java/org/htmlunit/javascript/host/dom/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public HtmlUnitScriptable extractContents() {
* equal to, or after the corresponding boundary-point of sourceRange.
*/
@JsxFunction
public Object compareBoundaryPoints(final int how, final Range sourceRange) {
public int compareBoundaryPoints(final int how, final Range sourceRange) {
final Node nodeForThis;
final int offsetForThis;
final int containingMoficator;
Expand Down Expand Up @@ -320,23 +320,24 @@ public Object compareBoundaryPoints(final int how, final Range sourceRange) {

if (nodeForThis == nodeForOther) {
if (offsetForThis < offsetForOther) {
return Integer.valueOf(-1);
return -1;
}
else if (offsetForThis > offsetForOther) {
return Integer.valueOf(1);
return 1;
}
return Integer.valueOf(0);
return 0;
}

final byte nodeComparision = (byte) nodeForThis.compareDocumentPosition(nodeForOther);
if ((nodeComparision & Node.DOCUMENT_POSITION_CONTAINED_BY) != 0) {
return Integer.valueOf(-1 * containingMoficator);
return -1 * containingMoficator;
}
else if ((nodeComparision & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
return Integer.valueOf(-1);
return -1;
}
// TODO: handle other cases!
return Integer.valueOf(1);

// TODO: handle other cases
return 1;
}

/**
Expand Down Expand Up @@ -400,7 +401,7 @@ public void surroundContents(final Node newNode) {
* @return a clone of the range
*/
@JsxFunction
public Object cloneRange() {
public Range cloneRange() {
try {
return new Range(getSimpleRange().cloneRange());
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/htmlunit/javascript/host/dom/Text.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.htmlunit.javascript.host.dom;

import org.htmlunit.html.DomText;
import org.htmlunit.javascript.HtmlUnitScriptable;
import org.htmlunit.javascript.configuration.JsxClass;
import org.htmlunit.javascript.configuration.JsxConstructor;
import org.htmlunit.javascript.configuration.JsxFunction;
Expand Down Expand Up @@ -48,7 +49,7 @@ public void jsConstructor() {
* @return the Text node that was split from this node
*/
@JsxFunction
public Object splitText(final int offset) {
public HtmlUnitScriptable splitText(final int offset) {
final DomText domText = (DomText) getDomNodeOrDie();
return getScriptableFor(domText.splitText(offset));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public HtmlUnitScriptable getTBodies() {
* @return a newly added caption if no caption exists, or the first existing caption
*/
@JsxFunction
public Object createCaption() {
public HtmlUnitScriptable createCaption() {
return getScriptableFor(getDomNodeOrDie().appendChildIfNoneExists("caption"));
}

Expand All @@ -185,7 +185,7 @@ public Object createCaption() {
* @return a newly added caption if no caption exists, or the first existing caption
*/
@JsxFunction
public Object createTFoot() {
public HtmlUnitScriptable createTFoot() {
return getScriptableFor(getDomNodeOrDie().appendChildIfNoneExists("tfoot"));
}

Expand All @@ -197,7 +197,7 @@ public Object createTFoot() {
* @return a newly added caption if no caption exists, or the first existing caption
*/
@JsxFunction
public Object createTBody() {
public HtmlUnitScriptable createTBody() {
return getScriptableFor(getDomNodeOrDie().appendChildIfNoneExists("tbody"));
}

Expand All @@ -209,7 +209,7 @@ public Object createTBody() {
* @return a newly added caption if no caption exists, or the first existing caption
*/
@JsxFunction
public Object createTHead() {
public HtmlUnitScriptable createTHead() {
return getScriptableFor(getDomNodeOrDie().appendChildIfNoneExists("thead"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.htmlunit.html.HtmlPage;
import org.htmlunit.html.HtmlTable;
import org.htmlunit.html.HtmlTableRow;
import org.htmlunit.javascript.HtmlUnitScriptable;
import org.htmlunit.javascript.JavaScriptEngine;
import org.htmlunit.javascript.configuration.JsxClass;
import org.htmlunit.javascript.configuration.JsxConstructor;
Expand Down Expand Up @@ -134,7 +135,7 @@ public void setBgColor(final String bgColor) {
* @return the newly-created cell
*/
@JsxFunction
public Object insertCell(final Object index) {
public HtmlUnitScriptable insertCell(final Object index) {
int position = -1;
if (!JavaScriptEngine.isUndefined(index)) {
position = (int) JavaScriptEngine.toNumber(index);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/htmlunit/javascript/host/xml/FormData.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public void forEach(final Object callback) {
* @return an iterator.
*/
@JsxFunction
public Object keys() {
public FormDataIterator keys() {
return new FormDataIterator(getParentScope(),
"FormData Iterator", FormDataIterator.Type.KEYS, requestParameters_);
}
Expand All @@ -361,7 +361,7 @@ public Object keys() {
* @return an iterator.
*/
@JsxFunction
public Object values() {
public FormDataIterator values() {
return new FormDataIterator(getParentScope(),
"FormData Iterator", FormDataIterator.Type.VALUES, requestParameters_);
}
Expand Down
12 changes: 0 additions & 12 deletions src/test/java/org/htmlunit/archunit/ArchitectureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ public boolean test(final JavaClass javaClass) {
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Node.removeChild(java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Node.replaceChild(java.lang.Object, java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.NodeList.item(java.lang.Object)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Range.cloneRange()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Range.compareBoundaryPoints(int, org.htmlunit.javascript.host.dom.Range)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.dom.Text.splitText(int)")
.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)")
Expand All @@ -310,23 +307,14 @@ public boolean test(final JavaClass javaClass) {
.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.HTMLTableElement.createCaption()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.createTBody()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.createTFoot()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableElement.createTHead()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.html.HTMLTableRowElement.insertCell(java.lang.Object)")
.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.svg.SVGPathElement.getTotalLength()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.svg.SVGTextContentElement.getComputedTextLength()")
.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)")
.and().doNotHaveFullName("org.htmlunit.javascript.host.xml.FormData.keys()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.xml.FormData.values()")
.and().doNotHaveFullName("org.htmlunit.javascript.host.xml.XSLTProcessor.getParameter(java.lang.String, java.lang.String)")

.should().haveRawReturnType(String.class)
Expand Down

0 comments on commit 9cb00d0

Please sign in to comment.