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 0000000000000000000000000000000000000000..f50070eb5fe15b166ecc6a38079b4fefdc7a00fd --- /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 0000000000000000000000000000000000000000..862d4b8e26a22c22ae4a240c752ae64b3f211862 --- /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 0000000000000000000000000000000000000000..20898e11ef116e82ec8db98f650b7076016cb264 --- /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 0000000000000000000000000000000000000000..89635bd15fc8c9af958a5055c0818612cf03e535 --- /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 0000000000000000000000000000000000000000..77479612f8308d63dcc5085a90900fe37a22befc --- /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 0000000000000000000000000000000000000000..e923a604c9f79830f57426c14fa7819456c7b0f5 --- /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 0000000000000000000000000000000000000000..b9109de63489cd3737bff2ca0484484b804e4e5e --- /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 0000000000000000000000000000000000000000..44ba2b275bb42ef89938a15f423e09bc65b5200f --- /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 0000000000000000000000000000000000000000..c18f7bbef03ead307c310cf90753e4d8811d83fc --- /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 0000000000000000000000000000000000000000..cd170c93fac7774685a74989c4b2455a9da75099 --- /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 0000000000000000000000000000000000000000..5d081b1b664a2e086f1ec7855cac2ba09b7aa7ce --- /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 0000000000000000000000000000000000000000..b0d8e0015bd56a71bb77517abdffe4993ae8d65f --- /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 0000000000000000000000000000000000000000..57ada56da139eb5e3035fdaf4aaef1735f833a8e --- /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 0000000000000000000000000000000000000000..2570ccc187404710d1f95602f9148cff298776b4 --- /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 0000000000000000000000000000000000000000..2d068919e66288ebd5a4ef4681268adaa2719710 --- /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 0000000000000000000000000000000000000000..ca93f9f57d0c40db79d8abcedf9becc1ca519c31 --- /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 0000000000000000000000000000000000000000..26377124acc09d145c6aa5472637242c61302071 --- /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 0000000000000000000000000000000000000000..156e2ef8594b52f6e80df3812f350a11e1c39a45 --- /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 0000000000000000000000000000000000000000..33306ad1146dd0148b2f45365e9f58c840a74267 --- /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 0000000000000000000000000000000000000000..d4fae2bd8eff33fdcc216451e93f23700d005ef3 --- /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 0000000000000000000000000000000000000000..460fd7004cb6d990036f21b31e7c085d3dd732f6 --- /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 0000000000000000000000000000000000000000..7034de91f4a6e030040ef7d99ab486c7420779e4 --- /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 0000000000000000000000000000000000000000..97c7c97a85a3598ef90cac244478bd081b61f885 --- /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 0000000000000000000000000000000000000000..ed940823b5bd663f84a689ebc29469c48245bd49 --- /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 0000000000000000000000000000000000000000..dad1843b82773db7834d800ea2dbc7e450cc9d5a --- /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 0000000000000000000000000000000000000000..512ab43c7e979ca2e6a80462832f5eb47181dfcb --- /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 0000000000000000000000000000000000000000..448934cd3028835da917aeee0bb7ce8b7c4bb510 --- /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 0000000000000000000000000000000000000000..c83ffa16efb673355c08da13c5a2cee1a704480d --- /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 0000000000000000000000000000000000000000..7f07943b5dd7aa9676104657a6fad2835873b466 --- /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 0000000000000000000000000000000000000000..cf0d11135d123449ccfff9b09ddff95225172526 --- /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 9eb6ec80a54777794f9adb97b1644b42c356373c..87845a14f1dc46d66fc7635f6f29071141c17c9d 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 f11d34abcf133186a9b83269342c87aeb6b995c9..6b6883d4531918150c28ec81f24f4f3fdb3dac3a 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 0e9feeb7744177036f4e3f8186a35c4e0e7809db..4c0c64e21af0153b5ee64c39249f14a934d8dda7 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 b57992c2e08a859e7def936f61572f4241072a42..bf68fe614db7954cf19dd21e3c41ce35bb0cb012 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 7252db75cbc19b23b58dc539e08ae94fa0169312..a627e8fda7e9e8c3e82219c5d4854e2a867f94bc 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 c67a73b79046bfc41456cb238f39028c6fa95915..9c5e0b8d8b08bc33b98b0b66c8897eaaf7dffffc 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 0000000000000000000000000000000000000000..1dfe8e25d74ec4efe4143059a84111a1c8fa5f65 --- /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 0000000000000000000000000000000000000000..dc4b7c90db948e560e57d6791478502164000087 --- /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 0000000000000000000000000000000000000000..905106e9affac8f067c576a284037708814eaa66 --- /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 0000000000000000000000000000000000000000..408fbc79b6d881126cac760abc5d0477e82fc7ba --- /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 0000000000000000000000000000000000000000..e4b46aae32ac37134f62752b22810478f1e3d95a --- /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 0000000000000000000000000000000000000000..3c265f5aecddaad6ed1b852e478fb73d8443633b --- /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 0000000000000000000000000000000000000000..7a43370f6c3afa6f2fa416bc4c7d05c1163b956b --- /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 0000000000000000000000000000000000000000..7a373dd230b65c5f8b9107878ebc0df8055c9efd --- /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 0000000000000000000000000000000000000000..ffa3a5216ecf89712278c191fb340ebf4f8fdeb3 --- /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 0000000000000000000000000000000000000000..3d139fb47caed782ff6f9f554ff1a7e0658e14c3 --- /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 0000000000000000000000000000000000000000..790ab292236082088be81e7f0a0895d38599a4ba --- /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 0000000000000000000000000000000000000000..75dc626762bf14dd45bba471dea906035d483a51 --- /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);