From 7dcccfcca6e7999124233cc813781dae3d2e80b3 Mon Sep 17 00:00:00 2001
From: Mike Pennisi <mike@mikepennisi.com>
Date: Thu, 2 Jun 2016 11:18:06 -0400
Subject: [PATCH] Add tests for use of `yield` in default parameters

---
 .../arrow-function/param-dflt-yield-expr.js   | 24 +++++++++++++++
 .../param-dflt-yield-id-non-strict.js         | 25 ++++++++++++++++
 .../param-dflt-yield-id-strict.js             | 17 +++++++++++
 .../class/gen-method-param-dflt-yield.js      | 23 +++++++++++++++
 .../class/method-param-dflt-yield.js          | 18 ++++++++++++
 .../static-gen-method-param-dflt-yield.js     | 23 +++++++++++++++
 .../class/static-method-param-dflt-yield.js   | 18 ++++++++++++
 .../function/param-dflt-yield-non-strict.js   | 27 +++++++++++++++++
 .../function/param-dflt-yield-strict.js       | 21 ++++++++++++++
 .../generators/param-dflt-yield.js            | 21 ++++++++++++++
 .../class/gen-method-param-dflt-yield.js      | 23 +++++++++++++++
 .../statements/class/method-param-yield.js    | 18 ++++++++++++
 .../static-gen-method-param-dflt-yield.js     | 23 +++++++++++++++
 .../class/static-method-param-yield.js        | 18 ++++++++++++
 .../function/param-dflt-yield-non-strict.js   | 29 +++++++++++++++++++
 .../function/param-dflt-yield-strict.js       | 21 ++++++++++++++
 .../statements/generators/param-dflt-yield.js | 20 +++++++++++++
 17 files changed, 369 insertions(+)
 create mode 100644 test/language/expressions/arrow-function/param-dflt-yield-expr.js
 create mode 100644 test/language/expressions/arrow-function/param-dflt-yield-id-non-strict.js
 create mode 100644 test/language/expressions/arrow-function/param-dflt-yield-id-strict.js
 create mode 100644 test/language/expressions/class/gen-method-param-dflt-yield.js
 create mode 100644 test/language/expressions/class/method-param-dflt-yield.js
 create mode 100644 test/language/expressions/class/static-gen-method-param-dflt-yield.js
 create mode 100644 test/language/expressions/class/static-method-param-dflt-yield.js
 create mode 100644 test/language/expressions/function/param-dflt-yield-non-strict.js
 create mode 100644 test/language/expressions/function/param-dflt-yield-strict.js
 create mode 100644 test/language/expressions/generators/param-dflt-yield.js
 create mode 100644 test/language/statements/class/gen-method-param-dflt-yield.js
 create mode 100644 test/language/statements/class/method-param-yield.js
 create mode 100644 test/language/statements/class/static-gen-method-param-dflt-yield.js
 create mode 100644 test/language/statements/class/static-method-param-yield.js
 create mode 100644 test/language/statements/function/param-dflt-yield-non-strict.js
 create mode 100644 test/language/statements/function/param-dflt-yield-strict.js
 create mode 100644 test/language/statements/generators/param-dflt-yield.js

diff --git a/test/language/expressions/arrow-function/param-dflt-yield-expr.js b/test/language/expressions/arrow-function/param-dflt-yield-expr.js
new file mode 100644
index 0000000000..20e6786187
--- /dev/null
+++ b/test/language/expressions/arrow-function/param-dflt-yield-expr.js
@@ -0,0 +1,24 @@
+// 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-arrow-function-definitions
+es6id: 14.2
+description: >
+  The `yield` token is interpreted contextually outside of strict mode
+info: |
+  ArrowFunction[In, Yield] :
+
+    ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
+
+  14.2.1 Static Semantics: Early Errors#
+
+  ArrowFunction : ArrowParameters=>ConciseBody
+
+  - It is a Syntax Error if ArrowParameters Contains YieldExpression is true. 
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+function *g() {
+  (x = yield) => {};
+}
diff --git a/test/language/expressions/arrow-function/param-dflt-yield-id-non-strict.js b/test/language/expressions/arrow-function/param-dflt-yield-id-non-strict.js
new file mode 100644
index 0000000000..90ce97b2a7
--- /dev/null
+++ b/test/language/expressions/arrow-function/param-dflt-yield-id-non-strict.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.
+/*---
+esid: sec-arrow-function-definitions
+es6id: 14.2
+description: >
+  The `yield` token is interpreted as an IdentifierReference outside of strict
+  mode and outside of generator function bodies.
+info: |
+  ArrowFunction[In, Yield] :
+
+    ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
+features: [default-parameters]
+flags: [onlyStrict]
+negative: SyntaxError
+---*/
+
+var yield = 23;
+var f, paramValue;
+
+f = (x = yield) => { paramValue = x; };
+
+f();
+
+assert.sameValue(paramValue, 23);
diff --git a/test/language/expressions/arrow-function/param-dflt-yield-id-strict.js b/test/language/expressions/arrow-function/param-dflt-yield-id-strict.js
new file mode 100644
index 0000000000..0e84b4b3fd
--- /dev/null
+++ b/test/language/expressions/arrow-function/param-dflt-yield-id-strict.js
@@ -0,0 +1,17 @@
+// 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-arrow-function-definitions
+es6id: 14.2
+description: >
+  The `yield` token is interpreted as a FutureReservedWord within strict mode
+info: |
+  ArrowFunction[In, Yield] :
+
+    ArrowParameters[?Yield] [no LineTerminator here] => ConciseBody[?In]
+features: [default-parameters]
+flags: [onlyStrict]
+negative: SyntaxError
+---*/
+
+(x = yield) => {};
diff --git a/test/language/expressions/class/gen-method-param-dflt-yield.js b/test/language/expressions/class/gen-method-param-dflt-yield.js
new file mode 100644
index 0000000000..da350ddbba
--- /dev/null
+++ b/test/language/expressions/class/gen-method-param-dflt-yield.js
@@ -0,0 +1,23 @@
+// 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-generator-function-definitions
+es6id: 14.4
+description: >
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function
+info: |
+  GeneratorMethod[Yield]:
+
+     * PropertyName[?Yield] ( StrictFormalParameters[Yield] ) { GeneratorBody }
+
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function because any expressions that are part of FormalParameters are
+  evaluated before the resulting generator object is in a resumable state.
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+0, class {
+  *g(x = yield) {}
+};
diff --git a/test/language/expressions/class/method-param-dflt-yield.js b/test/language/expressions/class/method-param-dflt-yield.js
new file mode 100644
index 0000000000..378e0e02f0
--- /dev/null
+++ b/test/language/expressions/class/method-param-dflt-yield.js
@@ -0,0 +1,18 @@
+// 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-method-definitions
+es6id: 14.3
+description: >
+  YieldExpression cannot be used within the FormalParameters of a class method
+info: |
+  MethodDefinition[Yield] :
+
+    PropertyName[?Yield] ( StrictFormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+0, class {
+  m(x = yield) {}
+};
diff --git a/test/language/expressions/class/static-gen-method-param-dflt-yield.js b/test/language/expressions/class/static-gen-method-param-dflt-yield.js
new file mode 100644
index 0000000000..c24810c3bb
--- /dev/null
+++ b/test/language/expressions/class/static-gen-method-param-dflt-yield.js
@@ -0,0 +1,23 @@
+// 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-generator-function-definitions
+es6id: 14.4
+description: >
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function
+info: |
+  GeneratorMethod[Yield]:
+
+     * PropertyName[?Yield] ( StrictFormalParameters[Yield] ) { GeneratorBody }
+
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function because any expressions that are part of FormalParameters are
+  evaluated before the resulting generator object is in a resumable state.
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+0, class {
+  static *g(x = yield) {}
+};
diff --git a/test/language/expressions/class/static-method-param-dflt-yield.js b/test/language/expressions/class/static-method-param-dflt-yield.js
new file mode 100644
index 0000000000..a6b6d16acd
--- /dev/null
+++ b/test/language/expressions/class/static-method-param-dflt-yield.js
@@ -0,0 +1,18 @@
+// 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-method-definitions
+es6id: 14.3
+description: >
+  YieldExpression cannot be used within the FormalParameters of a class method
+info: |
+  MethodDefinition[Yield] :
+
+    PropertyName[?Yield] ( StrictFormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+0, class {
+  static m(x = yield) {}
+};
diff --git a/test/language/expressions/function/param-dflt-yield-non-strict.js b/test/language/expressions/function/param-dflt-yield-non-strict.js
new file mode 100644
index 0000000000..9149401c40
--- /dev/null
+++ b/test/language/expressions/function/param-dflt-yield-non-strict.js
@@ -0,0 +1,27 @@
+// 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-function-definitions
+es6id: 14.1
+description: >
+  The `yield` token is interpreted as an IdentifierReference within a generator
+  and outside of strict mode
+info: |
+  FunctionExpression :
+    function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+flags: [noStrict]
+---*/
+
+var yield = 23;
+var paramValue;
+
+function *g() {
+  (function(x = yield) {
+    paramValue = x;
+  }());
+}
+
+g().next();
+
+assert.sameValue(paramValue, 23);
diff --git a/test/language/expressions/function/param-dflt-yield-strict.js b/test/language/expressions/function/param-dflt-yield-strict.js
new file mode 100644
index 0000000000..875973f963
--- /dev/null
+++ b/test/language/expressions/function/param-dflt-yield-strict.js
@@ -0,0 +1,21 @@
+// 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-function-definitions
+es6id: 14.1
+description: >
+  The `yield` token is interpreted as an IdentifierReference within a generator
+  and outside of strict mode
+info: |
+  FunctionExpression :
+    function BindingIdentifieropt ( FormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+flags: [onlyStrict]
+negative: SyntaxError
+---*/
+
+function *g() {
+  0, function(x = yield) {
+    paramValue = x;
+  };
+}
diff --git a/test/language/expressions/generators/param-dflt-yield.js b/test/language/expressions/generators/param-dflt-yield.js
new file mode 100644
index 0000000000..98952a2974
--- /dev/null
+++ b/test/language/expressions/generators/param-dflt-yield.js
@@ -0,0 +1,21 @@
+// 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-generator-function-definitions
+es6id: 14.4
+description: >
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function
+info: |
+  GeneratorExpression :
+
+    function * BindingIdentifier[Yield]opt ( FormalParameters[Yield] ) { GeneratorBody }
+
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function because any expressions that are part of FormalParameters are
+  evaluated before the resulting generator object is in a resumable state.
+features: [default-parameters]
+negative: SyntaxError
+---*/
+
+0, function*(x = yield) {};
diff --git a/test/language/statements/class/gen-method-param-dflt-yield.js b/test/language/statements/class/gen-method-param-dflt-yield.js
new file mode 100644
index 0000000000..708120b2b5
--- /dev/null
+++ b/test/language/statements/class/gen-method-param-dflt-yield.js
@@ -0,0 +1,23 @@
+// 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-generator-function-definitions
+es6id: 14.4
+description: >
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function
+info: |
+  GeneratorMethod[Yield]:
+
+     * PropertyName[?Yield] ( StrictFormalParameters[Yield] ) { GeneratorBody }
+
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function because any expressions that are part of FormalParameters are
+  evaluated before the resulting generator object is in a resumable state.
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+class C {
+  *g(x = yield) {}
+}
diff --git a/test/language/statements/class/method-param-yield.js b/test/language/statements/class/method-param-yield.js
new file mode 100644
index 0000000000..244c1e8945
--- /dev/null
+++ b/test/language/statements/class/method-param-yield.js
@@ -0,0 +1,18 @@
+// 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-method-definitions
+es6id: 14.3
+description: >
+  YieldExpression cannot be used within the FormalParameters of a class method
+info: |
+  MethodDefinition[Yield] :
+
+    PropertyName[?Yield] ( StrictFormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+class C {
+  m(x = yield) {}
+}
diff --git a/test/language/statements/class/static-gen-method-param-dflt-yield.js b/test/language/statements/class/static-gen-method-param-dflt-yield.js
new file mode 100644
index 0000000000..903c8eeba3
--- /dev/null
+++ b/test/language/statements/class/static-gen-method-param-dflt-yield.js
@@ -0,0 +1,23 @@
+// 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-generator-function-definitions
+es6id: 14.4
+description: >
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function
+info: |
+  GeneratorMethod[Yield]:
+
+     * PropertyName[?Yield] ( StrictFormalParameters[Yield] ) { GeneratorBody }
+
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function because any expressions that are part of FormalParameters are
+  evaluated before the resulting generator object is in a resumable state.
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+class C {
+  static *g(x = yield) {}
+}
diff --git a/test/language/statements/class/static-method-param-yield.js b/test/language/statements/class/static-method-param-yield.js
new file mode 100644
index 0000000000..be2fc13002
--- /dev/null
+++ b/test/language/statements/class/static-method-param-yield.js
@@ -0,0 +1,18 @@
+// 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-method-definitions
+es6id: 14.3
+description: >
+  YieldExpression cannot be used within the FormalParameters of a class method
+info: |
+  MethodDefinition[Yield] :
+
+    PropertyName[?Yield] ( StrictFormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+negative: SyntaxError
+---*/
+
+class C {
+  static m(x = yield) {}
+}
diff --git a/test/language/statements/function/param-dflt-yield-non-strict.js b/test/language/statements/function/param-dflt-yield-non-strict.js
new file mode 100644
index 0000000000..d04d8d5dd9
--- /dev/null
+++ b/test/language/statements/function/param-dflt-yield-non-strict.js
@@ -0,0 +1,29 @@
+// 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-function-definitions
+es6id: 14.1
+description: >
+  The `yield` token is interpreted as an IdentifierReference within a generator
+  and outside of strict mode
+info: |
+  FunctionDeclaration[Yield, Default] :
+    function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+flags: [noStrict]
+---*/
+
+var yield = 23;
+var paramValue;
+
+function *g() {
+  function f(x = yield) {
+    paramValue = x;
+  }
+
+  f();
+}
+
+g().next();
+
+assert.sameValue(paramValue, 23);
diff --git a/test/language/statements/function/param-dflt-yield-strict.js b/test/language/statements/function/param-dflt-yield-strict.js
new file mode 100644
index 0000000000..39a14ad1d4
--- /dev/null
+++ b/test/language/statements/function/param-dflt-yield-strict.js
@@ -0,0 +1,21 @@
+// 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-function-definitions
+es6id: 14.1
+description: >
+  The `yield` token is interpreted as an IdentifierReference within a generator
+  and outside of strict mode
+info: |
+  FunctionDeclaration[Yield, Default] :
+    function BindingIdentifier[?Yield] ( FormalParameters ) { FunctionBody }
+features: [generators, default-parameters]
+flags: [onlyStrict]
+negative: SyntaxError
+---*/
+
+function *g() {
+  function f(x = yield) {
+    paramValue = x;
+  }
+}
diff --git a/test/language/statements/generators/param-dflt-yield.js b/test/language/statements/generators/param-dflt-yield.js
new file mode 100644
index 0000000000..6df68b3beb
--- /dev/null
+++ b/test/language/statements/generators/param-dflt-yield.js
@@ -0,0 +1,20 @@
+// 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-generator-function-definitions
+es6id: 14.4
+description: >
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function
+info: |
+  GeneratorDeclaration[Yield, Default] :
+    function * BindingIdentifier[?Yield] ( FormalParameters[Yield] ) { GeneratorBody }
+
+  YieldExpression cannot be used within the FormalParameters of a generator
+  function because any expressions that are part of FormalParameters are
+  evaluated before the resulting generator object is in a resumable state.
+features: [default-parameters]
+negative: SyntaxError
+---*/
+
+function* g(x = yield) {}
-- 
GitLab