instance-yield-expr-in-param.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2016 the V8 project authors. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. esid: sec-generatorfunction
  5. description: Definition of instance `length` property
  6. info: |
  7. [...]
  8. 3. Return CreateDynamicFunction(C, NewTarget, "generator", args).
  9. 19.2.1.1.1 Runtime Semantics: CreateDynamicFunction
  10. [...]
  11. 20. If kind is "generator", then
  12. a. If parameters Contains YieldExpression is true, throw a SyntaxError
  13. exception.
  14. features: [generators]
  15. ---*/
  16. var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor;
  17. // YieldExpression is permitted in function body.
  18. GeneratorFunction('x = yield');
  19. assert.throws(SyntaxError, function() {
  20. GeneratorFunction('x = yield', '');
  21. }, 'YieldExpression not permitted generally');
  22. var withinGenerator = function*() {
  23. GeneratorFunction('x = yield', '');
  24. };
  25. assert.throws(SyntaxError, function() {
  26. withinGenerator().next();
  27. }, 'YieldExpression not permitted when calling context is a generator');