invoked-as-function-single-argument.js 849 B

123456789101112131415161718192021222324
  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 a single argument,
  7. the GeneratorFunction intrinsic creates a valid generator whose body is the
  8. first argument evaluated as source code.
  9. features: [generators]
  10. ---*/
  11. var GeneratorFunction = Object.getPrototypeOf(function*() {}).constructor;
  12. var g = GeneratorFunction('yield 1;');
  13. var iter = g();
  14. var result;
  15. result = iter.next();
  16. assert.sameValue(result.value, 1, 'First result `value`');
  17. assert.sameValue(result.done, false, 'First result `done` flag');
  18. result = iter.next();
  19. assert.sameValue(result.value, undefined, 'Final result `value`');
  20. assert.sameValue(result.done, true, 'Final result `done` flag');