Skip to content

Commit 743a8e6

Browse files
committed
build the correct error
1 parent 3925833 commit 743a8e6

File tree

10 files changed

+39
-35
lines changed

10 files changed

+39
-35
lines changed

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,16 +1169,6 @@ public static EcmaError typeError(final String message) {
11691169
return ScriptRuntime.typeError(message);
11701170
}
11711171

1172-
/**
1173-
* Report a runtime error using the error reporter for the current thread.
1174-
*
1175-
* @param message the error message to report
1176-
* @return EcmaError
1177-
*/
1178-
public static EcmaError networkError(final String message) {
1179-
return ScriptRuntime.networkError(message);
1180-
}
1181-
11821172
/**
11831173
* Report a runtime error using the error reporter for the current thread.
11841174
*

src/main/java/org/htmlunit/javascript/host/Window.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@
9999
import org.htmlunit.javascript.host.css.MediaQueryList;
100100
import org.htmlunit.javascript.host.css.StyleMedia;
101101
import org.htmlunit.javascript.host.dom.AbstractList.EffectOnCache;
102+
import org.htmlunit.javascript.host.dom.DOMException;
102103
import org.htmlunit.javascript.host.dom.Document;
103104
import org.htmlunit.javascript.host.dom.Selection;
104105
import org.htmlunit.javascript.host.event.Event;
@@ -1983,9 +1984,12 @@ public static void postMessage(final Context context, final Scriptable scope,
19831984
targetURL = new URL(targetOrigin);
19841985
}
19851986
catch (final Exception e) {
1986-
throw JavaScriptEngine.syntaxError(
1987-
"Failed to execute 'postMessage' on 'Window': Invalid target origin '"
1988-
+ targetOrigin + "' was specified (reason: " + e.getMessage() + ".");
1987+
throw JavaScriptEngine.asJavaScriptException(
1988+
(HtmlUnitScriptable) getTopLevelScope(thisObj),
1989+
new DOMException(
1990+
"Failed to execute 'postMessage' on 'Window': Invalid target origin '"
1991+
+ targetOrigin + "' was specified (reason: " + e.getMessage() + ".",
1992+
DOMException.SYNTAX_ERR));
19891993
}
19901994
}
19911995

src/main/java/org/htmlunit/javascript/host/xml/XMLHttpRequest.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -908,7 +908,11 @@ void doSend() {
908908
if (LOG.isDebugEnabled()) {
909909
LOG.debug("Not allowed to load local resource: " + webRequest_.getUrl());
910910
}
911-
throw JavaScriptEngine.networkError("Not allowed to load local resource: " + webRequest_.getUrl());
911+
throw JavaScriptEngine.asJavaScriptException(
912+
getWindow(),
913+
new DOMException(
914+
"Not allowed to load local resource: " + webRequest_.getUrl(),
915+
DOMException.NETWORK_ERR));
912916
}
913917

914918
final BrowserVersion browserVersion = getBrowserVersion();
@@ -960,7 +964,11 @@ void doSend() {
960964
if (LOG.isDebugEnabled()) {
961965
LOG.debug("No permitted request for URL " + webRequest_.getUrl());
962966
}
963-
throw JavaScriptEngine.networkError("No permitted \"Access-Control-Allow-Origin\" header.");
967+
throw JavaScriptEngine.asJavaScriptException(
968+
getWindow(),
969+
new DOMException(
970+
"No permitted \"Access-Control-Allow-Origin\" header.",
971+
DOMException.NETWORK_ERR));
964972
}
965973
}
966974

@@ -1081,7 +1089,9 @@ public Charset getContentCharset() {
10811089
fireJavascriptEvent(Event.TYPE_LOAD_END);
10821090
}
10831091

1084-
throw JavaScriptEngine.networkError(e.getMessage());
1092+
throw JavaScriptEngine.asJavaScriptException(
1093+
getWindow(),
1094+
new DOMException(e.getMessage(), DOMException.NETWORK_ERR));
10851095
}
10861096
}
10871097
}

src/test/java/org/htmlunit/javascript/host/dom/DOMExceptionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ public void properties() throws Exception {
310310
*/
311311
@Test
312312
@Alerts(DEFAULT = {"3", "true", "undefined", "undefined", "HIERARCHY_REQUEST_ERR: 3", "1"},
313-
FF = {"3", "true", "8", "§§URL§§", "HIERARCHY_REQUEST_ERR: 3", "1"},
314-
FF_ESR = {"3", "true", "8", "§§URL§§", "HIERARCHY_REQUEST_ERR: 3", "1"})
313+
FF = {"3", "true", "25", "§§URL§§", "HIERARCHY_REQUEST_ERR: 3", "1"},
314+
FF_ESR = {"3", "true", "25", "§§URL§§", "HIERARCHY_REQUEST_ERR: 3", "1"})
315315
/*
316316
* Messages:
317317
* CHROME: "A Node was inserted somewhere it doesn't belong."

src/test/java/org/htmlunit/javascript/host/dom/DocumentTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,10 +3693,10 @@ public void useInWeakSet() throws Exception {
36933693
*/
36943694
@Test
36953695
@Alerts({"about:blank", "about:blank", "undefined", "null", "null"})
3696-
@HtmlUnitNYI(CHROME = "InternalError",
3697-
EDGE = "InternalError",
3698-
FF = "InternalError",
3699-
FF_ESR = "InternalError")
3696+
@HtmlUnitNYI(CHROME = "InternalError/InternalError",
3697+
EDGE = "InternalError/InternalError",
3698+
FF = "InternalError/InternalError",
3699+
FF_ESR = "InternalError/InternalError")
37003700
public void newDoc() throws Exception {
37013701
final String html = "<html>\n"
37023702
+ "<head>\n"

src/test/java/org/htmlunit/javascript/host/event/AnimationEventTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public void create_ctor() throws Exception {
6767
*/
6868
@Test
6969
@Alerts(DEFAULT = {"[object AnimationEvent]", "", "false", "false", "false"},
70-
FF = "NotSupportedError",
71-
FF_ESR = "NotSupportedError")
70+
FF = "NotSupportedError/DOMException",
71+
FF_ESR = "NotSupportedError/DOMException")
7272
public void create_createEvent() throws Exception {
7373
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_
7474
+ "<html><head><script>\n"

src/test/java/org/htmlunit/javascript/host/event/CloseEventTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public void create_ctorWithDetails() throws Exception {
9999
*/
100100
@Test
101101
@Alerts(DEFAULT = {"[object CloseEvent]", "", "false", "false", "false", "0", "", "false"},
102-
FF = "NotSupportedError",
103-
FF_ESR = "NotSupportedError")
102+
FF = "NotSupportedError/DOMException",
103+
FF_ESR = "NotSupportedError/DOMException")
104104
public void create_createEvent() throws Exception {
105105
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_
106106
+ "<html><head><script>\n"
@@ -123,8 +123,8 @@ public void create_createEvent() throws Exception {
123123
*/
124124
@Test
125125
@Alerts(DEFAULT = "no initCloseEvent",
126-
FF = "NotSupportedError",
127-
FF_ESR = "NotSupportedError")
126+
FF = "NotSupportedError/DOMException",
127+
FF_ESR = "NotSupportedError/DOMException")
128128
public void initCloseEvent() throws Exception {
129129
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_
130130
+ "<html><head><script>\n"

src/test/java/org/htmlunit/javascript/host/event/KeyboardEventTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,10 @@ public void initKeyEvent() throws Exception {
446446
FF_ESR = {"NotSupportedError/DOMException",
447447
"keydown, true, true, Fn, 0, true, true, true, true, 0, 0",
448448
"keyup, false, false, , 7, false, false, false, false, 0, 0"})
449-
@HtmlUnitNYI(CHROME = {"NotSupportedError",
449+
@HtmlUnitNYI(CHROME = {"NotSupportedError/DOMException",
450450
"keydown, true, true, Fn, 0, true, true, true, true, 0, 0",
451451
"keyup, false, false, , 7, false, false, false, false, 0, 0"},
452-
EDGE = {"NotSupportedError",
452+
EDGE = {"NotSupportedError/DOMException",
453453
"keydown, true, true, Fn, 0, true, true, true, true, 0, 0",
454454
"keyup, false, false, , 7, false, false, false, false, 0, 0"})
455455
public void initKeyboardEvent() throws Exception {

src/test/java/org/htmlunit/javascript/host/event/PopStateEventTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public void create_ctorWithDetails() throws Exception {
101101
*/
102102
@Test
103103
@Alerts(DEFAULT = {"[object PopStateEvent]", "null", "", "false", "false", "false", "null"},
104-
FF = "NotSupportedError",
105-
FF_ESR = "NotSupportedError")
104+
FF = "NotSupportedError/DOMException",
105+
FF_ESR = "NotSupportedError/DOMException")
106106
public void create_createEvent() throws Exception {
107107
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_
108108
+ "<html><head><script>\n"
@@ -125,8 +125,8 @@ public void create_createEvent() throws Exception {
125125
*/
126126
@Test
127127
@Alerts(DEFAULT = {"[object PopStateEvent]", "null", "", "false", "false", "false", "null"},
128-
FF = "NotSupportedError",
129-
FF_ESR = "NotSupportedError")
128+
FF = "NotSupportedError/DOMException",
129+
FF_ESR = "NotSupportedError/DOMException")
130130
public void setState() throws Exception {
131131
final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_
132132
+ "<html><head><script>\n"

src/test/java/org/htmlunit/javascript/host/html/HTMLTableRowElementTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public void insertCell_Two() throws Exception {
492492
* @throws Exception if the test fails
493493
*/
494494
@Test
495-
@Alerts({"2", "IndexSizeError"})
495+
@Alerts({"2", "IndexSizeError/DOMException"})
496496
public void insertCell_Three() throws Exception {
497497
insertCell("3");
498498
}

0 commit comments

Comments
 (0)