From 088ef770001f41921543923ba0447f3b95b6b6ff Mon Sep 17 00:00:00 2001 From: Leo Balter <leonardo.balter@gmail.com> Date: Mon, 27 Mar 2017 17:19:11 -0400 Subject: [PATCH] Generate tests --- .../named-yield-star-async-next.js | 224 +++++++++++++++ .../named-yield-star-async-return.js | 242 +++++++++++++++++ .../named-yield-star-async-throw.js | 247 +++++++++++++++++ .../named-yield-star-sync-next.js | 224 +++++++++++++++ .../named-yield-star-sync-return.js | 196 ++++++++++++++ .../named-yield-star-sync-throw.js | 202 ++++++++++++++ .../async-generator/yield-star-async-next.js | 224 +++++++++++++++ .../yield-star-async-return.js | 242 +++++++++++++++++ .../async-generator/yield-star-async-throw.js | 247 +++++++++++++++++ .../async-generator/yield-star-sync-next.js | 224 +++++++++++++++ .../async-generator/yield-star-sync-return.js | 196 ++++++++++++++ .../async-generator/yield-star-sync-throw.js | 202 ++++++++++++++ ...gen-method-static-yield-star-async-next.js | 231 ++++++++++++++++ ...n-method-static-yield-star-async-return.js | 249 +++++++++++++++++ ...en-method-static-yield-star-async-throw.js | 254 ++++++++++++++++++ ...-gen-method-static-yield-star-sync-next.js | 231 ++++++++++++++++ ...en-method-static-yield-star-sync-return.js | 203 ++++++++++++++ ...gen-method-static-yield-star-sync-throw.js | 209 ++++++++++++++ .../async-gen-method-yield-star-async-next.js | 231 ++++++++++++++++ ...sync-gen-method-yield-star-async-return.js | 249 +++++++++++++++++ ...async-gen-method-yield-star-async-throw.js | 254 ++++++++++++++++++ .../async-gen-method-yield-star-sync-next.js | 231 ++++++++++++++++ ...async-gen-method-yield-star-sync-return.js | 203 ++++++++++++++ .../async-gen-method-yield-star-sync-throw.js | 209 ++++++++++++++ .../async-gen-yield-star-async-next.js | 224 +++++++++++++++ .../async-gen-yield-star-async-return.js | 242 +++++++++++++++++ .../async-gen-yield-star-async-throw.js | 247 +++++++++++++++++ .../async-gen-yield-star-sync-next.js | 224 +++++++++++++++ .../async-gen-yield-star-sync-return.js | 196 ++++++++++++++ .../async-gen-yield-star-sync-throw.js | 202 ++++++++++++++ .../async-generator/yield-star-async-next.js | 102 +++---- .../yield-star-async-return.js | 48 ++-- .../async-generator/yield-star-async-throw.js | 58 ++-- .../async-generator/yield-star-sync-next.js | 60 +++-- .../async-generator/yield-star-sync-return.js | 48 ++-- .../async-generator/yield-star-sync-throw.js | 58 ++-- ...gen-method-static-yield-star-async-next.js | 231 ++++++++++++++++ ...n-method-static-yield-star-async-return.js | 249 +++++++++++++++++ ...en-method-static-yield-star-async-throw.js | 254 ++++++++++++++++++ ...-gen-method-static-yield-star-sync-next.js | 231 ++++++++++++++++ ...en-method-static-yield-star-sync-return.js | 203 ++++++++++++++ ...gen-method-static-yield-star-sync-throw.js | 209 ++++++++++++++ .../async-gen-method-yield-star-async-next.js | 231 ++++++++++++++++ ...sync-gen-method-yield-star-async-return.js | 249 +++++++++++++++++ ...async-gen-method-yield-star-async-throw.js | 254 ++++++++++++++++++ .../async-gen-method-yield-star-sync-next.js | 231 ++++++++++++++++ ...async-gen-method-yield-star-sync-return.js | 203 ++++++++++++++ .../async-gen-method-yield-star-sync-throw.js | 209 ++++++++++++++ 48 files changed, 9728 insertions(+), 159 deletions(-) create mode 100644 test/language/expressions/async-generator/named-yield-star-async-next.js create mode 100644 test/language/expressions/async-generator/named-yield-star-async-return.js create mode 100644 test/language/expressions/async-generator/named-yield-star-async-throw.js create mode 100644 test/language/expressions/async-generator/named-yield-star-sync-next.js create mode 100644 test/language/expressions/async-generator/named-yield-star-sync-return.js create mode 100644 test/language/expressions/async-generator/named-yield-star-sync-throw.js create mode 100644 test/language/expressions/async-generator/yield-star-async-next.js create mode 100644 test/language/expressions/async-generator/yield-star-async-return.js create mode 100644 test/language/expressions/async-generator/yield-star-async-throw.js create mode 100644 test/language/expressions/async-generator/yield-star-sync-next.js create mode 100644 test/language/expressions/async-generator/yield-star-sync-return.js create mode 100644 test/language/expressions/async-generator/yield-star-sync-throw.js create mode 100644 test/language/expressions/class/async-gen-method-static-yield-star-async-next.js create mode 100644 test/language/expressions/class/async-gen-method-static-yield-star-async-return.js create mode 100644 test/language/expressions/class/async-gen-method-static-yield-star-async-throw.js create mode 100644 test/language/expressions/class/async-gen-method-static-yield-star-sync-next.js create mode 100644 test/language/expressions/class/async-gen-method-static-yield-star-sync-return.js create mode 100644 test/language/expressions/class/async-gen-method-static-yield-star-sync-throw.js create mode 100644 test/language/expressions/class/async-gen-method-yield-star-async-next.js create mode 100644 test/language/expressions/class/async-gen-method-yield-star-async-return.js create mode 100644 test/language/expressions/class/async-gen-method-yield-star-async-throw.js create mode 100644 test/language/expressions/class/async-gen-method-yield-star-sync-next.js create mode 100644 test/language/expressions/class/async-gen-method-yield-star-sync-return.js create mode 100644 test/language/expressions/class/async-gen-method-yield-star-sync-throw.js create mode 100644 test/language/expressions/object/method-definition/async-gen-yield-star-async-next.js create mode 100644 test/language/expressions/object/method-definition/async-gen-yield-star-async-return.js create mode 100644 test/language/expressions/object/method-definition/async-gen-yield-star-async-throw.js create mode 100644 test/language/expressions/object/method-definition/async-gen-yield-star-sync-next.js create mode 100644 test/language/expressions/object/method-definition/async-gen-yield-star-sync-return.js create mode 100644 test/language/expressions/object/method-definition/async-gen-yield-star-sync-throw.js create mode 100644 test/language/statements/class/async-gen-method-static-yield-star-async-next.js create mode 100644 test/language/statements/class/async-gen-method-static-yield-star-async-return.js create mode 100644 test/language/statements/class/async-gen-method-static-yield-star-async-throw.js create mode 100644 test/language/statements/class/async-gen-method-static-yield-star-sync-next.js create mode 100644 test/language/statements/class/async-gen-method-static-yield-star-sync-return.js create mode 100644 test/language/statements/class/async-gen-method-static-yield-star-sync-throw.js create mode 100644 test/language/statements/class/async-gen-method-yield-star-async-next.js create mode 100644 test/language/statements/class/async-gen-method-yield-star-async-return.js create mode 100644 test/language/statements/class/async-gen-method-yield-star-async-throw.js create mode 100644 test/language/statements/class/async-gen-method-yield-star-sync-next.js create mode 100644 test/language/statements/class/async-gen-method-yield-star-sync-return.js create mode 100644 test/language/statements/class/async-gen-method-yield-star-sync-throw.js diff --git a/test/language/expressions/async-generator/named-yield-star-async-next.js b/test/language/expressions/async-generator/named-yield-star-async-next.js new file mode 100644 index 0000000000..f50070eb5f --- /dev/null +++ b/test/language/expressions/async-generator/named-yield-star-async-next.js @@ -0,0 +1,224 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-expression-named.template +/*--- +description: Execution order for yield* with async iterator and next() (Named async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/named-yield-star-async-return.js b/test/language/expressions/async-generator/named-yield-star-async-return.js new file mode 100644 index 0000000000..862d4b8e26 --- /dev/null +++ b/test/language/expressions/async-generator/named-yield-star-async-return.js @@ -0,0 +1,242 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-expression-named.template +/*--- +description: execution order for yield* with async iterator and return() (Named async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/named-yield-star-async-throw.js b/test/language/expressions/async-generator/named-yield-star-async-throw.js new file mode 100644 index 0000000000..20898e11ef --- /dev/null +++ b/test/language/expressions/async-generator/named-yield-star-async-throw.js @@ -0,0 +1,247 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-expression-named.template +/*--- +description: execution order for yield* with async iterator and throw() (Named async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/named-yield-star-sync-next.js b/test/language/expressions/async-generator/named-yield-star-sync-next.js new file mode 100644 index 0000000000..89635bd15f --- /dev/null +++ b/test/language/expressions/async-generator/named-yield-star-sync-next.js @@ -0,0 +1,224 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-expression-named.template +/*--- +description: execution order for yield* with sync iterator and next() (Named async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/named-yield-star-sync-return.js b/test/language/expressions/async-generator/named-yield-star-sync-return.js new file mode 100644 index 0000000000..77479612f8 --- /dev/null +++ b/test/language/expressions/async-generator/named-yield-star-sync-return.js @@ -0,0 +1,196 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-expression-named.template +/*--- +description: execution order for yield* with sync iterator and return() (Named async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/named-yield-star-sync-throw.js b/test/language/expressions/async-generator/named-yield-star-sync-throw.js new file mode 100644 index 0000000000..e923a604c9 --- /dev/null +++ b/test/language/expressions/async-generator/named-yield-star-sync-throw.js @@ -0,0 +1,202 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-expression-named.template +/*--- +description: execution order for yield* with sync iterator and throw() (Named async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *g() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/yield-star-async-next.js b/test/language/expressions/async-generator/yield-star-async-next.js new file mode 100644 index 0000000000..b9109de634 --- /dev/null +++ b/test/language/expressions/async-generator/yield-star-async-next.js @@ -0,0 +1,224 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-expression.template +/*--- +description: Execution order for yield* with async iterator and next() (Unnamed async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/yield-star-async-return.js b/test/language/expressions/async-generator/yield-star-async-return.js new file mode 100644 index 0000000000..44ba2b275b --- /dev/null +++ b/test/language/expressions/async-generator/yield-star-async-return.js @@ -0,0 +1,242 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-expression.template +/*--- +description: execution order for yield* with async iterator and return() (Unnamed async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/yield-star-async-throw.js b/test/language/expressions/async-generator/yield-star-async-throw.js new file mode 100644 index 0000000000..c18f7bbef0 --- /dev/null +++ b/test/language/expressions/async-generator/yield-star-async-throw.js @@ -0,0 +1,247 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-expression.template +/*--- +description: execution order for yield* with async iterator and throw() (Unnamed async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/yield-star-sync-next.js b/test/language/expressions/async-generator/yield-star-sync-next.js new file mode 100644 index 0000000000..cd170c93fa --- /dev/null +++ b/test/language/expressions/async-generator/yield-star-sync-next.js @@ -0,0 +1,224 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-expression.template +/*--- +description: execution order for yield* with sync iterator and next() (Unnamed async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/yield-star-sync-return.js b/test/language/expressions/async-generator/yield-star-sync-return.js new file mode 100644 index 0000000000..5d081b1b66 --- /dev/null +++ b/test/language/expressions/async-generator/yield-star-sync-return.js @@ -0,0 +1,196 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-expression.template +/*--- +description: execution order for yield* with sync iterator and return() (Unnamed async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/async-generator/yield-star-sync-throw.js b/test/language/expressions/async-generator/yield-star-sync-throw.js new file mode 100644 index 0000000000..b0d8e0015b --- /dev/null +++ b/test/language/expressions/async-generator/yield-star-sync-throw.js @@ -0,0 +1,202 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-expression.template +/*--- +description: execution order for yield* with sync iterator and throw() (Unnamed async generator expression) +esid: prod-AsyncGeneratorExpression +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorExpression : + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var gen = async function *() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-static-yield-star-async-next.js b/test/language/expressions/class/async-gen-method-static-yield-star-async-next.js new file mode 100644 index 0000000000..57ada56da1 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-static-yield-star-async-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-class-expr-static-method.template +/*--- +description: Execution order for yield* with async iterator and next() (Static async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-static-yield-star-async-return.js b/test/language/expressions/class/async-gen-method-static-yield-star-async-return.js new file mode 100644 index 0000000000..2570ccc187 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-static-yield-star-async-return.js @@ -0,0 +1,249 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-class-expr-static-method.template +/*--- +description: execution order for yield* with async iterator and return() (Static async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-static-yield-star-async-throw.js b/test/language/expressions/class/async-gen-method-static-yield-star-async-throw.js new file mode 100644 index 0000000000..2d068919e6 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-static-yield-star-async-throw.js @@ -0,0 +1,254 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-class-expr-static-method.template +/*--- +description: execution order for yield* with async iterator and throw() (Static async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-static-yield-star-sync-next.js b/test/language/expressions/class/async-gen-method-static-yield-star-sync-next.js new file mode 100644 index 0000000000..ca93f9f57d --- /dev/null +++ b/test/language/expressions/class/async-gen-method-static-yield-star-sync-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-class-expr-static-method.template +/*--- +description: execution order for yield* with sync iterator and next() (Static async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-static-yield-star-sync-return.js b/test/language/expressions/class/async-gen-method-static-yield-star-sync-return.js new file mode 100644 index 0000000000..26377124ac --- /dev/null +++ b/test/language/expressions/class/async-gen-method-static-yield-star-sync-return.js @@ -0,0 +1,203 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-class-expr-static-method.template +/*--- +description: execution order for yield* with sync iterator and return() (Static async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-static-yield-star-sync-throw.js b/test/language/expressions/class/async-gen-method-static-yield-star-sync-throw.js new file mode 100644 index 0000000000..156e2ef859 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-static-yield-star-sync-throw.js @@ -0,0 +1,209 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-class-expr-static-method.template +/*--- +description: execution order for yield* with sync iterator and throw() (Static async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-yield-star-async-next.js b/test/language/expressions/class/async-gen-method-yield-star-async-next.js new file mode 100644 index 0000000000..33306ad114 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-yield-star-async-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-class-expr-method.template +/*--- +description: Execution order for yield* with async iterator and next() (Async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-yield-star-async-return.js b/test/language/expressions/class/async-gen-method-yield-star-async-return.js new file mode 100644 index 0000000000..d4fae2bd8e --- /dev/null +++ b/test/language/expressions/class/async-gen-method-yield-star-async-return.js @@ -0,0 +1,249 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-class-expr-method.template +/*--- +description: execution order for yield* with async iterator and return() (Async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-yield-star-async-throw.js b/test/language/expressions/class/async-gen-method-yield-star-async-throw.js new file mode 100644 index 0000000000..460fd7004c --- /dev/null +++ b/test/language/expressions/class/async-gen-method-yield-star-async-throw.js @@ -0,0 +1,254 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-class-expr-method.template +/*--- +description: execution order for yield* with async iterator and throw() (Async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-yield-star-sync-next.js b/test/language/expressions/class/async-gen-method-yield-star-sync-next.js new file mode 100644 index 0000000000..7034de91f4 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-yield-star-sync-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-class-expr-method.template +/*--- +description: execution order for yield* with sync iterator and next() (Async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-yield-star-sync-return.js b/test/language/expressions/class/async-gen-method-yield-star-sync-return.js new file mode 100644 index 0000000000..97c7c97a85 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-yield-star-sync-return.js @@ -0,0 +1,203 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-class-expr-method.template +/*--- +description: execution order for yield* with sync iterator and return() (Async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/class/async-gen-method-yield-star-sync-throw.js b/test/language/expressions/class/async-gen-method-yield-star-sync-throw.js new file mode 100644 index 0000000000..ed940823b5 --- /dev/null +++ b/test/language/expressions/class/async-gen-method-yield-star-sync-throw.js @@ -0,0 +1,209 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-class-expr-method.template +/*--- +description: execution order for yield* with sync iterator and throw() (Async generator method as a ClassExpression element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +var C = class { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/object/method-definition/async-gen-yield-star-async-next.js b/test/language/expressions/object/method-definition/async-gen-yield-star-async-next.js new file mode 100644 index 0000000000..dad1843b82 --- /dev/null +++ b/test/language/expressions/object/method-definition/async-gen-yield-star-async-next.js @@ -0,0 +1,224 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-obj-method.template +/*--- +description: Execution order for yield* with async iterator and next() (Async generator method) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + + } +}.method; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/object/method-definition/async-gen-yield-star-async-return.js b/test/language/expressions/object/method-definition/async-gen-yield-star-async-return.js new file mode 100644 index 0000000000..512ab43c7e --- /dev/null +++ b/test/language/expressions/object/method-definition/async-gen-yield-star-async-return.js @@ -0,0 +1,242 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-obj-method.template +/*--- +description: execution order for yield* with async iterator and return() (Async generator method) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + + } +}.method; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/object/method-definition/async-gen-yield-star-async-throw.js b/test/language/expressions/object/method-definition/async-gen-yield-star-async-throw.js new file mode 100644 index 0000000000..448934cd30 --- /dev/null +++ b/test/language/expressions/object/method-definition/async-gen-yield-star-async-throw.js @@ -0,0 +1,247 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-obj-method.template +/*--- +description: execution order for yield* with async iterator and throw() (Async generator method) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + + } +}.method; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/object/method-definition/async-gen-yield-star-sync-next.js b/test/language/expressions/object/method-definition/async-gen-yield-star-sync-next.js new file mode 100644 index 0000000000..c83ffa16ef --- /dev/null +++ b/test/language/expressions/object/method-definition/async-gen-yield-star-sync-next.js @@ -0,0 +1,224 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-obj-method.template +/*--- +description: execution order for yield* with sync iterator and next() (Async generator method) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + + } +}.method; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/object/method-definition/async-gen-yield-star-sync-return.js b/test/language/expressions/object/method-definition/async-gen-yield-star-sync-return.js new file mode 100644 index 0000000000..7f07943b5d --- /dev/null +++ b/test/language/expressions/object/method-definition/async-gen-yield-star-sync-return.js @@ -0,0 +1,196 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-obj-method.template +/*--- +description: execution order for yield* with sync iterator and return() (Async generator method) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + + } +}.method; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/expressions/object/method-definition/async-gen-yield-star-sync-throw.js b/test/language/expressions/object/method-definition/async-gen-yield-star-sync-throw.js new file mode 100644 index 0000000000..cf0d11135d --- /dev/null +++ b/test/language/expressions/object/method-definition/async-gen-yield-star-sync-throw.js @@ -0,0 +1,202 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-obj-method.template +/*--- +description: execution order for yield* with sync iterator and throw() (Async generator method) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + +var callCount = 0; + +var gen = { + async *method() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + + } +}.method; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/async-generator/yield-star-async-next.js b/test/language/statements/async-generator/yield-star-async-next.js index 9eb6ec80a5..87845a14f1 100644 --- a/test/language/statements/async-generator/yield-star-async-next.js +++ b/test/language/statements/async-generator/yield-star-async-next.js @@ -1,58 +1,23 @@ -// Copyright 2017 Tooru Fujisawa. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-declaration.template /*--- -author: Tooru Fujisawa [:arai] <arai_a@mac.com> -esid: pending -description: execution order for yield* with async iterator and next() +description: Execution order for yield* with async iterator and next() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] info: | - YieldExpression: yield * AssignmentExpression - - ... - 2. Let value be ? GetValue(exprRef). - 3. Let generatorKind be ! GetGeneratorKind(). - 4. Let iterator be ? GetIterator(value, generatorKind). - 5. Let received be NormalCompletion(undefined). - 6. Repeat - a. If received.[[Type]] is normal, then - i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). - ii. Let innerResult be ? Invoke(iterator, "next", - « received.[[Value]] »). - iii. If generatorKind is async, then set innerResult to - ? Await(innerResult). - ... - v. Let done be ? IteratorComplete(innerResult). - vi. If done is true, then - 1. Return ? IteratorValue(innerResult). - vii. Let received be GeneratorYield(innerResult). - ... - - GetIterator ( obj [ , hint ] ) - - ... - 3. If hint is async, - a. Set method to ? GetMethod(obj, @@asyncIterator). - b. If method is undefined, - i. Let syncMethod be ? GetMethod(obj, @@iterator). - ii. Let syncIterator be ? Call(syncMethod, obj). - iii. Return ? CreateAsyncFromSyncIterator(syncIterator). - ... - - GeneratorYield ( iterNextObj ) - - ... - 10. If generatorKind is async, - a. Let value be IteratorValue(iterNextObj). - b. Let done be IteratorComplete(iterNextObj). - c. Return ! AsyncGeneratorResolve(generator, value, done). - ... - -flags: [async] -features: [async-iteration] ----*/ + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + +---*/ var log = []; -var iter = { +var obj = { get [Symbol.iterator]() { log.push({ name: "get [Symbol.iterator]" }); }, @@ -160,26 +125,35 @@ var iter = { }; } }; -var asyncIterator = (async function*() { + + + +var callCount = 0; + +async function *gen() { + callCount += 1; log.push({ name: "before yield*" }); - var v = yield* iter; - log.push({ - name: "after yield*", - value: v - }); - return "return-value"; -})(); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); assert.sameValue(log.length, 0, "log.length"); -asyncIterator.next("next-arg-1").then(v => { +iter.next("next-arg-1").then(v => { assert.sameValue(log[0].name, "before yield*"); assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); - assert.sameValue(log[1].thisValue, iter, "get [Symbol.asyncIterator] thisValue"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); - assert.sameValue(log[2].thisValue, iter, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); assert.sameValue(log[3].name, "get next"); @@ -213,7 +187,7 @@ asyncIterator.next("next-arg-1").then(v => { assert.sameValue(log.length, 10, "log.length"); - asyncIterator.next("next-arg-2").then(v => { + iter.next("next-arg-2").then(v => { assert.sameValue(log[10].name, "get next"); assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); @@ -246,3 +220,5 @@ asyncIterator.next("next-arg-1").then(v => { assert.sameValue(log.length, 17, "log.length"); }).then($DONE, $DONE); }).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/async-generator/yield-star-async-return.js b/test/language/statements/async-generator/yield-star-async-return.js index f11d34abcf..6b6883d453 100644 --- a/test/language/statements/async-generator/yield-star-async-return.js +++ b/test/language/statements/async-generator/yield-star-async-return.js @@ -1,11 +1,19 @@ -// Copyright 2017 Tooru Fujisawa. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-declaration.template /*--- -author: Tooru Fujisawa [:arai] <arai_a@mac.com> -esid: pending -description: execution order for yield* with async iterator and return() +description: execution order for yield* with async iterator and return() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + YieldExpression: yield * AssignmentExpression ... @@ -36,12 +44,9 @@ info: | c. Return ! AsyncGeneratorResolve(generator, value, done). ... -flags: [async] -features: [async-iteration] ---*/ - var log = []; -var iter = { +var obj = { [Symbol.asyncIterator]() { var returnCount = 0; return { @@ -144,14 +149,23 @@ var iter = { }; } }; -var asyncIterator = (async function*() { + + + +var callCount = 0; + +async function *gen() { + callCount += 1; log.push({ name: "before yield*" }); - yield* iter; -})(); + yield* obj; + +} + +var iter = gen(); assert.sameValue(log.length, 0, "log.length"); -asyncIterator.next().then(v => { +iter.next().then(v => { assert.sameValue(log[0].name, "before yield*"); assert.sameValue(log[1].name, "get next"); @@ -161,7 +175,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 2, "log.length"); - asyncIterator.return("return-arg-1").then(v => { + iter.return("return-arg-1").then(v => { assert.sameValue(log[2].name, "get return"); assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); @@ -193,7 +207,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 9, "log.length"); - asyncIterator.return("return-arg-2").then(v => { + iter.return("return-arg-2").then(v => { assert.sameValue(log[9].name, "get return"); assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); @@ -224,3 +238,5 @@ asyncIterator.next().then(v => { }).then($DONE, $DONE); }).catch($DONE); }).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/async-generator/yield-star-async-throw.js b/test/language/statements/async-generator/yield-star-async-throw.js index 0e9feeb774..4c0c64e21a 100644 --- a/test/language/statements/async-generator/yield-star-async-throw.js +++ b/test/language/statements/async-generator/yield-star-async-throw.js @@ -1,11 +1,19 @@ -// Copyright 2017 Tooru Fujisawa. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-declaration.template /*--- -author: Tooru Fujisawa [:arai] <arai_a@mac.com> -esid: pending -description: execution order for yield* with async iterator and throw() +description: execution order for yield* with async iterator and throw() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + YieldExpression: yield * AssignmentExpression ... @@ -33,12 +41,9 @@ info: | c. Return ! AsyncGeneratorResolve(generator, value, done). ... -flags: [async] -features: [async-iteration] ---*/ - var log = []; -var iter = { +var obj = { [Symbol.asyncIterator]() { var throwCount = 0; return { @@ -141,19 +146,28 @@ var iter = { }; } }; -var asyncIterator = (async function*() { + + + +var callCount = 0; + +async function *gen() { + callCount += 1; log.push({ name: "before yield*" }); - var v = yield* iter; - log.push({ - name: "after yield*", - value: v - }); - return "return-value"; -})(); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); assert.sameValue(log.length, 0, "log.length"); -asyncIterator.next().then(v => { +iter.next().then(v => { assert.sameValue(log[0].name, "before yield*"); assert.sameValue(log[1].name, "get next"); @@ -163,7 +177,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 2, "log.length"); - asyncIterator.throw("throw-arg-1").then(v => { + iter.throw("throw-arg-1").then(v => { assert.sameValue(log[2].name, "get throw"); assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); @@ -195,7 +209,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 9, "log.length"); - asyncIterator.throw("throw-arg-2").then(v => { + iter.throw("throw-arg-2").then(v => { assert.sameValue(log[9].name, "get throw"); assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); @@ -229,3 +243,5 @@ asyncIterator.next().then(v => { }).then($DONE, $DONE); }).catch($DONE); }).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/async-generator/yield-star-sync-next.js b/test/language/statements/async-generator/yield-star-sync-next.js index b57992c2e0..bf68fe614d 100644 --- a/test/language/statements/async-generator/yield-star-sync-next.js +++ b/test/language/statements/async-generator/yield-star-sync-next.js @@ -1,11 +1,19 @@ -// Copyright 2017 Tooru Fujisawa. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-declaration.template /*--- -author: Tooru Fujisawa [:arai] <arai_a@mac.com> -esid: pending -description: execution order for yield* with sync iterator and next() +description: execution order for yield* with sync iterator and next() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + YieldExpression: yield * AssignmentExpression ... @@ -59,12 +67,9 @@ info: | 1. Return ! CreateIterResultObject(value, F.[[Done]]). -flags: [async] -features: [async-iteration] ---*/ - var log = []; -var iter = { +var obj = { get [Symbol.iterator]() { log.push({ name: "get [Symbol.iterator]", @@ -139,28 +144,37 @@ var iter = { return null; } }; -var asyncIterator = (async function*() { + + + +var callCount = 0; + +async function *gen() { + callCount += 1; log.push({ name: "before yield*" }); - var v = yield* iter; - log.push({ - name: "after yield*", - value: v - }); - return "return-value"; -})(); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); assert.sameValue(log.length, 0, "log.length"); -asyncIterator.next("next-arg-1").then(v => { +iter.next("next-arg-1").then(v => { assert.sameValue(log[0].name, "before yield*"); assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); assert.sameValue(log[2].name, "get [Symbol.iterator]"); - assert.sameValue(log[2].thisValue, iter, "get [Symbol.iterator] thisValue"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); assert.sameValue(log[3].name, "call [Symbol.iterator]"); - assert.sameValue(log[3].thisValue, iter, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); assert.sameValue(log[4].name, "get next"); @@ -182,7 +196,7 @@ asyncIterator.next("next-arg-1").then(v => { assert.sameValue(log.length, 8, "log.length"); - asyncIterator.next("next-arg-2").then(v => { + iter.next("next-arg-2").then(v => { assert.sameValue(log[8].name, "get next"); assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); @@ -206,3 +220,5 @@ asyncIterator.next("next-arg-1").then(v => { assert.sameValue(log.length, 13, "log.length"); }).then($DONE, $DONE); }).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/async-generator/yield-star-sync-return.js b/test/language/statements/async-generator/yield-star-sync-return.js index 7252db75cb..a627e8fda7 100644 --- a/test/language/statements/async-generator/yield-star-sync-return.js +++ b/test/language/statements/async-generator/yield-star-sync-return.js @@ -1,11 +1,19 @@ -// Copyright 2017 Tooru Fujisawa. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-declaration.template /*--- -author: Tooru Fujisawa [:arai] <arai_a@mac.com> -esid: pending -description: execution order for yield* with sync iterator and return() +description: execution order for yield* with sync iterator and return() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + YieldExpression: yield * AssignmentExpression ... @@ -45,12 +53,9 @@ info: | onFulfilled, undefined, promiseCapability). ... -flags: [async] -features: [async-iteration] ---*/ - var log = []; -var iter = { +var obj = { [Symbol.iterator]() { var returnCount = 0; return { @@ -119,14 +124,23 @@ var iter = { }; } }; -var asyncIterator = (async function*() { + + + +var callCount = 0; + +async function *gen() { + callCount += 1; log.push({ name: "before yield*" }); - yield* iter; -})(); + yield* obj; + +} + +var iter = gen(); assert.sameValue(log.length, 0, "log.length"); -asyncIterator.next().then(v => { +iter.next().then(v => { assert.sameValue(log[0].name, "before yield*"); assert.sameValue(log[1].name, "get next"); @@ -136,7 +150,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 2, "log.length"); - asyncIterator.return("return-arg-1").then(v => { + iter.return("return-arg-1").then(v => { assert.sameValue(log[2].name, "get return"); assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); @@ -156,7 +170,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 6, "log.length"); - asyncIterator.return("return-arg-2").then(v => { + iter.return("return-arg-2").then(v => { assert.sameValue(log[6].name, "get return"); assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); @@ -178,3 +192,5 @@ asyncIterator.next().then(v => { }).then($DONE, $DONE); }).catch($DONE); }).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/async-generator/yield-star-sync-throw.js b/test/language/statements/async-generator/yield-star-sync-throw.js index c67a73b790..9c5e0b8d8b 100644 --- a/test/language/statements/async-generator/yield-star-sync-throw.js +++ b/test/language/statements/async-generator/yield-star-sync-throw.js @@ -1,11 +1,19 @@ -// Copyright 2017 Tooru Fujisawa. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-declaration.template /*--- -author: Tooru Fujisawa [:arai] <arai_a@mac.com> -esid: pending -description: execution order for yield* with sync iterator and throw() +description: execution order for yield* with sync iterator and throw() (Async generator Function declaration) +esid: prod-AsyncGeneratorDeclaration +features: [async-iteration, async-iteration] +flags: [generated, async] info: | + Async Generator Function Definitions + + AsyncGeneratorDeclaration: + async [no LineTerminator here] function * BindingIdentifier ( FormalParameters ) { + AsyncGeneratorBody } + + YieldExpression: yield * AssignmentExpression ... @@ -43,12 +51,9 @@ info: | onFulfilled, undefined, promiseCapability). ... -flags: [async] -features: [async-iteration] ---*/ - var log = []; -var iter = { +var obj = { [Symbol.iterator]() { var throwCount = 0; return { @@ -117,19 +122,28 @@ var iter = { }; } }; -var asyncIterator = (async function*() { + + + +var callCount = 0; + +async function *gen() { + callCount += 1; log.push({ name: "before yield*" }); - var v = yield* iter; - log.push({ - name: "after yield*", - value: v - }); - return "return-value"; -})(); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +} + +var iter = gen(); assert.sameValue(log.length, 0, "log.length"); -asyncIterator.next().then(v => { +iter.next().then(v => { assert.sameValue(log[0].name, "before yield*"); assert.sameValue(log[1].name, "get next"); @@ -139,7 +153,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 2, "log.length"); - asyncIterator.throw("throw-arg-1").then(v => { + iter.throw("throw-arg-1").then(v => { assert.sameValue(log[2].name, "get throw"); assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); @@ -159,7 +173,7 @@ asyncIterator.next().then(v => { assert.sameValue(log.length, 6, "log.length"); - asyncIterator.throw("throw-arg-2").then(v => { + iter.throw("throw-arg-2").then(v => { assert.sameValue(log[6].name, "get throw"); assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); @@ -184,3 +198,5 @@ asyncIterator.next().then(v => { }).then($DONE, $DONE); }).catch($DONE); }).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-static-yield-star-async-next.js b/test/language/statements/class/async-gen-method-static-yield-star-async-next.js new file mode 100644 index 0000000000..1dfe8e25d7 --- /dev/null +++ b/test/language/statements/class/async-gen-method-static-yield-star-async-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-class-decl-static-method.template +/*--- +description: Execution order for yield* with async iterator and next() (Static async generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-static-yield-star-async-return.js b/test/language/statements/class/async-gen-method-static-yield-star-async-return.js new file mode 100644 index 0000000000..dc4b7c90db --- /dev/null +++ b/test/language/statements/class/async-gen-method-static-yield-star-async-return.js @@ -0,0 +1,249 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-class-decl-static-method.template +/*--- +description: execution order for yield* with async iterator and return() (Static async generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-static-yield-star-async-throw.js b/test/language/statements/class/async-gen-method-static-yield-star-async-throw.js new file mode 100644 index 0000000000..905106e9af --- /dev/null +++ b/test/language/statements/class/async-gen-method-static-yield-star-async-throw.js @@ -0,0 +1,254 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-class-decl-static-method.template +/*--- +description: execution order for yield* with async iterator and throw() (Static async generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-static-yield-star-sync-next.js b/test/language/statements/class/async-gen-method-static-yield-star-sync-next.js new file mode 100644 index 0000000000..408fbc79b6 --- /dev/null +++ b/test/language/statements/class/async-gen-method-static-yield-star-sync-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-class-decl-static-method.template +/*--- +description: execution order for yield* with sync iterator and next() (Static async generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-static-yield-star-sync-return.js b/test/language/statements/class/async-gen-method-static-yield-star-sync-return.js new file mode 100644 index 0000000000..e4b46aae32 --- /dev/null +++ b/test/language/statements/class/async-gen-method-static-yield-star-sync-return.js @@ -0,0 +1,203 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-class-decl-static-method.template +/*--- +description: execution order for yield* with sync iterator and return() (Static async generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-static-yield-star-sync-throw.js b/test/language/statements/class/async-gen-method-static-yield-star-sync-throw.js new file mode 100644 index 0000000000..3c265f5aec --- /dev/null +++ b/test/language/statements/class/async-gen-method-static-yield-star-sync-throw.js @@ -0,0 +1,209 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-class-decl-static-method.template +/*--- +description: execution order for yield* with sync iterator and throw() (Static async generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + ClassElement : + static MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { static async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-yield-star-async-next.js b/test/language/statements/class/async-gen-method-yield-star-async-next.js new file mode 100644 index 0000000000..7a43370f6c --- /dev/null +++ b/test/language/statements/class/async-gen-method-yield-star-async-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-next.case +// - src/async-generators/default/async-class-decl-method.template +/*--- +description: Execution order for yield* with async iterator and next() (Async Generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ name: "get [Symbol.iterator]" }); + }, + get [Symbol.asyncIterator]() { + log.push({ + name: "get [Symbol.asyncIterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.asyncIterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-promise-1", + get then() { + log.push({ + name: "get next then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "next-promise-2", + get then() { + log.push({ + name: "get next then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call next then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + }; + } +}; + + + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + assert.sameValue(log[1].thisValue, obj, "get [Symbol.asyncIterator] thisValue"); + + assert.sameValue(log[2].name, "call [Symbol.asyncIterator]"); + assert.sameValue(log[2].thisValue, obj, "[Symbol.asyncIterator] thisValue"); + assert.sameValue(log[2].args.length, 0, "[Symbol.asyncIterator] args.length"); + + assert.sameValue(log[3].name, "get next"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[4].name, "call next"); + assert.sameValue(log[4].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[4].args.length, 1, "next args.length"); + assert.sameValue(log[4].args[0], undefined, "next args[0]"); + + assert.sameValue(log[5].name, "get next then (1)"); + assert.sameValue(log[5].thisValue.name, "next-promise-1", "get next then thisValue"); + + assert.sameValue(log[6].name, "call next then (1)"); + assert.sameValue(log[6].thisValue.name, "next-promise-1", "next then thisValue"); + assert.sameValue(log[6].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[6].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[6].args[1], "function", "next then args[1]"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(log[8].name, "get next value (1)"); + assert.sameValue(log[8].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[9].name, "get next done (1)"); + assert.sameValue(log[9].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 10, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[10].name, "get next"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "get next thisValue"); + + assert.sameValue(log[11].name, "call next"); + assert.sameValue(log[11].thisValue.name, "asyncIterator", "next thisValue"); + assert.sameValue(log[11].args.length, 1, "next args.length"); + assert.sameValue(log[11].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[12].name, "get next then (2)"); + assert.sameValue(log[12].thisValue.name, "next-promise-2", "get next then thisValue"); + + assert.sameValue(log[13].name, "call next then (2)"); + assert.sameValue(log[13].thisValue.name, "next-promise-2", "next then thisValue"); + assert.sameValue(log[13].args.length, 2, "next then args.length"); + assert.sameValue(typeof log[13].args[0], "function", "next then args[0]"); + assert.sameValue(typeof log[13].args[1], "function", "next then args[1]"); + + assert.sameValue(log[14].name, "get next done (2)"); + assert.sameValue(log[14].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[15].name, "get next value (2)"); + assert.sameValue(log[15].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[16].name, "after yield*"); + assert.sameValue(log[16].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 17, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-yield-star-async-return.js b/test/language/statements/class/async-gen-method-yield-star-async-return.js new file mode 100644 index 0000000000..7a373dd230 --- /dev/null +++ b/test/language/statements/class/async-gen-method-yield-star-async-return.js @@ -0,0 +1,249 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-return.case +// - src/async-generators/default/async-class-decl-method.template +/*--- +description: execution order for yield* with async iterator and return() (Async Generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var returnCount = 0; + return { + name: 'asyncIterator', + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-promise-1", + get then() { + log.push({ + name: "get return then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "return-promise-2", + get then() { + log.push({ + name: "get return then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call return then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return then (1)"); + assert.sameValue(log[4].thisValue.name, "return-promise-1", "get return then thisValue"); + + assert.sameValue(log[5].name, "call return then (1)"); + assert.sameValue(log[5].thisValue.name, "return-promise-1", "return then thisValue"); + assert.sameValue(log[5].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "return then args[1]"); + + assert.sameValue(log[6].name, "get return done (1)"); + assert.sameValue(log[6].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(log[7].name, "get return value (1)"); + assert.sameValue(log[7].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[8].name, "get return done (1)"); + assert.sameValue(log[8].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[9].name, "get return"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get return thisValue"); + + assert.sameValue(log[10].name, "call return"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "return thisValue"); + assert.sameValue(log[10].args.length, 1, "return args.length"); + assert.sameValue(log[10].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[11].name, "get return then (2)"); + assert.sameValue(log[11].thisValue.name, "return-promise-2", "get return then thisValue"); + + assert.sameValue(log[12].name, "call return then (2)"); + assert.sameValue(log[12].thisValue.name, "return-promise-2", "return then thisValue"); + assert.sameValue(log[12].args.length, 2, "return then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "return then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "return then args[1]"); + + assert.sameValue(log[13].name, "get return done (2)"); + assert.sameValue(log[13].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(log[14].name, "get return value (2)"); + assert.sameValue(log[14].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 15, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-yield-star-async-throw.js b/test/language/statements/class/async-gen-method-yield-star-async-throw.js new file mode 100644 index 0000000000..ffa3a5216e --- /dev/null +++ b/test/language/statements/class/async-gen-method-yield-star-async-throw.js @@ -0,0 +1,254 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-async-throw.case +// - src/async-generators/default/async-class-decl-method.template +/*--- +description: execution order for yield* with async iterator and throw() (Async Generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + GeneratorYield ( iterNextObj ) + + ... + 10. If generatorKind is async, + a. Let value be IteratorValue(iterNextObj). + b. Let done be IteratorComplete(iterNextObj). + c. Return ! AsyncGeneratorResolve(generator, value, done). + ... + +---*/ +var log = []; +var obj = { + [Symbol.asyncIterator]() { + var throwCount = 0; + return { + name: "asyncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-promise-1", + get then() { + log.push({ + name: "get throw then (1)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (1)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }); + }; + } + }; + } + + return { + name: "throw-promise-2", + get then() { + log.push({ + name: "get throw then (2)", + thisValue: this + }); + return function(resolve) { + log.push({ + name: "call throw then (2)", + thisValue: this, + args: [...arguments] + }); + + resolve({ + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }); + }; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw then (1)"); + assert.sameValue(log[4].thisValue.name, "throw-promise-1", "get throw thisValue"); + + assert.sameValue(log[5].name, "call throw then (1)"); + assert.sameValue(log[5].thisValue.name, "throw-promise-1", "throw thisValue"); + assert.sameValue(log[5].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[5].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[5].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[6].name, "get throw done (1)"); + assert.sameValue(log[6].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(log[7].name, "get throw value (1)"); + assert.sameValue(log[7].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[8].name, "get throw done (1)"); + assert.sameValue(log[8].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 9, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[9].name, "get throw"); + assert.sameValue(log[9].thisValue.name, "asyncIterator", "get throw thisValue"); + + assert.sameValue(log[10].name, "call throw"); + assert.sameValue(log[10].thisValue.name, "asyncIterator", "throw thisValue"); + assert.sameValue(log[10].args.length, 1, "throw args.length"); + assert.sameValue(log[10].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[11].name, "get throw then (2)"); + assert.sameValue(log[11].thisValue.name, "throw-promise-2", "get throw thisValue"); + + assert.sameValue(log[12].name, "call throw then (2)"); + assert.sameValue(log[12].thisValue.name, "throw-promise-2", "throw thisValue"); + assert.sameValue(log[12].args.length, 2, "throw then args.length"); + assert.sameValue(typeof log[12].args[0], "function", "throw then args[0]"); + assert.sameValue(typeof log[12].args[1], "function", "throw then args[1]"); + + assert.sameValue(log[13].name, "get throw done (2)"); + assert.sameValue(log[13].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[14].name, "get throw value (2)"); + assert.sameValue(log[14].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[15].name, "after yield*"); + assert.sameValue(log[15].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 16, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-yield-star-sync-next.js b/test/language/statements/class/async-gen-method-yield-star-sync-next.js new file mode 100644 index 0000000000..3d139fb47c --- /dev/null +++ b/test/language/statements/class/async-gen-method-yield-star-sync-next.js @@ -0,0 +1,231 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-next.case +// - src/async-generators/default/async-class-decl-method.template +/*--- +description: execution order for yield* with sync iterator and next() (Async Generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 2. Let value be ? GetValue(exprRef). + 3. Let generatorKind be ! GetGeneratorKind(). + 4. Let iterator be ? GetIterator(value, generatorKind). + 5. Let received be NormalCompletion(undefined). + 6. Repeat + a. If received.[[Type]] is normal, then + i. Let innerResult be ? IteratorNext(iterator, received.[[Value]]). + ii. Let innerResult be ? Invoke(iterator, "next", + « received.[[Value]] »). + iii. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + v. Let done be ? IteratorComplete(innerResult). + vi. If done is true, then + 1. Return ? IteratorValue(innerResult). + vii. Let received be GeneratorYield(innerResult). + ... + + GetIterator ( obj [ , hint ] ) + + ... + 3. If hint is async, + a. Set method to ? GetMethod(obj, @@asyncIterator). + b. If method is undefined, + i. Let syncMethod be ? GetMethod(obj, @@iterator). + ii. Let syncIterator be ? Call(syncMethod, obj). + iii. Return ? CreateAsyncFromSyncIterator(syncIterator). + ... + + %AsyncFromSyncIteratorPrototype%.next ( value ) + + ... + 5. Let nextResult be IteratorNext(syncIterator, value). + ... + 7. Let nextValue be IteratorValue(nextResult). + ... + 9. Let nextDone be IteratorComplete(nextResult). + ... + 12. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « nextValue »). + ... + 14. Set onFulfilled.[[Done]] to nextDone. + 15. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + + Async Iterator Value Unwrap Functions + + 1. Return ! CreateIterResultObject(value, F.[[Done]]). + +---*/ +var log = []; +var obj = { + get [Symbol.iterator]() { + log.push({ + name: "get [Symbol.iterator]", + thisValue: this + }); + return function() { + log.push({ + name: "call [Symbol.iterator]", + thisValue: this, + args: [...arguments] + }); + var nextCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ + name: "get next", + thisValue: this + }); + return function() { + log.push({ + name: "call next", + thisValue: this, + args: [...arguments] + }); + + nextCount++; + if (nextCount == 1) { + return { + name: "next-result-1", + get value() { + log.push({ + name: "get next value (1)", + thisValue: this + }); + return "next-value-1"; + }, + get done() { + log.push({ + name: "get next done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "next-result-2", + get value() { + log.push({ + name: "get next value (2)", + thisValue: this + }); + return "next-value-2"; + }, + get done() { + log.push({ + name: "get next done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + }; + }, + get [Symbol.asyncIterator]() { + log.push({ name: "get [Symbol.asyncIterator]" }); + return null; + } +}; + + + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next("next-arg-1").then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get [Symbol.asyncIterator]"); + + assert.sameValue(log[2].name, "get [Symbol.iterator]"); + assert.sameValue(log[2].thisValue, obj, "get [Symbol.iterator] thisValue"); + + assert.sameValue(log[3].name, "call [Symbol.iterator]"); + assert.sameValue(log[3].thisValue, obj, "[Symbol.iterator] thisValue"); + assert.sameValue(log[3].args.length, 0, "[Symbol.iterator] args.length"); + + assert.sameValue(log[4].name, "get next"); + assert.sameValue(log[4].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[5].name, "call next"); + assert.sameValue(log[5].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[5].args.length, 1, "next args.length"); + assert.sameValue(log[5].args[0], undefined, "next args[0]"); + + assert.sameValue(log[6].name, "get next value (1)"); + assert.sameValue(log[6].thisValue.name, "next-result-1", "get next value thisValue"); + + assert.sameValue(log[7].name, "get next done (1)"); + assert.sameValue(log[7].thisValue.name, "next-result-1", "get next done thisValue"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 8, "log.length"); + + iter.next("next-arg-2").then(v => { + assert.sameValue(log[8].name, "get next"); + assert.sameValue(log[8].thisValue.name, "syncIterator", "get next thisValue"); + + assert.sameValue(log[9].name, "call next"); + assert.sameValue(log[9].thisValue.name, "syncIterator", "next thisValue"); + assert.sameValue(log[9].args.length, 1, "next args.length"); + assert.sameValue(log[9].args[0], "next-arg-2", "next args[0]"); + + assert.sameValue(log[10].name, "get next value (2)"); + assert.sameValue(log[10].thisValue.name, "next-result-2", "get next value thisValue"); + + assert.sameValue(log[11].name, "get next done (2)"); + assert.sameValue(log[11].thisValue.name, "next-result-2", "get next done thisValue"); + + assert.sameValue(log[12].name, "after yield*"); + assert.sameValue(log[12].value, "next-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 13, "log.length"); + }).then($DONE, $DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-yield-star-sync-return.js b/test/language/statements/class/async-gen-method-yield-star-sync-return.js new file mode 100644 index 0000000000..790ab29223 --- /dev/null +++ b/test/language/statements/class/async-gen-method-yield-star-sync-return.js @@ -0,0 +1,203 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-return.case +// - src/async-generators/default/async-class-decl-method.template +/*--- +description: execution order for yield* with sync iterator and return() (Async Generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, Symbol.asyncIterator, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + c. Else, + i. Assert: received.[[Type]] is return. + ii. Let return be ? GetMethod(iterator, "return"). + iii. If return is undefined, return Completion(received). + iv. Let innerReturnResult be ? Call(return, iterator, + « received.[[Value]] »). + v. If generatorKind is async, then set innerReturnResult to + ? Await(innerReturnResult). + ... + vii. Let done be ? IteratorComplete(innerReturnResult). + viii. If done is true, then + 1. Let value be ? IteratorValue(innerReturnResult). + 2. Return Completion{[[Type]]: return, [[Value]]: value, + [[Target]]: empty}. + ix. Let received be GeneratorYield(innerResult). + + %AsyncFromSyncIteratorPrototype%.return ( value ) + + 5. Let return be GetMethod(syncIterator, "return"). + ... + ... + 8. Let returnResult be Call(return, syncIterator, « value »). + ... + 11. Let returnValue be IteratorValue(returnResult). + .. + 13. Let returnDone be IteratorComplete(returnResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, « returnValue »). + ... + 18. Set onFulfilled.[[Done]] to returnDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var returnCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get return() { + log.push({ + name: "get return", + thisValue: this + }); + return function() { + log.push({ + name: "call return", + thisValue: this, + args: [...arguments] + }); + + returnCount++; + if (returnCount == 1) { + return { + name: "return-result-1", + get value() { + log.push({ + name: "get return value (1)", + thisValue: this + }); + return "return-value-1"; + }, + get done() { + log.push({ + name: "get return done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "return-result-2", + get value() { + log.push({ + name: "get return value (2)", + thisValue: this + }); + return "return-value-2"; + }, + get done() { + log.push({ + name: "get return done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + yield* obj; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.return("return-arg-1").then(v => { + assert.sameValue(log[2].name, "get return"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[3].name, "call return"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "return thisValue"); + assert.sameValue(log[3].args.length, 1, "return args.length"); + assert.sameValue(log[3].args[0], "return-arg-1", "return args[0]"); + + assert.sameValue(log[4].name, "get return value (1)"); + assert.sameValue(log[4].thisValue.name, "return-result-1", "get return value thisValue"); + + assert.sameValue(log[5].name, "get return done (1)"); + assert.sameValue(log[5].thisValue.name, "return-result-1", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.return("return-arg-2").then(v => { + assert.sameValue(log[6].name, "get return"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get return thisValue"); + + assert.sameValue(log[7].name, "call return"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "get return thisValue"); + assert.sameValue(log[7].args.length, 1, "return args.length"); + assert.sameValue(log[7].args[0], "return-arg-2", "return args[0]"); + + assert.sameValue(log[8].name, "get return value (2)"); + assert.sameValue(log[8].thisValue.name, "return-result-2", "get return value thisValue"); + + assert.sameValue(log[9].name, "get return done (2)"); + assert.sameValue(log[9].thisValue.name, "return-result-2", "get return done thisValue"); + + assert.sameValue(v.value, "return-value-2"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 10, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); diff --git a/test/language/statements/class/async-gen-method-yield-star-sync-throw.js b/test/language/statements/class/async-gen-method-yield-star-sync-throw.js new file mode 100644 index 0000000000..75dc626762 --- /dev/null +++ b/test/language/statements/class/async-gen-method-yield-star-sync-throw.js @@ -0,0 +1,209 @@ +// This file was procedurally generated from the following sources: +// - src/async-generators/yield-star-sync-throw.case +// - src/async-generators/default/async-class-decl-method.template +/*--- +description: execution order for yield* with sync iterator and throw() (Async Generator method as a ClassDeclaration element) +esid: prod-AsyncGeneratorMethod +features: [async-iteration, async-iteration] +flags: [generated, async] +info: | + ClassElement : + MethodDefinition + + MethodDefinition : + AsyncGeneratorMethod + + Async Generator Function Definitions + + AsyncGeneratorMethod : + async [no LineTerminator here] * PropertyName ( UniqueFormalParameters ) { AsyncGeneratorBody } + + + YieldExpression: yield * AssignmentExpression + + ... + 6. Repeat + ... + b. Else if received.[[Type]] is throw, then + i. Let throw be ? GetMethod(iterator, "throw"). + ii. If throw is not undefined, then + 1. Let innerResult be ? Call(throw, iterator, « received.[[Value]] »). + 2. If generatorKind is async, then set innerResult to + ? Await(innerResult). + ... + 5. Let done be ? IteratorComplete(innerResult). + 6. If done is true, then + a. Return ? IteratorValue(innerResult). + 7. Let received be GeneratorYield(innerResult). + ... + + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + ... + 5. Let throw be GetMethod(syncIterator, "throw"). + ... + 8. Let throwResult be Call(throw, syncIterator, « value »). + ... + 11. Let throwValue be IteratorValue(throwResult). + ... + 13. Let throwDone be IteratorComplete(throwResult). + ... + 16. Perform ! Call(valueWrapperCapability.[[Resolve]], undefined, + « throwValue »). + ... + 18. Set onFulfilled.[[Done]] to throwDone. + 19. Perform ! PerformPromiseThen(valueWrapperCapability.[[Promise]], + onFulfilled, undefined, promiseCapability). + ... + +---*/ +var log = []; +var obj = { + [Symbol.iterator]() { + var throwCount = 0; + return { + name: "syncIterator", + get next() { + log.push({ name: "get next" }); + return function() { + return { + value: "next-value-1", + done: false + }; + }; + }, + get throw() { + log.push({ + name: "get throw", + thisValue: this + }); + return function() { + log.push({ + name: "call throw", + thisValue: this, + args: [...arguments] + }); + + throwCount++; + if (throwCount == 1) { + return { + name: "throw-result-1", + get value() { + log.push({ + name: "get throw value (1)", + thisValue: this + }); + return "throw-value-1"; + }, + get done() { + log.push({ + name: "get throw done (1)", + thisValue: this + }); + return false; + } + }; + } + + return { + name: "throw-result-2", + get value() { + log.push({ + name: "get throw value (2)", + thisValue: this + }); + return "throw-value-2"; + }, + get done() { + log.push({ + name: "get throw done (2)", + thisValue: this + }); + return true; + } + }; + }; + } + }; + } +}; + + + +var callCount = 0; + +class C { async *gen() { + callCount += 1; + log.push({ name: "before yield*" }); + var v = yield* obj; + log.push({ + name: "after yield*", + value: v + }); + return "return-value"; + +}} + +var gen = C.prototype.gen; + +var iter = gen(); + +assert.sameValue(log.length, 0, "log.length"); + +iter.next().then(v => { + assert.sameValue(log[0].name, "before yield*"); + + assert.sameValue(log[1].name, "get next"); + + assert.sameValue(v.value, "next-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 2, "log.length"); + + iter.throw("throw-arg-1").then(v => { + assert.sameValue(log[2].name, "get throw"); + assert.sameValue(log[2].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[3].name, "call throw"); + assert.sameValue(log[3].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[3].args.length, 1, "throw args.length"); + assert.sameValue(log[3].args[0], "throw-arg-1", "throw args[0]"); + + assert.sameValue(log[4].name, "get throw value (1)"); + assert.sameValue(log[4].thisValue.name, "throw-result-1", "get throw value thisValue"); + + assert.sameValue(log[5].name, "get throw done (1)"); + assert.sameValue(log[5].thisValue.name, "throw-result-1", "get throw done thisValue"); + + assert.sameValue(v.value, "throw-value-1"); + assert.sameValue(v.done, false); + + assert.sameValue(log.length, 6, "log.length"); + + iter.throw("throw-arg-2").then(v => { + assert.sameValue(log[6].name, "get throw"); + assert.sameValue(log[6].thisValue.name, "syncIterator", "get throw thisValue"); + + assert.sameValue(log[7].name, "call throw"); + assert.sameValue(log[7].thisValue.name, "syncIterator", "throw thisValue"); + assert.sameValue(log[7].args.length, 1, "throw args.length"); + assert.sameValue(log[7].args[0], "throw-arg-2", "throw args[0]"); + + assert.sameValue(log[8].name, "get throw value (2)"); + assert.sameValue(log[8].thisValue.name, "throw-result-2", "get throw value thisValue"); + + assert.sameValue(log[9].name, "get throw done (2)"); + assert.sameValue(log[9].thisValue.name, "throw-result-2", "get throw done thisValue"); + + assert.sameValue(log[10].name, "after yield*"); + assert.sameValue(log[10].value, "throw-value-2"); + + assert.sameValue(v.value, "return-value"); + assert.sameValue(v.done, true); + + assert.sameValue(log.length, 11, "log.length"); + }).then($DONE, $DONE); + }).catch($DONE); +}).catch($DONE); + +assert.sameValue(callCount, 1); -- GitLab