1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript;
16
17 import org.htmlunit.ScriptException;
18 import org.htmlunit.WebDriverTestCase;
19 import org.junit.jupiter.api.Test;
20
21
22
23
24
25
26
27 public class IEWeirdSyntaxTest extends WebDriverTestCase {
28
29
30
31
32 @Test
33 public void semicolon_before_finally() throws Exception {
34 doTestTryCatchFinally("", ";");
35 doTestTryCatchFinally("", "\n;\n");
36 doTestTryCatchFinally("", "\n;");
37 }
38
39
40
41
42 @Test
43 public void semicolon_before_catch() throws Exception {
44 doTestTryCatchFinally(";", "");
45 doTestTryCatchFinally("\n;\n", "");
46 }
47
48
49
50
51 @Test
52 public void semicolonAndComment_before_catchAndFinally() throws Exception {
53 doTestTryCatchFinally("// comment\n;\n", "");
54 doTestTryCatchFinally("", "// comment\n;\n");
55 doTestTryCatchFinally("", "// comment\n // other comment\n;\n");
56 doTestTryCatchFinally("", "// comment\n ; // other comment\n");
57 }
58
59 private void doTestTryCatchFinally(final String beforeCatch, final String beforeFinally) throws Exception {
60 final String html = "<html>\n"
61 + "<script>\n"
62 + " try {\n"
63 + " alert('1');\n"
64 + " }" + beforeCatch
65 + " catch(e) {\n"
66 + " alert('2');\n"
67 + " }" + beforeFinally
68 + " finally {\n"
69 + " alert('3');\n"
70 + " }\n"
71 + "</script>\n"
72 + "</html>";
73 doTestWithEvaluatorExceptionExcept(html);
74 }
75
76
77
78
79 @Test
80 public void windowDotHandlerFunction() throws Exception {
81 final String html = "<html>\n"
82 + "<head>\n"
83 + "<script>\n"
84 + " function window.onload() {\n"
85 + " alert(1);\n"
86 + " }\n"
87 + "</script>\n"
88 + "</head>\n"
89 + "<body></body></html>";
90 doTestWithEvaluatorExceptionExcept(html);
91 }
92
93 private void doTestWithEvaluatorExceptionExcept(final String html) throws Exception {
94 try {
95 loadPageWithAlerts2(html);
96 }
97 catch (final Exception e) {
98 if (!(e.getCause() instanceof ScriptException)) {
99 throw e;
100 }
101 }
102 }
103 }