[explicit-resource-management] Fix async disposal

This CL fixes the async disposal from sync methods that return
a promise. The result of calling `symbol.dispose` should
not be used to resolve the outer promise.

Bug: 42203814
Change-Id: I4c4573035b74b06ad78e2810e3f132301954c048
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6291492
Reviewed-by: Shu-yu Guo <syg@chromium.org>
Commit-Queue: Rezvan Mahdavi Hezaveh <rezvan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#98898}
This commit is contained in:
Rezvan Mahdavi Hezaveh 2025-02-24 12:20:46 -08:00 committed by test262-merge-bot
parent 44d71fbe7d
commit 15e602780c
1 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,32 @@
// Copyright (C) 2025 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Fix async disposal from sync method returning a promise.
includes: [asyncHelpers.js, compareArray.js]
flags: [async]
features: [explicit-resource-management]
---*/
asyncTest(async function() {
let values = [];
async function TestAsyncDisposalWithSyncMethodReturningAPromise() {
let stack = new AsyncDisposableStack();
const neverResolves = Promise.withResolvers().promise;
stack.use({
[Symbol.dispose]() {
return neverResolves
}
});
await stack.disposeAsync();
values.push(42);
await using x = {[Symbol.dispose]: () => neverResolves};
values.push(43);
};
await TestAsyncDisposalWithSyncMethodReturningAPromise();
assert.compareArray(values, [42, 43]);
});