Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: test/mjsunit/harmony/block-let-declaration.js

Issue 7992005: Block scoped const variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments, function variable mode, preparser. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/mjsunit/harmony/block-conflicts.js ('k') | test/mjsunit/harmony/block-let-semantics.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --harmony-scoping 28 // Flags: --harmony-scoping
29 29
30 // Test let declarations in various settings. 30 // Test let declarations in various settings.
31 31
32 // Global 32 // Global
33 let x; 33 let x;
34 let y = 2; 34 let y = 2;
35 const z = 4;
35 36
36 // Block local 37 // Block local
37 { 38 {
38 let y; 39 let y;
39 let x = 3; 40 let x = 3;
41 const z = 5;
40 } 42 }
41 43
42 assertEquals(undefined, x); 44 assertEquals(undefined, x);
43 assertEquals(2,y); 45 assertEquals(2,y);
46 assertEquals(4,z);
44 47
45 if (true) { 48 if (true) {
46 let y; 49 let y;
47 assertEquals(undefined, y); 50 assertEquals(undefined, y);
48 } 51 }
49 52
50 // Invalid declarations are early errors in harmony mode and thus should trigger 53 // Invalid declarations are early errors in harmony mode and thus should trigger
51 // an exception in eval code during parsing, before even compiling or executing 54 // an exception in eval code during parsing, before even compiling or executing
52 // the code. Thus the generated function is not called here. 55 // the code. Thus the generated function is not called here.
53 function TestLocalThrows(str, expect) { 56 function TestLocalThrows(str, expect) {
54 assertThrows("(function(){" + str + "})", expect); 57 assertThrows("(function(){" + str + "})", expect);
55 } 58 }
56 59
57 function TestLocalDoesNotThrow(str) { 60 function TestLocalDoesNotThrow(str) {
58 assertDoesNotThrow("(function(){" + str + "})()"); 61 assertDoesNotThrow("(function(){" + str + "})()");
59 } 62 }
60 63
61 // Test let declarations statement positions. 64 // Test let declarations in statement positions.
62 TestLocalThrows("if (true) let x;", SyntaxError); 65 TestLocalThrows("if (true) let x;", SyntaxError);
63 TestLocalThrows("if (true) {} else let x;", SyntaxError); 66 TestLocalThrows("if (true) {} else let x;", SyntaxError);
64 TestLocalThrows("do let x; while (false)", SyntaxError); 67 TestLocalThrows("do let x; while (false)", SyntaxError);
65 TestLocalThrows("while (false) let x;", SyntaxError); 68 TestLocalThrows("while (false) let x;", SyntaxError);
66 TestLocalThrows("label: let x;", SyntaxError); 69 TestLocalThrows("label: let x;", SyntaxError);
67 TestLocalThrows("for (;false;) let x;", SyntaxError); 70 TestLocalThrows("for (;false;) let x;", SyntaxError);
68 TestLocalThrows("switch (true) { case true: let x; }", SyntaxError); 71 TestLocalThrows("switch (true) { case true: let x; }", SyntaxError);
69 TestLocalThrows("switch (true) { default: let x; }", SyntaxError); 72 TestLocalThrows("switch (true) { default: let x; }", SyntaxError);
70 73
71 // Test var declarations statement positions. 74 // Test const declarations with initialisers in statement positions.
75 TestLocalThrows("if (true) const x = 1;", SyntaxError);
76 TestLocalThrows("if (true) {} else const x = 1;", SyntaxError);
77 TestLocalThrows("do const x = 1; while (false)", SyntaxError);
78 TestLocalThrows("while (false) const x = 1;", SyntaxError);
79 TestLocalThrows("label: const x = 1;", SyntaxError);
80 TestLocalThrows("for (;false;) const x = 1;", SyntaxError);
81 TestLocalThrows("switch (true) { case true: const x = 1; }", SyntaxError);
82 TestLocalThrows("switch (true) { default: const x = 1; }", SyntaxError);
83
84 // Test const declarations without initialisers.
85 TestLocalThrows("const x;", SyntaxError);
86 TestLocalThrows("const x = 1, y;", SyntaxError);
87 TestLocalThrows("const x, y = 1;", SyntaxError);
88
89 // Test const declarations without initialisers in statement positions.
90 TestLocalThrows("if (true) const x;", SyntaxError);
91 TestLocalThrows("if (true) {} else const x;", SyntaxError);
92 TestLocalThrows("do const x; while (false)", SyntaxError);
93 TestLocalThrows("while (false) const x;", SyntaxError);
94 TestLocalThrows("label: const x;", SyntaxError);
95 TestLocalThrows("for (;false;) const x;", SyntaxError);
96 TestLocalThrows("switch (true) { case true: const x; }", SyntaxError);
97 TestLocalThrows("switch (true) { default: const x; }", SyntaxError);
98
99 // Test var declarations in statement positions.
72 TestLocalDoesNotThrow("if (true) var x;"); 100 TestLocalDoesNotThrow("if (true) var x;");
73 TestLocalDoesNotThrow("if (true) {} else var x;"); 101 TestLocalDoesNotThrow("if (true) {} else var x;");
74 TestLocalDoesNotThrow("do var x; while (false)"); 102 TestLocalDoesNotThrow("do var x; while (false)");
75 TestLocalDoesNotThrow("while (false) var x;"); 103 TestLocalDoesNotThrow("while (false) var x;");
76 TestLocalDoesNotThrow("label: var x;"); 104 TestLocalDoesNotThrow("label: var x;");
77 TestLocalDoesNotThrow("for (;false;) var x;"); 105 TestLocalDoesNotThrow("for (;false;) var x;");
78 TestLocalDoesNotThrow("switch (true) { case true: var x; }"); 106 TestLocalDoesNotThrow("switch (true) { case true: var x; }");
79 TestLocalDoesNotThrow("switch (true) { default: var x; }"); 107 TestLocalDoesNotThrow("switch (true) { default: var x; }");
80 108
81 // Test function declarations in source element and 109 // Test function declarations in source element and
(...skipping 16 matching lines...) Expand all
98 126
99 // Test function declarations in statement position in strict mode. 127 // Test function declarations in statement position in strict mode.
100 TestLocalThrows("function f() { if (true) function g() {}", SyntaxError); 128 TestLocalThrows("function f() { if (true) function g() {}", SyntaxError);
101 TestLocalThrows("function f() { if (true) {} else function g() {}", SyntaxError) ; 129 TestLocalThrows("function f() { if (true) {} else function g() {}", SyntaxError) ;
102 TestLocalThrows("function f() { do function g() {} while (false)", SyntaxError); 130 TestLocalThrows("function f() { do function g() {} while (false)", SyntaxError);
103 TestLocalThrows("function f() { while (false) function g() {}", SyntaxError); 131 TestLocalThrows("function f() { while (false) function g() {}", SyntaxError);
104 TestLocalThrows("function f() { label: function g() {}", SyntaxError); 132 TestLocalThrows("function f() { label: function g() {}", SyntaxError);
105 TestLocalThrows("function f() { for (;false;) function g() {}", SyntaxError); 133 TestLocalThrows("function f() { for (;false;) function g() {}", SyntaxError);
106 TestLocalThrows("function f() { switch (true) { case true: function g() {} }", S yntaxError); 134 TestLocalThrows("function f() { switch (true) { case true: function g() {} }", S yntaxError);
107 TestLocalThrows("function f() { switch (true) { default: function g() {} }", Syn taxError); 135 TestLocalThrows("function f() { switch (true) { default: function g() {} }", Syn taxError);
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/block-conflicts.js ('k') | test/mjsunit/harmony/block-let-semantics.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698