From d6580e8b66ab960dbfbc9034c68b0d46c8c249d7 Mon Sep 17 00:00:00 2001
From: Kevin Gibbons <bakkot@gmail.com>
Date: Tue, 2 Aug 2016 12:47:39 -0700
Subject: [PATCH] Add tests for for-in initializers (#735)

These were re-introduced in sloppy mode per
https://github.com/tc39/ecma262/pull/614
---
 .../statements/for-in/bare-initializer.js     | 12 ++++++
 .../statements/for-in/const-initializer.js    | 11 ++++++
 .../statements/for-in/let-initializer.js      | 11 ++++++
 .../for-in/nonstrict-initializer.js           | 39 +++++++++++++++++++
 .../statements/for-in/strict-initializer.js   | 12 ++++++
 .../var-arraybindingpattern-initializer.js    | 11 ++++++
 .../var-objectbindingpattern-initializer.js   | 11 ++++++
 7 files changed, 107 insertions(+)
 create mode 100644 test/annexB/language/statements/for-in/bare-initializer.js
 create mode 100644 test/annexB/language/statements/for-in/const-initializer.js
 create mode 100644 test/annexB/language/statements/for-in/let-initializer.js
 create mode 100644 test/annexB/language/statements/for-in/nonstrict-initializer.js
 create mode 100644 test/annexB/language/statements/for-in/strict-initializer.js
 create mode 100644 test/annexB/language/statements/for-in/var-arraybindingpattern-initializer.js
 create mode 100644 test/annexB/language/statements/for-in/var-objectbindingpattern-initializer.js

diff --git a/test/annexB/language/statements/for-in/bare-initializer.js b/test/annexB/language/statements/for-in/bare-initializer.js
new file mode 100644
index 0000000000..2ef778ecb0
--- /dev/null
+++ b/test/annexB/language/statements/for-in/bare-initializer.js
@@ -0,0 +1,12 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in heads prohibit AssignmentExpressions
+negative: SyntaxError
+---*/
+var a;
+throw NotEarlyError;
+for (a = 0 in {});
+
diff --git a/test/annexB/language/statements/for-in/const-initializer.js b/test/annexB/language/statements/for-in/const-initializer.js
new file mode 100644
index 0000000000..1f79959dc1
--- /dev/null
+++ b/test/annexB/language/statements/for-in/const-initializer.js
@@ -0,0 +1,11 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in initializers with const are prohibited
+negative: SyntaxError
+---*/
+throw NotEarlyError;
+for (const a = 0 in {});
+
diff --git a/test/annexB/language/statements/for-in/let-initializer.js b/test/annexB/language/statements/for-in/let-initializer.js
new file mode 100644
index 0000000000..f7cc4750a8
--- /dev/null
+++ b/test/annexB/language/statements/for-in/let-initializer.js
@@ -0,0 +1,11 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in initializers with let are prohibited
+negative: SyntaxError
+---*/
+throw NotEarlyError;
+for (let a = 0 in {});
+
diff --git a/test/annexB/language/statements/for-in/nonstrict-initializer.js b/test/annexB/language/statements/for-in/nonstrict-initializer.js
new file mode 100644
index 0000000000..0a279f49dc
--- /dev/null
+++ b/test/annexB/language/statements/for-in/nonstrict-initializer.js
@@ -0,0 +1,39 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in initializers in nonstrict mode
+flags: [noStrict]
+---*/
+(function() {
+  var effects = 0;
+  for (var a = ++effects in {});
+  assert.sameValue(effects, 1);
+})();
+
+
+(function() {
+  var stored;
+  for (var a = 0 in stored = a, {});
+  assert.sameValue(stored, 0);
+})();
+
+
+(function() {
+  for (var a = 0 in {});
+  assert.sameValue(a, 0);
+})();
+
+
+(function() {
+  var effects = 0;
+  var iterations = 0;
+  var stored;
+  for (var a = (++effects, -1) in stored = a, {a: 0, b: 1, c: 2}) {
+    ++iterations;
+  }
+  assert.sameValue(stored, -1, "Initialized value should be available to RHS");
+  assert.sameValue(effects, 1, "Initializer should only be executed once");
+  assert.sameValue(iterations, 3, "Loop body should be executed the appropriate number of times");
+})();
diff --git a/test/annexB/language/statements/for-in/strict-initializer.js b/test/annexB/language/statements/for-in/strict-initializer.js
new file mode 100644
index 0000000000..60f00d2835
--- /dev/null
+++ b/test/annexB/language/statements/for-in/strict-initializer.js
@@ -0,0 +1,12 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in initializers in strict mode are prohibited
+negative: SyntaxError
+flags: [onlyStrict]
+---*/
+throw NotEarlyError;
+for (var a = 0 in {});
+
diff --git a/test/annexB/language/statements/for-in/var-arraybindingpattern-initializer.js b/test/annexB/language/statements/for-in/var-arraybindingpattern-initializer.js
new file mode 100644
index 0000000000..2507c74502
--- /dev/null
+++ b/test/annexB/language/statements/for-in/var-arraybindingpattern-initializer.js
@@ -0,0 +1,11 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in initializers with ArrayBindingPatterns are always prohibited
+negative: SyntaxError
+---*/
+throw NotEarlyError;
+for (var [a] = 0 in {});
+
diff --git a/test/annexB/language/statements/for-in/var-objectbindingpattern-initializer.js b/test/annexB/language/statements/for-in/var-objectbindingpattern-initializer.js
new file mode 100644
index 0000000000..84c14d60b8
--- /dev/null
+++ b/test/annexB/language/statements/for-in/var-objectbindingpattern-initializer.js
@@ -0,0 +1,11 @@
+// Copyright (C) 2016 the V8 project authors. All rights reserved.
+// This code is governed by the BSD license found in the LICENSE file.
+/*---
+esid: sec-initializers-in-forin-statement-heads
+description: >
+    for-in initializers with ObjectBindingPattern are always prohibited
+negative: SyntaxError
+---*/
+throw NotEarlyError;
+for (var {a} = 0 in {});
+
-- 
GitLab