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

Side by Side Diff: test/mjsunit/strong/undefined.js

Issue 1070633002: [strong] Implement static restrictions on binding/assignment to 'undefined' identifier. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: improve tests (rebase, only undefined.js has changed) Created 5 years, 8 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 | « src/preparser.cc ('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 2014 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: --strong-mode --harmony-sloppy --harmony-arrow-functions
6
7 // Repurposing the strict mode 'eval' and 'arguments' tests to test for correct
8 // behaviour of 'undefined' as an identifier in strong mode.
9 "use strict";
10
11 function CheckStrongMode(code) {
12 assertThrows("'use strict'; " + code + "; throw new TypeError();", TypeError);
rossberg 2015/04/10 07:31:28 I think you can drop these 3 lines now, they are a
conradw 2015/04/10 11:02:06 Done.
13 assertThrows("'use strong'; " + code, SyntaxError);
14 assertThrows('"use strong"; ' + code, SyntaxError);
15
16 let strictContexts = [
17 ["'use strict';", ""],
18 ["function outer() { 'use strict';", "}"],
19 ["function outer() { 'use strict'; function inner() {", "}}"],
20 ["class C { m() {", "} }"]
21 ]
22 let strongContexts = [
23 ["'use strong';", ""],
24 ["function outer() { 'use strong';", "}"],
25 ["function outer() { 'use strong'; function inner() {", "}}"],
26 ["class C { m() { 'use strong';", "} }"]
27 ]
28
29 for (let context of strictContexts) {
30 assertThrows(context[0] + code + context[1] + "; throw new TypeError()",
31 TypeError);
32 }
33 for (let context of strongContexts) {
34 assertThrows(context[0] + code + context[1], SyntaxError);
35 }
36 }
37
38 // Binding 'undefined'
39 CheckStrongMode("var undefined;");
40 CheckStrongMode("let undefined;");
41 CheckStrongMode("var undefined = 0;");
42 CheckStrongMode("let undefined = 0;");
43 CheckStrongMode("const undefined = 0;");
44 CheckStrongMode("var x, y = 0, undefined;");
45 CheckStrongMode("let x, y = 0, undefined;");
46
47 // Function named 'undefined'.
48 CheckStrongMode("function undefined() {}");
49 assertThrows("function undefined() {'use strong';}", SyntaxError);
50
51 // Generator Function named 'undefined';
52 CheckStrongMode("function* undefined() {}");
53 assertThrows("function* undefined() {'use strong';}", SyntaxError);
54
55 // FunctionExpression named 'undefined';
56 CheckStrongMode("(function undefined() {})");
57 assertThrows("(function undefined() {'use strong';})", SyntaxError);
58
59 // Generator function expression named 'undefined';
60 CheckStrongMode("(function* undefined() {})");
61 assertThrows("(function* undefined() {'use strong';})", SyntaxError);
62
63 //Function parameter named 'undefined'.
64 CheckStrongMode("function foo(a, b, undefined, c, d) {}");
65 assertThrows("function foo(a, b, undefined, c, d) {'use strong';}",
66 SyntaxError);
67 assertThrows("(function foo(a, b, undefined, c, d) {'use strong';})",
68 SyntaxError);
69 assertThrows("class C { foo(a, b, undefined, c, d) {'use strong';} }",
rossberg 2015/04/10 07:31:28 Also add a case for methods in object literals:
conradw 2015/04/10 11:02:05 Done.
70 SyntaxError);
71
72 // Generator function parameter named 'undefined'.
73 CheckStrongMode("function* foo(a, b, undefined, c, d) {}");
74 assertThrows("function* foo(a, b, undefined, c, d) {'use strong';}",
75 SyntaxError);
76 assertThrows("(function* foo(a, b, undefined, c, d) {'use strong';})",
77 SyntaxError);
78 assertThrows("class C { *foo(a, b, undefined, c, d) {'use strong';} }",
79 SyntaxError);
80
81 // Arrow function expression with 'undefined' param
82 // TODO(conradw): Checking arrow function heads is hard to modify just now
83 // CheckStrongMode("(undefined => {return})");
84 // assertThrows("(undefined => {'use strong';})");
85
86 // Class declaration named 'undefined'
87 CheckStrongMode("class undefined {}");
88 assertThrows("class undefined {'use strong'}", SyntaxError);
89
90 //ClassExpression named 'undefined'
91 CheckStrongMode("(class undefined {})");
92 assertThrows("(class undefined {'use strong'})", SyntaxError);
93
94 // Binding/assigning to 'undefined' in for
95 CheckStrongMode("for(undefined = 0;false;);");
96 CheckStrongMode("for(var undefined = 0;false;);");
97 CheckStrongMode("for(let undefined = 0;false;);");
98 CheckStrongMode("for(const undefined = 0;false;);");
99
100 // Binding/assigning to 'undefined' in for-in
101 CheckStrongMode("for(undefined in {});");
102 CheckStrongMode("for(var undefined in {});");
103 CheckStrongMode("for(let undefined in {});");
104 CheckStrongMode("for(const undefined in {});");
105
106 // Binding/assigning to 'undefined' in for-of
107 CheckStrongMode("for(undefined of []);");
108 CheckStrongMode("for(var undefined of []);");
109 CheckStrongMode("for(let undefined of []);");
110 CheckStrongMode("for(const undefined of []);");
111
112 // Property accessor parameter named 'undefined'.
113 CheckStrongMode("let o = { set foo(undefined) {} }");
114 assertThrows("let o = { set foo(undefined) {'use strong';} }", SyntaxError);
115
116 // catch(undefined)
117 CheckStrongMode("try {} catch(undefined) {};");
118
119 // Assignment to undefined
120 CheckStrongMode("undefined = 0;");
121 CheckStrongMode("print(undefined = 0);");
122 CheckStrongMode("let x = undefined = 0;");
123
124 // Compound assignment to undefined
125 CheckStrongMode("undefined *= 0;");
126 CheckStrongMode("undefined /= 0;");
127 CheckStrongMode("print(undefined %= 0);");
128 CheckStrongMode("let x = undefined += 0;");
129 CheckStrongMode("let x = undefined -= 0;");
130 CheckStrongMode("undefined <<= 0;");
131 CheckStrongMode("undefined >>= 0;");
132 CheckStrongMode("print(undefined >>>= 0);");
133 CheckStrongMode("print(undefined &= 0);");
134 CheckStrongMode("let x = undefined ^= 0;");
135 CheckStrongMode("let x = undefined |= 0;");
136
137 // Postfix increment with undefined
138 CheckStrongMode("undefined++;");
139 CheckStrongMode("print(undefined++);");
140 CheckStrongMode("let x = undefined++;");
141
142 // Postfix decrement with undefined
143 CheckStrongMode("undefined--;");
144 CheckStrongMode("print(undefined--);");
145 CheckStrongMode("let x = undefined--;");
146
147 // Prefix increment with undefined
148 CheckStrongMode("++undefined;");
149 CheckStrongMode("print(++undefined);");
150 CheckStrongMode("let x = ++undefined;");
151
152 // Prefix decrement with undefined
153 CheckStrongMode("--undefined;");
154 CheckStrongMode("print(--undefined);");
155 CheckStrongMode("let x = --undefined;");
156
157 // Function constructor: 'undefined' parameter name.
158 assertDoesNotThrow(function() {
159 Function("undefined", "");
160 });
161 assertThrows(function() {
162 Function("undefined", "'use strong';");
163 }, SyntaxError);
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698