Skip to content

Commit e9c057a

Browse files
committed
more on error handling
1 parent 46ea3ee commit e9c057a

File tree

5 files changed

+24
-14
lines changed

5 files changed

+24
-14
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+
SVGMatrix.rotateFromVector()/inverse() throws the correct error (InvalidAccessError/InvalidStateError).
13+
</action>
1114
<action type="fix" dev="rbri">
1215
Crypto.getRandomValues() throws a QuotaExceededError.
1316
</action>

src/main/java/org/htmlunit/javascript/host/svg/SVGMatrix.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.htmlunit.javascript.configuration.JsxGetter;
2323
import org.htmlunit.javascript.configuration.JsxSetter;
2424
import org.htmlunit.javascript.host.Window;
25+
import org.htmlunit.javascript.host.dom.DOMException;
2526

2627
/**
2728
* A JavaScript object for {@code SVGMatrix}.
@@ -222,8 +223,11 @@ public SVGMatrix inverse() {
222223
final double determinant = scaleX_ * scaleY_ - shearX_ * shearY_;
223224

224225
if (Math.abs(determinant) < 1E-10) {
225-
throw JavaScriptEngine.constructError("Error",
226-
"Failed to execute 'inverse' on 'SVGMatrix': The matrix is not invertible.");
226+
throw JavaScriptEngine.asJavaScriptException(
227+
getWindow(),
228+
new DOMException(
229+
"Failed to execute 'inverse' on 'SVGMatrix': The matrix is not invertible.",
230+
DOMException.INVALID_STATE_ERR));
227231
}
228232

229233
final SVGMatrix result = new SVGMatrix(getWindow());
@@ -288,8 +292,11 @@ public SVGMatrix rotate(final double angle) {
288292
@JsxFunction
289293
public SVGMatrix rotateFromVector(final double x, final double y) {
290294
if (x == 0 || y == 0) {
291-
throw JavaScriptEngine.constructError("Error",
292-
"Failed to execute 'rotateFromVector' on 'SVGMatrix': Arguments cannot be zero.");
295+
throw JavaScriptEngine.asJavaScriptException(
296+
getWindow(),
297+
new DOMException(
298+
"Failed to execute 'rotateFromVector' on 'SVGMatrix': Arguments cannot be zero.",
299+
DOMException.INVALID_ACCESS_ERR));
293300
}
294301

295302
final double theta = Math.atan2(y, x);

src/test/java/org/htmlunit/svg/SvgMatrixTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void fields() throws Exception {
8080
+ " m.e = 6;\n"
8181
+ " m.f = 7;\n"
8282
+ " alertFields(m);\n"
83-
+ "} catch(e) { log('exception'); }\n"
83+
+ "} catch(e) { log(e.name); }\n"
8484
+ "</script>\n"
8585
+ "</body></html>";
8686

@@ -114,7 +114,7 @@ public void methods() throws Exception {
114114
+ " log(typeof m.skewX);\n"
115115
+ " log(typeof m.skewY);\n"
116116
+ " log(typeof m.translate);\n"
117-
+ "} catch(e) { log('exception'); }\n"
117+
+ "} catch(e) { log(e.name); }\n"
118118
+ "</script>\n"
119119
+ "</body></html>";
120120

@@ -152,7 +152,7 @@ public void inverse() throws Exception {
152152
* @throws Exception if the test fails
153153
*/
154154
@Test
155-
@Alerts("exception")
155+
@Alerts("InvalidStateError")
156156
public void inverseNotPossible() throws Exception {
157157
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_
158158
+ "<html><body>\n"
@@ -178,7 +178,7 @@ public void inverseNotPossible() throws Exception {
178178
+ " m.f = 6;\n"
179179
+ " m = m.inverse();\n"
180180
+ " alertFields(m);\n"
181-
+ "} catch(e) { log('exception'); }\n"
181+
+ "} catch(e) { log(e.name); }\n"
182182
+ "</script>\n"
183183
+ "</body></html>";
184184

@@ -226,7 +226,7 @@ public void rotateFromVector() throws Exception {
226226
* @throws Exception if the test fails
227227
*/
228228
@Test
229-
@Alerts("exception")
229+
@Alerts("InvalidAccessError")
230230
public void rotateFromVectorZeroX() throws Exception {
231231
transformTest("rotateFromVector(0, 74)");
232232
}
@@ -235,7 +235,7 @@ public void rotateFromVectorZeroX() throws Exception {
235235
* @throws Exception if the test fails
236236
*/
237237
@Test
238-
@Alerts("exception")
238+
@Alerts("InvalidAccessError")
239239
public void rotateFromVectorZeroY() throws Exception {
240240
transformTest("rotateFromVector(17, 0)");
241241
}
@@ -244,7 +244,7 @@ public void rotateFromVectorZeroY() throws Exception {
244244
* @throws Exception if the test fails
245245
*/
246246
@Test
247-
@Alerts("exception")
247+
@Alerts("InvalidAccessError")
248248
public void rotateFromVectorZeroXY() throws Exception {
249249
transformTest("rotateFromVector(0, 0)");
250250
}
@@ -332,7 +332,7 @@ private void transformTest(final String transforamtion) throws Exception {
332332
+ " r = m." + transforamtion + ";\n"
333333
+ " log(m === r);\n"
334334
+ " alertFields(r);\n"
335-
+ "} catch(e) { log('exception'); }\n"
335+
+ "} catch(e) { log(e.name); }\n"
336336
+ "</script>\n"
337337
+ "</body></html>";
338338

src/test/java/org/htmlunit/svg/SvgTextTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void getFontSize() throws Exception {
7575
+ LOG_TITLE_FUNCTION
7676
+ "try {\n"
7777
+ " log(window.getComputedStyle(document.getElementById('myId'), null).fontSize);\n"
78-
+ "} catch(e) { log('exception'); }\n"
78+
+ "} catch(e) { log(e.name); }\n"
7979
+ "</script></body></html>";
8080

8181
loadPageVerifyTitle2(html);

src/test/java/org/htmlunit/xml/XmlPage2Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void createElementNS() throws Exception {
9090
+ " var doc = document.implementation.createDocument('', '', null);\n"
9191
+ " try {\n"
9292
+ " log(doc.createElementNS('myNS', 'ppp:eee'));\n"
93-
+ " } catch(e) {log('exception')}\n"
93+
+ " } catch(e) {log(e.name)}\n"
9494
+ " }\n"
9595
+ "</script></head><body onload='test()'>\n"
9696
+ "</body></html>";

0 commit comments

Comments
 (0)