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

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

Issue 8139027: Version 3.6.5 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: '' Created 9 years, 2 months 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/global-const-var-conflicts.js ('k') | test/mjsunit/harmony/proxies.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 29 matching lines...) Expand all
40 } 40 }
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 // 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
52 // the code. Thus the generated function is not called here.
50 function TestLocalThrows(str, expect) { 53 function TestLocalThrows(str, expect) {
51 assertThrows("(function(){" + str + "})()", expect); 54 assertThrows("(function(){" + str + "})", expect);
52 } 55 }
53 56
54 function TestLocalDoesNotThrow(str) { 57 function TestLocalDoesNotThrow(str) {
55 assertDoesNotThrow("(function(){" + str + "})()"); 58 assertDoesNotThrow("(function(){" + str + "})()");
56 } 59 }
57 60
58 // Unprotected statement 61 // Test let declarations statement positions.
59 TestLocalThrows("if (true) let x;", SyntaxError); 62 TestLocalThrows("if (true) let x;", SyntaxError);
63 TestLocalThrows("if (true) {} else let x;", SyntaxError);
60 TestLocalThrows("do let x; while (false)", SyntaxError); 64 TestLocalThrows("do let x; while (false)", SyntaxError);
61 TestLocalThrows("while (false) let x;", SyntaxError); 65 TestLocalThrows("while (false) let x;", SyntaxError);
66 TestLocalThrows("label: let x;", SyntaxError);
67 TestLocalThrows("for (;false;) let x;", SyntaxError);
68 TestLocalThrows("switch (true) { case true: let x; }", SyntaxError);
69 TestLocalThrows("switch (true) { default: let x; }", SyntaxError);
62 70
71 // Test var declarations statement positions.
63 TestLocalDoesNotThrow("if (true) var x;"); 72 TestLocalDoesNotThrow("if (true) var x;");
73 TestLocalDoesNotThrow("if (true) {} else var x;");
64 TestLocalDoesNotThrow("do var x; while (false)"); 74 TestLocalDoesNotThrow("do var x; while (false)");
65 TestLocalDoesNotThrow("while (false) var x;"); 75 TestLocalDoesNotThrow("while (false) var x;");
76 TestLocalDoesNotThrow("label: var x;");
77 TestLocalDoesNotThrow("for (;false;) var x;");
78 TestLocalDoesNotThrow("switch (true) { case true: var x; }");
79 TestLocalDoesNotThrow("switch (true) { default: var x; }");
80
81 // Test function declarations in source element and
82 // non-strict statement positions.
83 function f() {
84 // Non-strict source element positions.
85 function g0() {
86 "use strict";
87 // Strict source element positions.
88 function h() { }
89 {
90 function h1() { }
91 }
92 }
93 {
94 function g1() { }
95 }
96 // Non-strict statement positions.
97 if (true) function g2() { }
98 if (true) {} else function g3() { }
99 do function g4() { } while (false)
100 while (false) function g5() { }
101 label: function g6() { }
102 for (;false;) function g7() { }
103 switch (true) { case true: function g8() { } }
104 switch (true) { default: function g9() { } }
105 }
106 f();
107
108 // Test function declarations in statement position in strict mode.
109 TestLocalThrows("function f() { 'use strict'; if (true) function g() {}", Syntax Error);
110 TestLocalThrows("function f() { 'use strict'; if (true) {} else function g() {}" , SyntaxError);
111 TestLocalThrows("function f() { 'use strict'; do function g() {} while (false)", SyntaxError);
112 TestLocalThrows("function f() { 'use strict'; while (false) function g() {}", Sy ntaxError);
113 TestLocalThrows("function f() { 'use strict'; label: function g() {}", SyntaxErr or);
114 TestLocalThrows("function f() { 'use strict'; for (;false;) function g() {}", Sy ntaxError);
115 TestLocalThrows("function f() { 'use strict'; switch (true) { case true: functio n g() {} }", SyntaxError);
116 TestLocalThrows("function f() { 'use strict'; switch (true) { default: function g() {} }", SyntaxError);
OLDNEW
« no previous file with comments | « test/mjsunit/global-const-var-conflicts.js ('k') | test/mjsunit/harmony/proxies.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698