Chromium Code Reviews| OLD | NEW |
|---|---|
| (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-classes --harmony-sloppy --harmony-arrow-funct ions | |
|
rossberg
2015/04/09 13:40:17
You shouldn't need --harmony-classes anymore, it's
conradw
2015/04/09 16:53:08
Done.
| |
| 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 | |
| 10 function CheckStrongMode(code, strictThrowsDyn) { | |
| 11 if(strictThrowsDyn) { | |
|
rossberg
2015/04/09 13:40:17
Instead of having this tedious flag, I'd perhaps d
conradw
2015/04/09 16:53:08
Done.
| |
| 12 assertThrows("'use strict';\n" + code, TypeError); | |
| 13 } else { | |
| 14 assertDoesNotThrow("'use strict';\n" + code); | |
| 15 } | |
| 16 assertThrows("'use strong';\n" + code, SyntaxError); | |
| 17 assertThrows('"use strong";\n' + code, SyntaxError); | |
| 18 | |
| 19 var funcs = ["sloppy() { " + code + " }", | |
|
rossberg
2015/04/09 13:40:17
Hm, I'm not sure what this tests. The outer/inner
conradw
2015/04/09 16:53:08
Done, although without the sloppy case, since most
| |
| 20 "strict() { 'use strict'; " + code + " }"] | |
| 21 | |
| 22 for(var i = 0; i < funcs.length; i++) { | |
| 23 var func = funcs[i]; | |
| 24 CheckClassEnvironment(func); | |
| 25 func = "function " + func; | |
| 26 assertDoesNotThrow("'use strict';\n" + func, TypeError); | |
| 27 assertThrows("'use strong';\n" + func, SyntaxError); | |
| 28 | |
| 29 assertDoesNotThrow("\ | |
| 30 function outer() {\ | |
| 31 'use strict';\ | |
| 32 function inner() {\n" | |
| 33 + func + | |
| 34 "\n}\ | |
| 35 }"); | |
| 36 assertThrows("\ | |
| 37 function outer() {\ | |
| 38 'use strong';\ | |
| 39 function inner() {\n" | |
| 40 + func + | |
| 41 "\n}\ | |
| 42 }", SyntaxError); | |
| 43 } | |
| 44 var strongFunc = "strong() { 'use strong'; " + code + " }" | |
| 45 assertThrows("class C { " + strongFunc + " }", SyntaxError); | |
| 46 strongFunc = "function " + strongFunc; | |
| 47 assertThrows(strongFunc); | |
| 48 } | |
| 49 | |
| 50 function CheckClassEnvironment(code) { | |
| 51 var strictClass = "class C { " + code + " }"; | |
| 52 var strongClass = "class C { 'use strong'; " + code + " }"; | |
| 53 assertDoesNotThrow(strictClass); | |
| 54 assertThrows(strongClass, SyntaxError); | |
|
rossberg
2015/04/09 13:40:17
I don't think this should throw. Method names are
conradw
2015/04/09 16:53:08
You're right, and I'm ashamed to admit that the te
| |
| 55 } | |
| 56 | |
| 57 // Binding 'undefined' | |
| 58 CheckStrongMode("var undefined = 0;", false) | |
| 59 CheckStrongMode("let undefined = 0;", false) | |
| 60 CheckStrongMode("const undefined = 0;", false) | |
|
rossberg
2015/04/09 13:40:17
Perhaps also add
let undefined;
let x, y = 0,
conradw
2015/04/09 16:53:08
Done.
| |
| 61 | |
| 62 // Function named 'undefined'. | |
| 63 CheckStrongMode("function undefined() {}", false); | |
| 64 CheckClassEnvironment("undefined() {}"); | |
| 65 assertThrows("function undefined() {'use strong';}", SyntaxError); | |
| 66 | |
| 67 // Function parameter named 'undefined'. | |
| 68 CheckStrongMode("function foo(a, b, undefined, c, d) {}", false); | |
| 69 CheckClassEnvironment("foo(a, b, undefined, c, d) {}"); | |
| 70 assertThrows("function foo(a, b, undefined, c, d) {'use strong';}", | |
| 71 SyntaxError); | |
| 72 | |
| 73 // FunctionExpression named 'undefined'; | |
|
rossberg
2015/04/09 13:40:17
Some more cases: generators and methods with undef
conradw
2015/04/09 16:53:08
Done.
| |
| 74 CheckStrongMode("(function undefined() {})", false); | |
| 75 assertThrows("(function undefined() {'use strong';})", SyntaxError); | |
| 76 | |
| 77 // Arrow function expression with 'undefined' param | |
| 78 // TODO(conradw): Checking arrow function heads is hard to modify just now | |
| 79 // CheckStrongMode("(undefined => {return})", false); | |
| 80 // assertThrows("(undefined => {'use strong';})"); | |
| 81 | |
| 82 // Class declaration named 'undefined' | |
| 83 CheckStrongMode("class undefined {}", false); | |
| 84 assertThrows("class undefined {'use strong'}", SyntaxError); | |
| 85 | |
| 86 //ClassExpression named 'undefined' | |
| 87 CheckStrongMode("(class undefined {})", false); | |
| 88 assertThrows("(class undefined {'use strong'})", SyntaxError); | |
| 89 | |
| 90 // Binding/assigning to 'undefined' in for | |
| 91 CheckStrongMode("for(undefined = 0;false;);", true) | |
| 92 CheckStrongMode("for(var undefined = 0;false;);", false) | |
| 93 CheckStrongMode("for(let undefined = 0;false;);", false) | |
| 94 CheckStrongMode("for(const undefined = 0;false;);", false) | |
| 95 | |
| 96 // Binding/assigning to 'undefined' in for-in | |
| 97 CheckStrongMode("for(undefined in {});", false) | |
| 98 CheckStrongMode("for(var undefined in {});", false) | |
| 99 CheckStrongMode("for(let undefined in {});", false) | |
| 100 CheckStrongMode("for(const undefined in {});", false) | |
| 101 | |
| 102 // Binding/assigning to 'undefined' in for-of | |
| 103 CheckStrongMode("for(undefined of []);", false) | |
| 104 CheckStrongMode("for(var undefined of []);", false) | |
| 105 CheckStrongMode("for(let undefined of []);", false) | |
| 106 CheckStrongMode("for(const undefined of []);", false) | |
| 107 | |
| 108 // Property accessor parameter named 'undefined'. | |
| 109 CheckStrongMode("let o = { set foo(undefined) {} }", false); | |
| 110 assertThrows("let o = { set foo(undefined) {'use strong';} }", SyntaxError); | |
| 111 | |
| 112 // catch(undefined) | |
| 113 CheckStrongMode("try{}catch(undefined){};", false); | |
|
rossberg
2015/04/09 13:40:17
Nit: no reason to be cheap with spaces. :)
conradw
2015/04/09 16:53:08
Done.
| |
| 114 | |
| 115 // Assignment to undefined | |
| 116 CheckStrongMode("undefined = 0;", true); | |
| 117 CheckStrongMode("print(undefined = 0);", true); | |
| 118 CheckStrongMode("let x = undefined = 0;", true); | |
| 119 | |
| 120 // Compound assignment to undefined | |
| 121 CheckStrongMode("undefined *= 0;", true); | |
| 122 CheckStrongMode("undefined /= 0;", true); | |
| 123 CheckStrongMode("print(undefined %= 0);", true); | |
| 124 CheckStrongMode("let x = undefined += 0;", true); | |
| 125 CheckStrongMode("let x = undefined -= 0;", true); | |
| 126 CheckStrongMode("undefined <<= 0;", true); | |
| 127 CheckStrongMode("undefined >>= 0;",true); | |
| 128 CheckStrongMode("print(undefined >>>= 0);", true); | |
| 129 CheckStrongMode("print(undefined &= 0);", true); | |
| 130 CheckStrongMode("let x = undefined ^= 0;", true); | |
| 131 CheckStrongMode("let x = undefined |= 0;", true); | |
| 132 | |
| 133 // Postfix increment with undefined | |
| 134 CheckStrongMode("undefined++;", true); | |
| 135 CheckStrongMode("print(undefined++);", true); | |
| 136 CheckStrongMode("let x = undefined++;", true); | |
| 137 | |
| 138 // Postfix decrement with undefined | |
| 139 CheckStrongMode("undefined--;", true); | |
| 140 CheckStrongMode("print(undefined--);", true); | |
| 141 CheckStrongMode("let x = undefined--;", true); | |
| 142 | |
| 143 // Prefix increment with undefined | |
| 144 CheckStrongMode("++undefined;", true); | |
| 145 CheckStrongMode("print(++undefined);", true); | |
| 146 CheckStrongMode("let x = ++undefined;", true); | |
| 147 | |
| 148 // Prefix decrement with undefined | |
| 149 CheckStrongMode("--undefined;", true); | |
| 150 CheckStrongMode("print(--undefined);", true); | |
| 151 CheckStrongMode("let x = --undefined;", true); | |
| 152 | |
| 153 // Function constructor: 'undefined' parameter name. | |
| 154 assertDoesNotThrow(function() { | |
| 155 Function("undefined", ""); | |
| 156 }); | |
| 157 assertThrows(function() { | |
| 158 Function("undefined", "'use strong';"); | |
| 159 }, SyntaxError); | |
| OLD | NEW |