From 15e602780c92d6373d0fcfb2203b902243b512a8 Mon Sep 17 00:00:00 2001 From: Rezvan Mahdavi Hezaveh Date: Mon, 24 Feb 2025 12:20:46 -0800 Subject: [PATCH] [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 Commit-Queue: Rezvan Mahdavi Hezaveh Cr-Commit-Position: refs/heads/main@{#98898} --- ...al-from-sync-method-returning-a-promise.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/staging/explicit-resource-management/async-disposal-from-sync-method-returning-a-promise.js diff --git a/test/staging/explicit-resource-management/async-disposal-from-sync-method-returning-a-promise.js b/test/staging/explicit-resource-management/async-disposal-from-sync-method-returning-a-promise.js new file mode 100644 index 0000000000..94278e9c9e --- /dev/null +++ b/test/staging/explicit-resource-management/async-disposal-from-sync-method-returning-a-promise.js @@ -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]); +});