invoked-as-function-multiple-arguments.js 938 B

12345678910111213141516171819202122232425
  1. // Copyright (C) 2013 the V8 project authors. All rights reserved.
  2. // This code is governed by the BSD license found in the LICENSE file.
  3. /*---
  4. es6id: 25.2
  5. description: >
  6. When invoked via the function invocation pattern with multiple arguments,
  7. the GeneratorFunction intrinsic creates a valid generator whose body is the
  8. last argument evaluated as source code and whose formal parameters are
  9. defined by the preceding arguments.
  10. features: [generators]
  11. ---*/
  12. var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor;
  13. var g = GeneratorFunction('x', 'y', 'yield x + y;');
  14. var iter = g(2, 3);
  15. var result;
  16. result = iter.next();
  17. assert.sameValue(result.value, 5, 'First result `value`');
  18. assert.sameValue(result.done, false, 'First result `done` flag');
  19. result = iter.next();
  20. assert.sameValue(result.value, undefined, 'Final result `value`');
  21. assert.sameValue(result.done, true, 'Final result `done` flag');