mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-26 06:34:20 +08:00
new DisposableStack() compiles to a native stack handle. use, adopt, defer, move, dispose, disposed and [Symbol.dispose] are members of its dynamic view, and the stack works with `using`. Disposal runs the resources in reverse order, calls use() resources' dispose methods with the resource as `this`, and raises a SuppressedError chain when more than one disposal throws; a single failure is rethrown as thrown. Calls on a disposed stack throw Node's ReferenceError, and invalid receivers, resources and callbacks throw Node's TypeErrors. use() of a class instance registers a function that calls the class's [Symbol.dispose] method, and returns the instance at its static type; use() of a union that includes class instances is refused. The stack is collected with its callbacks when a callback captures the stack. x instanceof DisposableStack compiles. Handles can expose symbol-keyed members through a new symbol_get hook.