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

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: 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
« src/preparser.h ('K') | « 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
6
7 //repurposing the strict mode 'eval' and 'arguments' tests to test for correct
rossberg 2015/04/08 11:30:11 Style nit: Spaces after // (here and below). Also,
conradw 2015/04/09 12:24:17 Done.
8 //behaviour of 'undefined' as an identifier in strong mode
rossberg 2015/04/08 11:30:11 Please add tests for: - bindings to undefined (va
conradw 2015/04/09 12:24:17 Done.
9
10 function CheckStrongMode(code, exception) {
11 assertDoesNotThrow("'use strict';\n" + code);
12 assertThrows("'use strong';\n" + code, exception);
13 assertThrows('"use strong";\n' + code, exception);
14 assertDoesNotThrow("\
15 function outer() {\
16 'use strict';\
17 function inner() {\n"
18 + code +
19 "\n}\
20 }");
21 assertThrows("\
22 function outer() {\
23 'use strong';\
24 function inner() {\n"
25 + code +
26 "\n}\
27 }", exception);
28 }
rossberg 2015/04/08 11:30:11 We also should have test contexts that are (strict
conradw 2015/04/09 12:24:17 Done.
29
30 function CheckFunctionConstructorStrongMode() {
31 var args = [];
32 for (var i = 0; i < arguments.length; i ++) {
rossberg 2015/04/08 11:30:11 With adding --harmony-rest-parameters to Flags you
conradw 2015/04/09 12:24:17 Acknowledged.
33 args[i] = arguments[i];
34 }
35 // Create non-strong function. No exception.
36 args[arguments.length] = "";
37 assertDoesNotThrow(function() {
38 Function.apply(this, args);
39 });
40 // Create strong mode function. Exception expected.
41 args[arguments.length] = "'use strong';";
42 assertThrows(function() {
43 Function.apply(this, args);
44 }, SyntaxError);
45 }
46
47 //Function named 'undefined'.
48 CheckStrongMode("function undefined() {}", SyntaxError);
49
50 // Function parameter named 'undefined'.
51 CheckStrongMode("function foo(a, b, undefined, c, d) {}", SyntaxError);
52
53 // Property accessor parameter named 'undefined'.
54 CheckStrongMode("let o = { set foo(undefined) {} }", SyntaxError);
55
56 //Function constructor: 'undefined' parameter name.
57 CheckFunctionConstructorStrongMode("undefined");
58
59 //catch(undefined)
60 CheckStrongMode("try{}catch(undefined){};", SyntaxError);
61
62 //Assignment to undefined
63 CheckStrongMode("function strong() { undefined = undefined; }", SyntaxError);
64 CheckStrongMode("function strong() { print(undefined = undefined); }", SyntaxErr or);
rossberg 2015/04/08 11:30:11 Style nit: line length (here and below)
conradw 2015/04/09 12:24:17 Done.
65 CheckStrongMode("function strong() { let x = undefined = undefined; }", SyntaxEr ror);
66
67 // Compound assignment to undefined
68 CheckStrongMode("function strong() { undefined *= undefined; }", SyntaxError);
69 CheckStrongMode("function strong() { undefined /= undefined; }", SyntaxError);
70 CheckStrongMode("function strong() { print(undefined %= undefined); }", SyntaxEr ror);
71 CheckStrongMode("function strong() { let x = undefined += undefined; }",
72 SyntaxError);
73 CheckStrongMode("function strong() { let x = undefined -= undefined; }",
74 SyntaxError);
75 CheckStrongMode("function strong() { undefined <<= undefined; }", SyntaxError);
76 CheckStrongMode("function strong() { undefined >>= undefined; }", SyntaxError);
77 CheckStrongMode("function strong() { print(undefined >>>= undefined); }",
78 SyntaxError);
79 CheckStrongMode("function strong() { print(undefined &= undefined); }",
80 SyntaxError);
81 CheckStrongMode("function strong() { let x = undefined ^= undefined; }",
82 SyntaxError);
83 CheckStrongMode("function strong() { let x = undefined |= undefined; }",
84 SyntaxError);
85
86 // Postfix increment with undefined
87 CheckStrongMode("function strong() { undefined++; }", SyntaxError);
88 CheckStrongMode("function strong() { print(undefined++); }", SyntaxError);
89 CheckStrongMode("function strong() { let x = undefined++; }", SyntaxError);
90
91 // Postfix decrement with undefined
92 CheckStrongMode("function strong() { undefined--; }", SyntaxError);
93 CheckStrongMode("function strong() { print(undefined--); }", SyntaxError);
94 CheckStrongMode("function strong() { let x = undefined--; }", SyntaxError);
95
96 // Prefix increment with undefined
97 CheckStrongMode("function strong() { ++undefined; }", SyntaxError);
98 CheckStrongMode("function strong() { print(++undefined); }", SyntaxError);
99 CheckStrongMode("function strong() { let x = ++undefined; }", SyntaxError);
100
101 // Prefix decrement with undefined
102 CheckStrongMode("function strong() { --undefined; }", SyntaxError);
103 CheckStrongMode("function strong() { print(--undefined); }", SyntaxError);
104 CheckStrongMode("function strong() { let x = --undefined; }", SyntaxError);
OLDNEW
« src/preparser.h ('K') | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698