You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is it possible to detect that a function was called with the using keyword? Going by #195 it seems not. Having the ability to detect that a variable was called without using using could help prevent leaking bugs where the intention of a function was to be called with using.
For example, I'd like a way so this throws an error:
functionopenFile(){letfptr=fopen()return{read(){if(!this.managedWithUsing)throwError('leak: use `using` when calling openFile()')}[Symbol.dispose](){free(fptr)}}}constfile=openFile()file.read()// throws leak error
The closest thing currently I can think of would be to use a FinalizationRegistry
But I'd imagine the overhead would be much higher and likely be less reliable this way (errors here can be called at arbitrary points of the program) than having a [Symbol.enter] or a maybe something like a decorator.
The text was updated successfully, but these errors were encountered:
It is possible to detect whether @@dispose was read by making it a getter, which might be "good enough" for some purposes. Anything more complex is better discussed in #195 or #49
Is it possible to detect that a function was called with the
using
keyword? Going by #195 it seems not. Having the ability to detect that a variable was called without usingusing
could help prevent leaking bugs where the intention of a function was to be called with using.For example, I'd like a way so this throws an error:
The closest thing currently I can think of would be to use a FinalizationRegistry
But I'd imagine the overhead would be much higher and likely be less reliable this way (errors here can be called at arbitrary points of the program) than having a [Symbol.enter] or a maybe something like a decorator.
The text was updated successfully, but these errors were encountered: