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
The current use of JS_AddInterruptCallback can provide a loose example of what the Rust code callback could look like. In the light of #30862, we should hide the use of jsapi inside dom/bindings, unlike what we did previously with JS_AddInterruptCallback.
What the DOM integration would look like is not completely clear to me yet, but it would seem that the callback should, when called, queue a task(or rather just send a message to the script or worker thread) that would then run something like the equivalent steps found here in Gecko
@gterzian Is this something that would be done with defining a new DOM binding via WebIDL and integrating the jsapi code in dom/bindings? I've been looking at FF/Chrome/Webkit and none of them seem to have IDL for FinalizationRegistry. (FF does but it just defines the callback if I understand correctly)
Re-reading the comments after pondering on this a bit I realize that there really isn't anything that needs to be exposed with WebIDL because this should be in the JS engine (and the comments above point that out).
I think I might have an idea of how this should go, and it looks like someone recently submitted a Spidermonkey-embedding-example for enabling FinalizationRegistry as well.
By the way in the light of #30862 it would be good to hide the JS_API stuff inside dom/bindings. See for example ongoing work with dom/bindings/typedarrays.rs.
I believe I have figured out how to set the realm options and callback in order for FinalizationRegistry to be enabled inside of SM.
I think I'm going to need a bit of mentoring on this one, I've got a few questions that I'm struggling with:
The example and FF both keep a vector of callbacks that they process. I'm struggling to understand what the type for this vec of JSFunctions should be for rooting and tracing purposes.
I think that using the Promise callback microtask queue would work for running the cleanup job but if there's another job queue that's better, it'd be good to know.
I'm not sure what the servo equivalent of ExposeObjectToActiveJS and JS_CallFunction is for running the callbacks.
I believe I have figured out how to set the realm options and callback in order for FinalizationRegistry to be enabled inside of SM.
Awesome!
Look into rooted_vec!
I think we can follow the example in your link and use the JobQueue
You probably will have to add manual code for your usecase, but the generated code can provide a useful example. For example if you build Servo locally, and search for DecodeErrorCallback, you can see some callback code generated in a file in target/(...)/Bindings/BaseAudioContextBinding.rs.
Hope this helps, let me know if you have other questions.
Activity
jdm commentedon Jan 12, 2024
This already present in Spidermonkey. We just haven't initializes the callbacks required to expose it and implement the DOM integration: https://searchfox.org/mozilla-central/source/js/src/shell/js.cpp#11041
jdm commentedon Jan 12, 2024
https://searchfox.org/mozilla-central/source/xpcom/base/CycleCollectedJSContext.cpp#859 is how Firefox uses it.
gterzian commentedon Jan 15, 2024
The current use of
JS_AddInterruptCallbackcan provide a loose example of what the Rust code callback could look like. In the light of #30862, we should hide the use ofjsapiinsidedom/bindings, unlike what we did previously withJS_AddInterruptCallback.gterzian commentedon Jan 15, 2024
What the DOM integration would look like is not completely clear to me yet, but it would seem that the callback should, when called, queue a task(or rather just send a message to the script or worker thread) that would then run something like the equivalent steps found here in Gecko
See also https://github.com/servo/mozjs/blob/191a3caafb7fb46e681fc45e07c94c290907abe5/mozjs-sys/mozjs/js/src/gc/FinalizationObservers.cpp#L296 (the part of the implementation in Spidermonkey that calls into the callback).
sebsebmc commentedon Feb 14, 2024
@gterzian Is this something that would be done with defining a new DOM binding via WebIDL and integrating the
jsapicode indom/bindings? I've been looking at FF/Chrome/Webkit and none of them seem to have IDL forFinalizationRegistry. (FF does but it just defines the callback if I understand correctly)sebsebmc commentedon Feb 14, 2024
Re-reading the comments after pondering on this a bit I realize that there really isn't anything that needs to be exposed with WebIDL because this should be in the JS engine (and the comments above point that out).
gterzian commentedon Feb 15, 2024
Right, this is more about using the JS_API to integrate with Servo, and also figuring out what Gecko does and whether we need to do anything similar.
sebsebmc commentedon Feb 15, 2024
I think I might have an idea of how this should go, and it looks like someone recently submitted a Spidermonkey-embedding-example for enabling FinalizationRegistry as well.
gterzian commentedon Feb 16, 2024
@sebsebmc I would say go for it!
By the way in the light of #30862 it would be good to hide the JS_API stuff inside
dom/bindings. See for example ongoing work withdom/bindings/typedarrays.rs.sebsebmc commentedon Feb 19, 2024
I believe I have figured out how to set the realm options and callback in order for FinalizationRegistry to be enabled inside of SM.
I think I'm going to need a bit of mentoring on this one, I've got a few questions that I'm struggling with:
ExposeObjectToActiveJSandJS_CallFunctionis for running the callbacks.gterzian commentedon Feb 20, 2024
Awesome!
rooted_vec!JobQueueDecodeErrorCallback, you can see some callback code generated in a file intarget/(...)/Bindings/BaseAudioContextBinding.rs.Hope this helps, let me know if you have other questions.