On 03/20/2014 12:37 PM, David Rajchenbach-Teller wrote:
So basically, you want to add a finalizer for JS component?

No. It would be callback to tell when the thing (wrappedJS) we have a weakref to
is going away. And wrappedJS keeps then a weak ref to the JS object.
As far as I see, this would be trivial to implement, at least if
we don't mind adding a word to nsXPCWrappedJS.
If we do mind, then some tricks need to be done.

Also, this all could be done outside JS engine, so the native services wouldn't
need to start care about JS API.

(Looks like the current nsXPCWrappedJS fits just perfectly into
jemalloc's 112 bucket on 64bit, but on 32bit case we have room for an extra 
word)


Note that we already have a weak (post-mortem) finalization module for
JS, hidden somewhere in mozilla-central. It's not meant to be used for
performance critical code, and it provides no guarantees about cycles,
but if this is necessary, I could rework it in something a bit
faster/more robust.

Cheers,
  David

On 3/20/14 1:25 AM, smaug wrote:
And we could add a flag to WrappedJS so that it would call some callback
when it is about
to go away. That would let cleanup of WeakPromise happen asap.
Basically keep a hashtable wrappedjs ->
objects_implementing_callback_interface_foo.
Then when adding an object to the hashtable, wrappedjs would get marked
with a flag, that
it should look at the hashtable when it is going away, and if there is
value in the hashtable,
call the foo.

This cleanup mechanism could be used with weak observers and weak
listeners too.


-Olli
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform



_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to