From 19762b927aea6838ef9a14041d17a3b5c76b948e Mon Sep 17 00:00:00 2001
From: Mike Pennisi <mike@mikepennisi.com>
Date: Tue, 19 Jan 2016 12:27:33 -0500
Subject: [PATCH] Add tests for iterator expression in ForIn/Of head

Although the `for..in` statement allows Expressions to define the
iterator, only an AssignmentExpression may occupy this position in the
`for..of` statement.
---
 .../statements/for-in/head-decl-expr.js       | 25 ++++++++++++++++++
 .../statements/for-in/head-expr-expr.js       | 26 +++++++++++++++++++
 .../statements/for-in/head-var-expr.js        | 25 ++++++++++++++++++
 .../statements/for-of/head-decl-no-expr.js    | 13 ++++++++++
 .../statements/for-of/head-expr-no-expr.js    | 14 ++++++++++
 .../statements/for-of/head-var-no-expr.js     | 13 ++++++++++
 6 files changed, 116 insertions(+)
 create mode 100644 test/language/statements/for-in/head-decl-expr.js
 create mode 100644 test/language/statements/for-in/head-expr-expr.js
 create mode 100644 test/language/statements/for-in/head-var-expr.js
 create mode 100644 test/language/statements/for-of/head-decl-no-expr.js
 create mode 100644 test/language/statements/for-of/head-expr-no-expr.js
 create mode 100644 test/language/statements/for-of/head-var-no-expr.js

diff --git a/test/language/statements/for-in/head-decl-expr.js b/test/language/statements/for-in/head-decl-expr.js
new file mode 100644
index 0000000000..fed986ef72
--- /dev/null
+++ b/test/language/statements/for-in/head-decl-expr.js
@@ -0,0 +1,25 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Expression is allowed in head
+info: >
+    IterationStatement : for ( ForDeclaration in Expression ) Statement
+
+    1. Let keyResult be the result of performing
+       ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, Expression,
+       enumerate).
+    2. ReturnIfAbrupt(keyResult).
+    3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult,
+       lexicalBinding, labelSet).
+es6id: 13.7.5.11
+---*/
+
+var iterCount = 0;
+
+for (let x in null, { key: 0 }) {
+  assert.sameValue(x, 'key');
+  iterCount += 1;
+}
+
+assert.sameValue(iterCount, 1);
diff --git a/test/language/statements/for-in/head-expr-expr.js b/test/language/statements/for-in/head-expr-expr.js
new file mode 100644
index 0000000000..2a2d81828a
--- /dev/null
+++ b/test/language/statements/for-in/head-expr-expr.js
@@ -0,0 +1,26 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Expression is allowed in head
+info: >
+    IterationStatement : for ( ForDeclaration in Expression ) Statement
+
+    1. Let keyResult be the result of performing
+       ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, Expression,
+       enumerate).
+    2. ReturnIfAbrupt(keyResult).
+    3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult,
+       lexicalBinding, labelSet).
+es6id: 13.7.5.11
+---*/
+
+var iterCount = 0;
+var x;
+
+for (x in null, { key: 0 }) {
+  assert.sameValue(x, 'key');
+  iterCount += 1;
+}
+
+assert.sameValue(iterCount, 1);
diff --git a/test/language/statements/for-in/head-var-expr.js b/test/language/statements/for-in/head-var-expr.js
new file mode 100644
index 0000000000..620ba5362d
--- /dev/null
+++ b/test/language/statements/for-in/head-var-expr.js
@@ -0,0 +1,25 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Expression is allowed in head
+info: >
+    IterationStatement : for ( ForDeclaration in Expression ) Statement
+
+    1. Let keyResult be the result of performing
+       ForIn/OfHeadEvaluation(BoundNames of ForDeclaration, Expression,
+       enumerate).
+    2. ReturnIfAbrupt(keyResult).
+    3. Return ForIn/OfBodyEvaluation(ForDeclaration, Statement, keyResult,
+       lexicalBinding, labelSet).
+es6id: 13.7.5.11
+---*/
+
+var iterCount = 0;
+
+for (var x in null, { key: 0 }) {
+  assert.sameValue(x, 'key');
+  iterCount += 1;
+}
+
+assert.sameValue(iterCount, 1);
diff --git a/test/language/statements/for-of/head-decl-no-expr.js b/test/language/statements/for-of/head-decl-no-expr.js
new file mode 100644
index 0000000000..01da99998f
--- /dev/null
+++ b/test/language/statements/for-of/head-decl-no-expr.js
@@ -0,0 +1,13 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Expression not allowed in head's AssignmentExpression position
+info: >
+    IterationStatement :
+        for ( ForDeclaration of AssignmentExpression ) Statement
+es6id: 13.7
+negative: SyntaxError
+---*/
+
+for (let x of [], []) {}
diff --git a/test/language/statements/for-of/head-expr-no-expr.js b/test/language/statements/for-of/head-expr-no-expr.js
new file mode 100644
index 0000000000..14e8e47bc4
--- /dev/null
+++ b/test/language/statements/for-of/head-expr-no-expr.js
@@ -0,0 +1,14 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Expression not allowed in head's AssignmentExpression position
+info: >
+    IterationStatement :
+        for ( LeftHandSideExpression of AssignmentExpression ) Statement
+es6id: 13.7
+negative: SyntaxError
+---*/
+
+var x;
+for (x of [], []) {}
diff --git a/test/language/statements/for-of/head-var-no-expr.js b/test/language/statements/for-of/head-var-no-expr.js
new file mode 100644
index 0000000000..f2de943db9
--- /dev/null
+++ b/test/language/statements/for-of/head-var-no-expr.js
@@ -0,0 +1,13 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+
+/*---
+description: Expression not allowed in head's AssignmentExpression position
+info: >
+    IterationStatement :
+        for ( var ForBinding of AssignmentExpression ) Statement
+es6id: 13.7
+negative: SyntaxError
+---*/
+
+for (var x of [], []) {}
-- 
GitLab