tc39/proposal-explicit-resource-management

What is an expected behaviour if I replace @@dispose symbol after using?

Closed this issue · 1 comments

If I have some disposable object, which dispose function call is expected if I replace it right after using syntax call.

{
    using obj = { [Symbol.dispose]: () => { console.log("original"); } };
    obj[Symbol.dispose] = () => { console.log("replaced"); };
}

My gut feeling saying that original string must be printed. But that's depend on the implementation of using syntax.

Option A: If using captures pair (@@disposable, this=obj for dispose call) - then original will be printed.
Option B: If using captures only object itself - then I can potentially damage this disposable call later, by not only changing the symbol value but also removing it completely.

The same question for @@asyncDispose symbol, but I guess behaviour must be the same.

I didn't find anything about it in the proposal description, so I decided to ask here. Current polyfill behaviour returning original string, and seems like doesn't captures this. On dispose call this = undefined. Is it intended and implementers must bind their dispose implementations manually?