[quickjs-devel] Re: Defining a finalizalizer for an object

  • From: "Eduard Suica" <dmarc-noreply@xxxxxxxxxxxxx> (Redacted sender "rokempes" for DMARC)
  • To: <quickjs-devel@xxxxxxxxxxxxx>
  • Date: Thu, 9 Jan 2020 19:51:16 +0000 (UTC)

 Cool idea, thank you. Do you know where I can find an example/documentation?
Thank you,GE.

    On Thursday, January 9, 2020, 9:45:40 PM GMT+2, Koushik Dutta 
<koush@xxxxxxxxxxxxxxxx> wrote:  
 
 It's not possible to do it for an arbitrary object, as far as I know. But my 
workaround is to create a custom class that is a "finalizer object", and then 
attach as a (hidden) property to any arbitrary object. I can then use the 
finalizer object to observe when the arbitrary object gets collected. The 
finalizer object gets collected at the same time as the arbitrary object; just 
ensure that the finalizer object is only referenced by that object.
Koush
On Thu, Jan 9, 2020 at 11:26 AM Eduard Suica <dmarc-noreply@xxxxxxxxxxxxx> 
wrote:

Is possible to define a finalizer/destructor for an object? Something like 
Duktape's fin function:
.fin(object, function(self) { ... } )
From the documentation: "When defining a new JS class, it is possible to 
declare a finalizerwhich is called when the object is destroyed. ". 

Is this possible for an arbitrary object? If yes, how?

Great project,GE.

  

Other related posts: