Skip to content

Commit 8920deb

Browse files
committed
Document - several fixes to throw the correct error
1 parent 44c0e43 commit 8920deb

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
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+
Document - several fixes to throw the correct error.
13+
</action>
1114
<action type="fix" dev="rbri">
1215
XMLHttpRequest - several fixes to throw the correct error.
1316
</action>

src/main/java/org/htmlunit/javascript/HtmlUnitScriptable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void put(final String name, final Scriptable start, final Object value) {
109109
}
110110
catch (final IllegalArgumentException e) {
111111
// is it the right place or should Rhino throw a RuntimeError instead of an IllegalArgumentException?
112-
throw JavaScriptEngine.reportRuntimeError("'set "
112+
throw JavaScriptEngine.typeError("'set "
113113
+ name + "' called on an object that does not implement interface " + getClassName());
114114
}
115115
}

src/main/java/org/htmlunit/javascript/host/dom/Document.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,9 +875,13 @@ public void setBody(final HTMLElement htmlElement) {
875875
}
876876
return;
877877
}
878-
throw JavaScriptEngine.reportRuntimeError("Failed to set the 'body' property on 'Document': "
879-
+ "The new body element is of type '" + htmlElement.getTagName() + "'. "
880-
+ "It must be either a 'BODY' or 'FRAMESET' element.");
878+
throw JavaScriptEngine.asJavaScriptException(
879+
getWindow(),
880+
new org.htmlunit.javascript.host.dom.DOMException(
881+
"Failed to set the 'body' property on 'Document': "
882+
+ "The new body element is of type '" + htmlElement.getTagName() + "'. "
883+
+ "It must be either a 'BODY' or 'FRAMESET' element.",
884+
org.htmlunit.javascript.host.dom.DOMException.HIERARCHY_REQUEST_ERR));
881885
}
882886

883887
/**

0 commit comments

Comments
 (0)