[explicit-resource-management] Add test for async generator body

This cl adds a test for having `await using` in the async
generator function body.

Bug: 42203814
Change-Id: I30c0d2fe354a3047f67a4a71f7c6472c3d832bbf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5867651
Commit-Queue: Rezvan Mahdavi Hezaveh <rezvan@chromium.org>
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#96146}
This commit is contained in:
Rezvan Mahdavi Hezaveh 2024-09-17 12:19:35 -07:00 committed by test262-merge-bot
parent 867ca540d6
commit dfece8cfc5
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// Copyright (C) 2024 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test if disposed methods are called correctly in generator body.
includes: [asyncHelpers.js, compareArray.js]
flags: [async]
features: [explicit-resource-management]
---*/
asyncTest(async function() {
let generatorBodyValues = [];
async function* gen() {
await using x = {
value: 1,
[Symbol.asyncDispose]() {
generatorBodyValues.push(42);
}
};
yield x;
}
async function TestUsingInGeneratorBody() {
let iter = gen();
await iter.next();
assert.compareArray(generatorBodyValues, []);
iter.next().then((result) => assert.sameValue(result.value, 1));
generatorBodyValues.push(43);
}
await TestUsingInGeneratorBody();
assert.compareArray(generatorBodyValues, [42, 43]);
});