Skip to content

Commit

Permalink
[explicit-resource-management] Fix async disposal
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Rezvan Mahdavi Hezaveh <[email protected]>
Cr-Commit-Position: refs/heads/main@{#98898}
  • Loading branch information
rmahdav authored and test262-merge-bot committed Feb 24, 2025
1 parent 44d71fb commit 15e6027
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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]);
});

0 comments on commit 15e6027

Please sign in to comment.