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

Side by Side Diff: test/mjsunit/harmony/block-sloppy-function.js

Issue 1332873003: Implement sloppy-mode block-defined functions (Annex B 3.3) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Improve type clarity Created 5 years, 3 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
« no previous file with comments | « test/mjsunit/harmony/block-let-semantics-sloppy.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Flags: --no-legacy-const --harmony-sloppy --harmony-sloppy-let
6 // Flags: --harmony-sloppy-function --harmony-destructuring
7 // Flags: --harmony-rest-parameters
8
9 // Test Annex B 3.3 semantics for functions declared in blocks in sloppy mode.
10 // http://www.ecma-international.org/ecma-262/6.0/#sec-block-level-function-decl arations-web-legacy-compatibility-semantics
11
12 (function overridingLocalFunction() {
13 var x = [];
14 assertEquals('function', typeof f);
15 function f() {
16 x.push(1);
17 }
18 f();
19 {
20 f();
21 function f() {
22 x.push(2);
23 }
24 f();
25 }
26 f();
27 {
28 f();
29 function f() {
30 x.push(3);
31 }
32 f();
33 }
34 f();
35 assertArrayEquals([1, 2, 2, 2, 3, 3, 3], x);
36 })();
37
38 (function newFunctionBinding() {
39 var x = [];
40 assertEquals('undefined', typeof f);
41 {
42 f();
43 function f() {
44 x.push(2);
45 }
46 f();
47 }
48 f();
49 {
50 f();
51 function f() {
52 x.push(3);
53 }
54 f();
55 }
56 f();
57 assertArrayEquals([2, 2, 2, 3, 3, 3], x);
58 })();
59
60 (function shadowingLetDoesntBind() {
61 let f = 1;
62 assertEquals(1, f);
63 {
64 let y = 3;
65 function f() {
66 y = 2;
67 }
68 f();
69 assertEquals(2, y);
70 }
71 assertEquals(1, f);
72 })();
73
74 (function shadowingClassDoesntBind() {
75 class f { }
76 assertEquals('class f { }', f.toString());
77 {
78 let y = 3;
79 function f() {
80 y = 2;
81 }
82 f();
83 assertEquals(2, y);
84 }
85 assertEquals('class f { }', f.toString());
86 })();
87
88 (function shadowingConstDoesntBind() {
89 const f = 1;
90 assertEquals(1, f);
91 {
92 let y = 3;
93 function f() {
94 y = 2;
95 }
96 f();
97 assertEquals(2, y);
98 }
99 assertEquals(1, f);
100 })();
101
102 (function shadowingVarBinds() {
103 var f = 1;
104 assertEquals(1, f);
105 {
106 let y = 3;
107 function f() {
108 y = 2;
109 }
110 f();
111 assertEquals(2, y);
112 }
113 assertEquals('function', typeof f);
114 })();
115
116 (function conditional() {
117 if (true) {
118 function f() { return 1; }
119 } else {
120 function f() { return 2; }
121 }
122 assertEquals(1, f());
123
124 if (false) {
125 function g() { return 1; }
126 } else {
127 function g() { return 2; }
128 }
129 assertEquals(2, g());
130 })();
131
132 (function skipExecution() {
133 {
134 function f() { return 1; }
135 }
136 assertEquals(1, f());
137 {
138 function f() { return 2; }
139 }
140 assertEquals(2, f());
141 L: {
142 assertEquals(3, f());
143 break L;
144 function f() { return 3; }
145 }
146 assertEquals(2, f());
147 })();
148
149 // Test that hoisting from blocks doesn't happen in global scope
150 function globalUnhoisted() { return 0; }
151 {
152 function globalUnhoisted() { return 1; }
153 }
154 assertEquals(0, globalUnhoisted());
155
156 // Test that shadowing arguments is fine
157 (function shadowArguments(x) {
158 assertArrayEquals([1], arguments);
159 {
160 assertEquals('function', typeof arguments);
161 function arguments() {}
162 assertEquals('function', typeof arguments);
163 }
164 assertEquals('function', typeof arguments);
165 })(1);
166
167 // Shadow function parameter
168 (function shadowParameter(x) {
169 assertEquals(1, x);
170 {
171 function x() {}
172 }
173 assertEquals('function', typeof x);
174 })(1);
175
176 // Shadow function parameter
177 (function shadowDefaultParameter(x = 0) {
178 assertEquals(1, x);
179 {
180 function x() {}
181 }
182 // TODO(littledan): Once destructured parameters are no longer
183 // let-bound, enable this assertion. This is the core of the test.
184 // assertEquals('function', typeof x);
185 })(1);
186
187 (function shadowRestParameter(...x) {
188 assertArrayEquals([1], x);
189 {
190 function x() {}
191 }
192 // TODO(littledan): Once destructured parameters are no longer
193 // let-bound, enable this assertion. This is the core of the test.
194 // assertEquals('function', typeof x);
195 })(1);
196
197 assertThrows(function notInDefaultScope(x = y) {
198 {
199 function y() {}
200 }
201 assertEquals('function', typeof y);
202 assertEquals(x, undefined);
203 }, ReferenceError);
OLDNEW
« no previous file with comments | « test/mjsunit/harmony/block-let-semantics-sloppy.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698