using/await using rejects bound functions and proxied callables as dispose methods
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
Version
v24.18.0
Platform
Microsoft Windows NT 10.0.26200.0 x64 (also reproduced on Linux x64 per downstream reports)
Subsystem
V8 / explicit resource management
What steps will reproduce the bug?
const fn = async function () { console.log('disposed'); };
// 1. bound function as async dispose method: throws
try {
await using a = { [Symbol.asyncDispose]: fn.bind(null) };
} catch (e) { console.log('bound async:', e.message); }
// 2. bound function as sync dispose method: throws
try {
using b = { [Symbol.dispose]: (function () {}).bind(null) };
} catch (e) { console.log('bound sync :', e.message); }
// 3. proxy-wrapped callable as dispose method: throws
try {
await using c = { [Symbol.asyncDispose]: new Proxy(fn, {}) };
} catch (e) { console.log('proxied fn :', e.message); }
// 4. ordinary function: works
await using d = { [Symbol.asyncDispose]: fn };
console.log('plain fn accepted');
Output:
bound async: Symbol(Symbol.asyncDispose) is not a function
bound sync : Symbol(Symbol.dispose) is not a function
proxied fn : Symbol(Symbol.asyncDispose) is not a function
plain fn accepted
disposed
What is the expected behavior? Why is that the expected behavior?
All four cases should dispose. Per the Explicit Resource Management proposal, the dispose method is retrieved with GetMethod, which throws only when the value is neither undefined nor callable. Bound function exotic objects and proxies over callables are both callable (typeof reports "function" and they invoke fine), so rejecting them deviates from the spec. It looks like the implementation checks for a specific function instance type rather than IsCallable.
What do you see instead?
TypeError: Symbol(Symbol.asyncDispose) is not a function (respectively Symbol.dispose) at the using declaration site, for values that are callable.
Additional information
Found while debugging unjs/jiti#437: jiti's interopDefault proxy returns bound methods, so any default export with [Symbol.asyncDispose] fails under native await using while typeof mod[Symbol.asyncDispose] === 'function' reports a callable. Downstream is working around it by not binding symbol-keyed methods, but the engine behavior affects any code that binds or proxies dispose methods, which is common in DI containers and instrumentation wrappers.
If this is already tracked in the V8 tracker, a pointer would be appreciated and this can be closed as upstream.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,在 Node v24.18.0 下运行 issue 的复现,并阅读涉及 dispose 方法查找的 V8 / explicit resource management 实现。将普通函数、绑定函数和 proxied 函数的 callable 检查与提案的 GetMethod 行为进行比较。四个示例都能成功 dispose,并且包含针对绑定 callable 和 proxied callable 的回归覆盖时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, nodejs
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100