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..d87dd88a4eaae2caff9a40af77d690e97e2a3bcd |
--- /dev/null |
+++ b/test/mjsunit/strong/undefined.js |
@@ -0,0 +1,163 @@ |
+// 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-sloppy --harmony-arrow-functions |
+ |
+// Repurposing the strict mode 'eval' and 'arguments' tests to test for correct |
+// behaviour of 'undefined' as an identifier in strong mode. |
+"use strict"; |
+ |
+function CheckStrongMode(code) { |
+ 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.
|
+ assertThrows("'use strong'; " + code, SyntaxError); |
+ assertThrows('"use strong"; ' + code, SyntaxError); |
+ |
+ let strictContexts = [ |
+ ["'use strict';", ""], |
+ ["function outer() { 'use strict';", "}"], |
+ ["function outer() { 'use strict'; function inner() {", "}}"], |
+ ["class C { m() {", "} }"] |
+ ] |
+ let strongContexts = [ |
+ ["'use strong';", ""], |
+ ["function outer() { 'use strong';", "}"], |
+ ["function outer() { 'use strong'; function inner() {", "}}"], |
+ ["class C { m() { 'use strong';", "} }"] |
+ ] |
+ |
+ for (let context of strictContexts) { |
+ assertThrows(context[0] + code + context[1] + "; throw new TypeError()", |
+ TypeError); |
+ } |
+ for (let context of strongContexts) { |
+ assertThrows(context[0] + code + context[1], SyntaxError); |
+ } |
+} |
+ |
+// Binding 'undefined' |
+CheckStrongMode("var undefined;"); |
+CheckStrongMode("let undefined;"); |
+CheckStrongMode("var undefined = 0;"); |
+CheckStrongMode("let undefined = 0;"); |
+CheckStrongMode("const undefined = 0;"); |
+CheckStrongMode("var x, y = 0, undefined;"); |
+CheckStrongMode("let x, y = 0, undefined;"); |
+ |
+// Function named 'undefined'. |
+CheckStrongMode("function undefined() {}"); |
+assertThrows("function undefined() {'use strong';}", SyntaxError); |
+ |
+// Generator Function named 'undefined'; |
+CheckStrongMode("function* undefined() {}"); |
+assertThrows("function* undefined() {'use strong';}", SyntaxError); |
+ |
+// FunctionExpression named 'undefined'; |
+CheckStrongMode("(function undefined() {})"); |
+assertThrows("(function undefined() {'use strong';})", SyntaxError); |
+ |
+// Generator function expression named 'undefined'; |
+CheckStrongMode("(function* undefined() {})"); |
+assertThrows("(function* undefined() {'use strong';})", SyntaxError); |
+ |
+//Function parameter named 'undefined'. |
+CheckStrongMode("function foo(a, b, undefined, c, d) {}"); |
+assertThrows("function foo(a, b, undefined, c, d) {'use strong';}", |
+ SyntaxError); |
+assertThrows("(function foo(a, b, undefined, c, d) {'use strong';})", |
+ SyntaxError); |
+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.
|
+ SyntaxError); |
+ |
+// Generator function parameter named 'undefined'. |
+CheckStrongMode("function* foo(a, b, undefined, c, d) {}"); |
+assertThrows("function* foo(a, b, undefined, c, d) {'use strong';}", |
+ SyntaxError); |
+assertThrows("(function* foo(a, b, undefined, c, d) {'use strong';})", |
+SyntaxError); |
+assertThrows("class C { *foo(a, b, undefined, c, d) {'use strong';} }", |
+ SyntaxError); |
+ |
+// Arrow function expression with 'undefined' param |
+// TODO(conradw): Checking arrow function heads is hard to modify just now |
+// CheckStrongMode("(undefined => {return})"); |
+// assertThrows("(undefined => {'use strong';})"); |
+ |
+// Class declaration named 'undefined' |
+CheckStrongMode("class undefined {}"); |
+assertThrows("class undefined {'use strong'}", SyntaxError); |
+ |
+//ClassExpression named 'undefined' |
+CheckStrongMode("(class undefined {})"); |
+assertThrows("(class undefined {'use strong'})", SyntaxError); |
+ |
+// Binding/assigning to 'undefined' in for |
+CheckStrongMode("for(undefined = 0;false;);"); |
+CheckStrongMode("for(var undefined = 0;false;);"); |
+CheckStrongMode("for(let undefined = 0;false;);"); |
+CheckStrongMode("for(const undefined = 0;false;);"); |
+ |
+// Binding/assigning to 'undefined' in for-in |
+CheckStrongMode("for(undefined in {});"); |
+CheckStrongMode("for(var undefined in {});"); |
+CheckStrongMode("for(let undefined in {});"); |
+CheckStrongMode("for(const undefined in {});"); |
+ |
+// Binding/assigning to 'undefined' in for-of |
+CheckStrongMode("for(undefined of []);"); |
+CheckStrongMode("for(var undefined of []);"); |
+CheckStrongMode("for(let undefined of []);"); |
+CheckStrongMode("for(const undefined of []);"); |
+ |
+// Property accessor parameter named 'undefined'. |
+CheckStrongMode("let o = { set foo(undefined) {} }"); |
+assertThrows("let o = { set foo(undefined) {'use strong';} }", SyntaxError); |
+ |
+// catch(undefined) |
+CheckStrongMode("try {} catch(undefined) {};"); |
+ |
+// Assignment to undefined |
+CheckStrongMode("undefined = 0;"); |
+CheckStrongMode("print(undefined = 0);"); |
+CheckStrongMode("let x = undefined = 0;"); |
+ |
+// Compound assignment to undefined |
+CheckStrongMode("undefined *= 0;"); |
+CheckStrongMode("undefined /= 0;"); |
+CheckStrongMode("print(undefined %= 0);"); |
+CheckStrongMode("let x = undefined += 0;"); |
+CheckStrongMode("let x = undefined -= 0;"); |
+CheckStrongMode("undefined <<= 0;"); |
+CheckStrongMode("undefined >>= 0;"); |
+CheckStrongMode("print(undefined >>>= 0);"); |
+CheckStrongMode("print(undefined &= 0);"); |
+CheckStrongMode("let x = undefined ^= 0;"); |
+CheckStrongMode("let x = undefined |= 0;"); |
+ |
+// Postfix increment with undefined |
+CheckStrongMode("undefined++;"); |
+CheckStrongMode("print(undefined++);"); |
+CheckStrongMode("let x = undefined++;"); |
+ |
+// Postfix decrement with undefined |
+CheckStrongMode("undefined--;"); |
+CheckStrongMode("print(undefined--);"); |
+CheckStrongMode("let x = undefined--;"); |
+ |
+// Prefix increment with undefined |
+CheckStrongMode("++undefined;"); |
+CheckStrongMode("print(++undefined);"); |
+CheckStrongMode("let x = ++undefined;"); |
+ |
+// Prefix decrement with undefined |
+CheckStrongMode("--undefined;"); |
+CheckStrongMode("print(--undefined);"); |
+CheckStrongMode("let x = --undefined;"); |
+ |
+// Function constructor: 'undefined' parameter name. |
+assertDoesNotThrow(function() { |
+ Function("undefined", ""); |
+}); |
+assertThrows(function() { |
+ Function("undefined", "'use strong';"); |
+}, SyntaxError); |