From 9cb00d0b943316d606a60f58db993470df65ebc1 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Sun, 10 Nov 2024 11:16:02 +0100 Subject: [PATCH] more concrete return values --- .../htmlunit/javascript/host/dom/Range.java | 19 ++++++++++--------- .../htmlunit/javascript/host/dom/Text.java | 3 ++- .../host/html/HTMLTableElement.java | 8 ++++---- .../host/html/HTMLTableRowElement.java | 3 ++- .../javascript/host/xml/FormData.java | 4 ++-- .../htmlunit/archunit/ArchitectureTest.java | 12 ------------ 6 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/htmlunit/javascript/host/dom/Range.java b/src/main/java/org/htmlunit/javascript/host/dom/Range.java index ce1a4a51c7..a98aec94c0 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/Range.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/Range.java @@ -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; @@ -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; } /** @@ -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()); } diff --git a/src/main/java/org/htmlunit/javascript/host/dom/Text.java b/src/main/java/org/htmlunit/javascript/host/dom/Text.java index e9d0874ad5..d286a1c7be 100644 --- a/src/main/java/org/htmlunit/javascript/host/dom/Text.java +++ b/src/main/java/org/htmlunit/javascript/host/dom/Text.java @@ -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; @@ -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)); } diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLTableElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLTableElement.java index 6116b13d83..c4203ca7de 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLTableElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLTableElement.java @@ -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")); } @@ -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")); } @@ -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")); } @@ -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")); } diff --git a/src/main/java/org/htmlunit/javascript/host/html/HTMLTableRowElement.java b/src/main/java/org/htmlunit/javascript/host/html/HTMLTableRowElement.java index 1b311fce1d..5828e4f12c 100644 --- a/src/main/java/org/htmlunit/javascript/host/html/HTMLTableRowElement.java +++ b/src/main/java/org/htmlunit/javascript/host/html/HTMLTableRowElement.java @@ -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; @@ -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); diff --git a/src/main/java/org/htmlunit/javascript/host/xml/FormData.java b/src/main/java/org/htmlunit/javascript/host/xml/FormData.java index 51ccec1108..0537d827ca 100644 --- a/src/main/java/org/htmlunit/javascript/host/xml/FormData.java +++ b/src/main/java/org/htmlunit/javascript/host/xml/FormData.java @@ -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_); } @@ -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_); } diff --git a/src/test/java/org/htmlunit/archunit/ArchitectureTest.java b/src/test/java/org/htmlunit/archunit/ArchitectureTest.java index a79b90c234..1d2833e9e4 100644 --- a/src/test/java/org/htmlunit/archunit/ArchitectureTest.java +++ b/src/test/java/org/htmlunit/archunit/ArchitectureTest.java @@ -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)") @@ -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)