Skip to content

Commit 3774153

Browse files
committed
HTMLInputElement value/selectionStart/selectionEnd properties throws the correct error (InvalidStateError)
1 parent 50fe363 commit 3774153

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/changes/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
<body>
1010
<release version="4.10.0" date="February xx, 2025" description="Bugfixes">
11+
<action type="fix" dev="rbri">
12+
HTMLInputElement value/selectionStart/selectionEnd properties throws the correct error (InvalidStateError).
13+
</action>
1114
<action type="fix" dev="rbri">
1215
SVGMatrix.rotateFromVector()/inverse() throws the correct error (InvalidAccessError/InvalidStateError).
1316
</action>

src/main/java/org/htmlunit/javascript/host/html/HTMLInputElement.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.htmlunit.javascript.configuration.JsxFunction;
3838
import org.htmlunit.javascript.configuration.JsxGetter;
3939
import org.htmlunit.javascript.configuration.JsxSetter;
40+
import org.htmlunit.javascript.host.dom.DOMException;
4041
import org.htmlunit.javascript.host.dom.NodeList;
4142
import org.htmlunit.javascript.host.event.Event;
4243
import org.htmlunit.javascript.host.file.FileList;
@@ -105,8 +106,11 @@ public void setValue(final Object newValue) {
105106
final String val = JavaScriptEngine.toString(newValue);
106107
if ("file".equalsIgnoreCase(getType())) {
107108
if (StringUtils.isNotEmpty(val)) {
108-
throw JavaScriptEngine.reportRuntimeError("InvalidStateError: "
109-
+ "Failed to set the 'value' property on 'HTMLInputElement'.");
109+
throw JavaScriptEngine.asJavaScriptException(
110+
getWindow(),
111+
new DOMException(
112+
"Failed to set the 'value' property on 'HTMLInputElement'.",
113+
DOMException.INVALID_STATE_ERR));
110114
}
111115
return;
112116
}
@@ -237,18 +241,25 @@ public void setSelectionStart(final int start) {
237241
final DomNode dom = getDomNodeOrDie();
238242
if (dom instanceof SelectableTextInput) {
239243
if ("number".equalsIgnoreCase(getType())) {
240-
throw JavaScriptEngine.reportRuntimeError("Failed to set the 'selectionStart' property"
241-
+ "from 'HTMLInputElement': "
242-
+ "The input element's type ('number') does not support selection.");
244+
throw JavaScriptEngine.asJavaScriptException(
245+
getWindow(),
246+
new DOMException(
247+
"Failed to set the 'selectionStart' property"
248+
+ "from 'HTMLInputElement': "
249+
+ "The input element's type ('number') does not support selection.",
250+
DOMException.INVALID_STATE_ERR));
243251
}
244252

245253
((SelectableTextInput) dom).setSelectionStart(start);
246254
return;
247255
}
248256

249-
throw JavaScriptEngine.reportRuntimeError(
250-
"Failed to set the 'selectionStart' property from 'HTMLInputElement': "
251-
+ "The input element's type (" + getType() + ") does not support selection.");
257+
throw JavaScriptEngine.asJavaScriptException(
258+
getWindow(),
259+
new DOMException(
260+
"Failed to set the 'selectionStart' property from 'HTMLInputElement': "
261+
+ "The input element's type (" + getType() + ") does not support selection.",
262+
DOMException.INVALID_STATE_ERR));
252263
}
253264

254265
/**
@@ -278,17 +289,25 @@ public void setSelectionEnd(final int end) {
278289
final DomNode dom = getDomNodeOrDie();
279290
if (dom instanceof SelectableTextInput) {
280291
if ("number".equalsIgnoreCase(getType())) {
281-
throw JavaScriptEngine.reportRuntimeError("Failed to set the 'selectionEnd' property"
282-
+ "from 'HTMLInputElement': "
283-
+ "The input element's type ('number') does not support selection.");
292+
throw JavaScriptEngine.asJavaScriptException(
293+
getWindow(),
294+
new DOMException(
295+
"Failed to set the 'selectionEnd' property"
296+
+ "from 'HTMLInputElement': "
297+
+ "The input element's type ('number') does not support selection.",
298+
DOMException.INVALID_STATE_ERR));
284299
}
285300

286301
((SelectableTextInput) dom).setSelectionEnd(end);
287302
return;
288303
}
289304

290-
throw JavaScriptEngine.reportRuntimeError("Failed to set the 'selectionEnd' property from 'HTMLInputElement': "
291-
+ "The input element's type (" + getType() + ") does not support selection.");
305+
throw JavaScriptEngine.asJavaScriptException(
306+
getWindow(),
307+
new DOMException(
308+
"Failed to set the 'selectionEnd' property from 'HTMLInputElement': "
309+
+ "The input element's type (" + getType() + ") does not support selection.",
310+
DOMException.INVALID_STATE_ERR));
292311
}
293312

294313
/**

0 commit comments

Comments
 (0)