OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 30 matching lines...) Expand all Loading... | |
41 | 41 |
42 assertEquals(undefined, x); | 42 assertEquals(undefined, x); |
43 assertEquals(2,y); | 43 assertEquals(2,y); |
44 | 44 |
45 if (true) { | 45 if (true) { |
46 let y; | 46 let y; |
47 assertEquals(undefined, y); | 47 assertEquals(undefined, y); |
48 } | 48 } |
49 | 49 |
50 function TestLocalThrows(str, expect) { | 50 function TestLocalThrows(str, expect) { |
51 assertThrows("(function(){" + str + "})()", expect); | 51 assertThrows("(function(){" + str + "})()", expect); |
Lasse Reichstein
2011/09/21 10:29:34
If this is early errors (and I guess it is), you s
Steven
2011/09/21 12:03:28
Yes they are early errors. Done.
On 2011/09/21 10:
| |
52 } | 52 } |
53 | 53 |
54 function TestLocalDoesNotThrow(str) { | 54 function TestLocalDoesNotThrow(str) { |
55 assertDoesNotThrow("(function(){" + str + "})()"); | 55 assertDoesNotThrow("(function(){" + str + "})()"); |
Lasse Reichstein
2011/09/21 10:29:34
But keep the call here. It should never fail, not
Steven
2011/09/21 12:03:28
Done.
| |
56 } | 56 } |
57 | 57 |
58 // Unprotected statement | 58 // Test let declarations statement positions. |
59 TestLocalThrows("if (true) let x;", SyntaxError); | 59 TestLocalThrows("if (true) let x;", SyntaxError); |
60 TestLocalThrows("if (true) {} else let x;", SyntaxError); | |
60 TestLocalThrows("do let x; while (false)", SyntaxError); | 61 TestLocalThrows("do let x; while (false)", SyntaxError); |
61 TestLocalThrows("while (false) let x;", SyntaxError); | 62 TestLocalThrows("while (false) let x;", SyntaxError); |
63 TestLocalThrows("label: let x;", SyntaxError); | |
64 TestLocalThrows("for (;false;) let x;", SyntaxError); | |
65 TestLocalThrows("switch (true) { case true: let x; }", SyntaxError); | |
66 TestLocalThrows("switch (true) { default: let x; }", SyntaxError); | |
62 | 67 |
68 // Test var declarations statement positions. | |
63 TestLocalDoesNotThrow("if (true) var x;"); | 69 TestLocalDoesNotThrow("if (true) var x;"); |
70 TestLocalDoesNotThrow("if (true) {} else var x;"); | |
64 TestLocalDoesNotThrow("do var x; while (false)"); | 71 TestLocalDoesNotThrow("do var x; while (false)"); |
65 TestLocalDoesNotThrow("while (false) var x;"); | 72 TestLocalDoesNotThrow("while (false) var x;"); |
73 TestLocalDoesNotThrow("label: var x;"); | |
74 TestLocalDoesNotThrow("for (;false;) var x;"); | |
75 TestLocalDoesNotThrow("switch (true) { case true: var x; }"); | |
76 TestLocalDoesNotThrow("switch (true) { default: var x; }"); | |
77 | |
78 // Test function declarations in source element and | |
79 // non-strict statement positions. | |
Lasse Reichstein
2011/09/21 10:29:34
Can you have a non-strict statement position in ha
Steven
2011/09/21 12:03:28
Indeed the harmony proposals actually take the ES5
| |
80 function f() { | |
81 // Non-strict source element positions. | |
82 function g0() { | |
83 "use strict"; | |
84 // Strict source element positions. | |
85 function h() { } | |
86 { | |
87 function h1() { } | |
88 } | |
89 } | |
90 { | |
91 function g1() { } | |
92 } | |
93 // Non-strict statement positions. | |
94 if (true) function g2() { } | |
95 if (true) {} else function g3() { } | |
96 do function g4() { } while (false) | |
97 while (false) function g5() { } | |
98 label: function g6() { } | |
99 for (;false;) function g7() { } | |
100 switch (true) { case true: function g8() { } } | |
101 switch (true) { default: function g9() { } } | |
102 | |
103 } | |
Lasse Reichstein
2011/09/21 10:29:34
Call f here, to ensure that it isn't lazily compil
Steven
2011/09/21 12:03:28
Done.
| |
104 | |
105 // Test function declarations in statement position in strict mode. | |
106 TestLocalThrows("function f() { 'use strict'; if (true) function g() {}", Syntax Error); | |
107 TestLocalThrows("function f() { 'use strict'; if (true) {} else function g() {}" , SyntaxError); | |
108 TestLocalThrows("function f() { 'use strict'; do function g() {} while (false)", SyntaxError); | |
109 TestLocalThrows("function f() { 'use strict'; while (false) function g() {}", Sy ntaxError); | |
110 TestLocalThrows("function f() { 'use strict'; label: function g() {}", SyntaxErr or); | |
111 TestLocalThrows("function f() { 'use strict'; for (;false;) function g() {}", Sy ntaxError); | |
112 TestLocalThrows("function f() { 'use strict'; switch (true) { case true: functio n g() {} }", SyntaxError); | |
113 TestLocalThrows("function f() { 'use strict'; switch (true) { default: function g() {} }", SyntaxError); | |
OLD | NEW |