Written on Jul 20, 2018
I need to figure out how the newly created Service object will be used by the js consumers. I found some classes where they also create a new object in js and now I need to look for classes where the new component is created using JS_NewPlainObject and returned.
ChromeUtils
ChromeUtils is not exactly the same as Services.jsm because one can do ChromeUtils.import("resource://gre/modules/Services.jsm")nsFrameMessageManager
.jsm files are treated. Maybe there are some that are implemented in C++.Update
Actually, I realized it’s okay that ChromeUtils is not exactly like Services.jsm because I just need an example of how C++ interfaces get exposed to JS code. Perhaps, it is through webidl.
Actually
It won’t work because ChromeUtils as an object is already exposed through webidl, and it uses low level JS APIs to create a copy of it. But the method that created a copy of itself is defined on an alerady existing object. So it won’t work 100% for me.
3:28 pm
Perhaps, I will look instead at functions that have the following function declaration
myFunc(JSContext* aCx, JS::MutableHandleValue aResult) and see they are exposed.
I found this https://searchfox.org/mozilla-central/source/widget/GfxInfoBase.cpp#1205.
.idl file.4:01 pm
I don’t think I should be creating new webidl file because that means I will be creating Services object in C++. Furthermore, if I can’t really generate a webidl file.
4:54 pm
I discovered a Components object. Per https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Language_Bindings/Components_object
The
Componentsobject is the object through whichXPConnectfunctionality is reflected into JavaScript.
5:49 pm
Success!!! I have managed to create an API in C++ in the Components class and expose it
to js. TODO This is how I did it.
Things to do