From 02013fd1d6e109f0cd48157645dac1634efaee59 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Wed, 27 May 2020 12:33:01 +0300 Subject: [PATCH] Add AsyncFromSyncIterator tests --- .../return/return-null.js | 53 ++++++++++++++++ .../throw/throw-null.js | 62 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 test/built-ins/AsyncFromSyncIteratorPrototype/return/return-null.js create mode 100644 test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js diff --git a/test/built-ins/AsyncFromSyncIteratorPrototype/return/return-null.js b/test/built-ins/AsyncFromSyncIteratorPrototype/return/return-null.js new file mode 100644 index 0000000000..1ca881ab5e --- /dev/null +++ b/test/built-ins/AsyncFromSyncIteratorPrototype/return/return-null.js @@ -0,0 +1,53 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%asyncfromsynciteratorprototype%.return +description: > + If syncIterator's "return" method is `null`, + a Promise resolved with `undefined` value is returned. +info: | + %AsyncFromSyncIteratorPrototype%.return ( value ) + + [...] + 5. Let return be GetMethod(syncIterator, "return"). + [...] + 7. If return is undefined, then + a. Let iterResult be ! CreateIterResultObject(value, true). + b. Perform ! Call(promiseCapability.[[Resolve]], undefined, « iterResult »). + c. Return promiseCapability.[[Promise]]. + + GetMethod ( V, P ) + + [...] + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. +flags: [async] +features: [async-iteration] +---*/ + +var iterationCount = 0; +var returnGets = 0; + +var syncIterator = { + [Symbol.iterator]() { + return this; + }, + next() { + return {value: 1, done: false}; + }, + get return() { + returnGets += 1; + return null; + }, +}; + +(async function() { + for await (let _ of syncIterator) { + iterationCount += 1; + break; + } + + assert.sameValue(iterationCount, 1); + assert.sameValue(returnGets, 1); +}()).then($DONE, $DONE); diff --git a/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js b/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js new file mode 100644 index 0000000000..235210bf9b --- /dev/null +++ b/test/built-ins/AsyncFromSyncIteratorPrototype/throw/throw-null.js @@ -0,0 +1,62 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%asyncfromsynciteratorprototype%.throw +description: > + If syncIterator's "throw" method is `null`, + a Promise rejected with provided value is returned. +info: | + %AsyncFromSyncIteratorPrototype%.throw ( value ) + + [...] + 5. Let throw be GetMethod(syncIterator, "throw"). + [...] + 7. If throw is undefined, then + a. Perform ! Call(promiseCapability.[[Reject]], undefined, « value »). + b. Return promiseCapability.[[Promise]]. + + GetMethod ( V, P ) + + [...] + 2. Let func be ? GetV(V, P). + 3. If func is either undefined or null, return undefined. +flags: [async] +features: [async-iteration] +---*/ + +var throwGets = 0; +var syncIterator = { + [Symbol.iterator]() { + return this; + }, + next() { + return {value: 1, done: false}; + }, + get throw() { + throwGets += 1; + return null; + }, +}; + +async function* asyncGenerator() { + yield* syncIterator; +} + +var asyncIterator = asyncGenerator(); +asyncIterator.next().then(function() { + var thrownError = { name: "err" }; + asyncIterator.throw(thrownError).then( + function(result) { + throw new Test262Error("Promise should be rejected, got: " + result.value); + }, + function(err) { + assert.sameValue(err, thrownError); + + asyncIterator.next().then(function(result) { + assert.sameValue(result.value, undefined); + assert.sameValue(result.done, true); + }).then($DONE, $DONE); + } + ).catch($DONE); +}).catch($DONE);