Chromium Code Reviews| Index: test/mjsunit/strong/undefined.js |
| diff --git a/test/mjsunit/strong/undefined.js b/test/mjsunit/strong/undefined.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dbc6adeb4a79df93410fc97b9f0fa1452ee9b4ea |
| --- /dev/null |
| +++ b/test/mjsunit/strong/undefined.js |
| @@ -0,0 +1,159 @@ |
| +// Copyright 2014 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Flags: --strong-mode --harmony-classes --harmony-sloppy --harmony-arrow-functions |
|
rossberg
2015/04/09 13:40:17
You shouldn't need --harmony-classes anymore, it's
conradw
2015/04/09 16:53:08
Done.
|
| + |
| +// Repurposing the strict mode 'eval' and 'arguments' tests to test for correct |
| +// behaviour of 'undefined' as an identifier in strong mode. |
| + |
| +function CheckStrongMode(code, strictThrowsDyn) { |
| + 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.
|
| + assertThrows("'use strict';\n" + code, TypeError); |
| + } else { |
| + assertDoesNotThrow("'use strict';\n" + code); |
| + } |
| + assertThrows("'use strong';\n" + code, SyntaxError); |
| + assertThrows('"use strong";\n' + code, SyntaxError); |
| + |
| + 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
|
| + "strict() { 'use strict'; " + code + " }"] |
| + |
| + for(var i = 0; i < funcs.length; i++) { |
| + var func = funcs[i]; |
| + CheckClassEnvironment(func); |
| + func = "function " + func; |
| + assertDoesNotThrow("'use strict';\n" + func, TypeError); |
| + assertThrows("'use strong';\n" + func, SyntaxError); |
| + |
| + assertDoesNotThrow("\ |
| + function outer() {\ |
| + 'use strict';\ |
| + function inner() {\n" |
| + + func + |
| + "\n}\ |
| + }"); |
| + assertThrows("\ |
| + function outer() {\ |
| + 'use strong';\ |
| + function inner() {\n" |
| + + func + |
| + "\n}\ |
| + }", SyntaxError); |
| + } |
| + var strongFunc = "strong() { 'use strong'; " + code + " }" |
| + assertThrows("class C { " + strongFunc + " }", SyntaxError); |
| + strongFunc = "function " + strongFunc; |
| + assertThrows(strongFunc); |
| +} |
| + |
| +function CheckClassEnvironment(code) { |
| + var strictClass = "class C { " + code + " }"; |
| + var strongClass = "class C { 'use strong'; " + code + " }"; |
| + assertDoesNotThrow(strictClass); |
| + 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
|
| +} |
| + |
| +// Binding 'undefined' |
| +CheckStrongMode("var undefined = 0;", false) |
| +CheckStrongMode("let undefined = 0;", false) |
| +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.
|
| + |
| +// Function named 'undefined'. |
| +CheckStrongMode("function undefined() {}", false); |
| +CheckClassEnvironment("undefined() {}"); |
| +assertThrows("function undefined() {'use strong';}", SyntaxError); |
| + |
| +// Function parameter named 'undefined'. |
| +CheckStrongMode("function foo(a, b, undefined, c, d) {}", false); |
| +CheckClassEnvironment("foo(a, b, undefined, c, d) {}"); |
| +assertThrows("function foo(a, b, undefined, c, d) {'use strong';}", |
| + SyntaxError); |
| + |
| +// 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.
|
| +CheckStrongMode("(function undefined() {})", false); |
| +assertThrows("(function undefined() {'use strong';})", SyntaxError); |
| + |
| +// Arrow function expression with 'undefined' param |
| +// TODO(conradw): Checking arrow function heads is hard to modify just now |
| +// CheckStrongMode("(undefined => {return})", false); |
| +// assertThrows("(undefined => {'use strong';})"); |
| + |
| +// Class declaration named 'undefined' |
| +CheckStrongMode("class undefined {}", false); |
| +assertThrows("class undefined {'use strong'}", SyntaxError); |
| + |
| +//ClassExpression named 'undefined' |
| +CheckStrongMode("(class undefined {})", false); |
| +assertThrows("(class undefined {'use strong'})", SyntaxError); |
| + |
| +// Binding/assigning to 'undefined' in for |
| +CheckStrongMode("for(undefined = 0;false;);", true) |
| +CheckStrongMode("for(var undefined = 0;false;);", false) |
| +CheckStrongMode("for(let undefined = 0;false;);", false) |
| +CheckStrongMode("for(const undefined = 0;false;);", false) |
| + |
| +// Binding/assigning to 'undefined' in for-in |
| +CheckStrongMode("for(undefined in {});", false) |
| +CheckStrongMode("for(var undefined in {});", false) |
| +CheckStrongMode("for(let undefined in {});", false) |
| +CheckStrongMode("for(const undefined in {});", false) |
| + |
| +// Binding/assigning to 'undefined' in for-of |
| +CheckStrongMode("for(undefined of []);", false) |
| +CheckStrongMode("for(var undefined of []);", false) |
| +CheckStrongMode("for(let undefined of []);", false) |
| +CheckStrongMode("for(const undefined of []);", false) |
| + |
| +// Property accessor parameter named 'undefined'. |
| +CheckStrongMode("let o = { set foo(undefined) {} }", false); |
| +assertThrows("let o = { set foo(undefined) {'use strong';} }", SyntaxError); |
| + |
| +// catch(undefined) |
| +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.
|
| + |
| +// Assignment to undefined |
| +CheckStrongMode("undefined = 0;", true); |
| +CheckStrongMode("print(undefined = 0);", true); |
| +CheckStrongMode("let x = undefined = 0;", true); |
| + |
| +// Compound assignment to undefined |
| +CheckStrongMode("undefined *= 0;", true); |
| +CheckStrongMode("undefined /= 0;", true); |
| +CheckStrongMode("print(undefined %= 0);", true); |
| +CheckStrongMode("let x = undefined += 0;", true); |
| +CheckStrongMode("let x = undefined -= 0;", true); |
| +CheckStrongMode("undefined <<= 0;", true); |
| +CheckStrongMode("undefined >>= 0;",true); |
| +CheckStrongMode("print(undefined >>>= 0);", true); |
| +CheckStrongMode("print(undefined &= 0);", true); |
| +CheckStrongMode("let x = undefined ^= 0;", true); |
| +CheckStrongMode("let x = undefined |= 0;", true); |
| + |
| +// Postfix increment with undefined |
| +CheckStrongMode("undefined++;", true); |
| +CheckStrongMode("print(undefined++);", true); |
| +CheckStrongMode("let x = undefined++;", true); |
| + |
| +// Postfix decrement with undefined |
| +CheckStrongMode("undefined--;", true); |
| +CheckStrongMode("print(undefined--);", true); |
| +CheckStrongMode("let x = undefined--;", true); |
| + |
| +// Prefix increment with undefined |
| +CheckStrongMode("++undefined;", true); |
| +CheckStrongMode("print(++undefined);", true); |
| +CheckStrongMode("let x = ++undefined;", true); |
| + |
| +// Prefix decrement with undefined |
| +CheckStrongMode("--undefined;", true); |
| +CheckStrongMode("print(--undefined);", true); |
| +CheckStrongMode("let x = --undefined;", true); |
| + |
| +// Function constructor: 'undefined' parameter name. |
| +assertDoesNotThrow(function() { |
| + Function("undefined", ""); |
| +}); |
| +assertThrows(function() { |
| + Function("undefined", "'use strong';"); |
| +}, SyntaxError); |