0

I am trying to implement nsIDOMGlobalPropertyInitializer::Init().

I have an existing object (based on Google Gears) that I am trying to extend to support JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY (since JAVASCRIPT_DOM_CLASS does not seem to work in FF17 anymore).

My implementation of nsIDOMGlobalPropertyInitializer::Init() is being called, but how do I convert my C++ object (it implements nsISupports and exposes the appropriate IDL) to JS:Value to make my object available in Java Script?

If I return NS_ERROR_NOT_IMPLEMENTED or do not implement the nsIDOMGlobalPropertyInitializer interface, FF (rightfully) complains that the no method or property is exposed by the object.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78

1 Answers1

0

You don't have to convert your object to JS:Value. If you implement XPCOM interfaces like nsISupports, they will be available in JavaScript. It's not clear from your description exactly what your object does, but you probably have to write a custom interface in IDL and implement it in your object. You can then manipulate it in JS through this interface. You should probably implement nsISecurityCheckedComponent and nsIClassInfo as well.

Matthew Gertner
  • 4,487
  • 2
  • 32
  • 54
  • Yes, my object already implements nsISupports. JAVASCRIPT_GLOBAL_CONSTRUCTOR_CATEGORY does not work in FF 17 anymore, so I am trying implement JAVASCRIPT_GLOBAL_PROPERTY_CATEGORY. But if I do that, FF does not see any properties or methods on my object because it requires the nsIDOMGlobalPropertyInitializer interface to be implemented. And to implement nsIDOMGlobalPropertyInitializer::Init, I need to cnvert my object to JS::Value. – Dmitry Streblechenko Apr 08 '13 at 17:08
  • Have you tried implementing `nsISecurityCheckedComponent`? It's more likely that this is the reason JS doesn't see your component's properties. As far as I know you don't need to implement `nsIDOMGlobalPropertyInitializer` unless you want your component to have access to the window (though they may have changed this since I like implemented a JS global property). – Matthew Gertner Apr 09 '13 at 08:39
  • nsIDOMGlobalPropertyInitializer did not help :-( FF does not even query my object for that interface. – Dmitry Streblechenko Apr 09 '13 at 23:48
  • As for the nsIDOMGlobalPropertyInitializer, I can see FF (from nsWindowSH::GlobalResolve() in nsDOMClassInfo.cpp) creating an instance of my global property and defaulting its value to JSVAL_VOID. It then proceeds to query my object for nsIDOMGlobalPropertyInitializer and calls nsIDOMGlobalPropertyInitializer::Init(), which is the method that I am having problems with... – Dmitry Streblechenko Apr 10 '13 at 00:06
  • You may be right. It looks like the changed the behavior in [bug 773803](https://bugzilla.mozilla.org/show_bug.cgi?id=773803), so perhaps now `nsIDOMGlobalPropertyInitializer` is required. You can instantiate XPConnect using XPCOM (basically `nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID()));`) but I'm not sure how you'd get the right `JSContext` from the window to create a `JSVal`. Any particular reason you can't simply implement your global property in JavaScript? – Matthew Gertner Apr 12 '13 at 10:19
  • In other words, use the XPCOM interfaces you added to your component to access the required functionality from your JS component, which will implement `nsIDOMGlobalPropertyInitializer`. It might be possible to create a `JSVal` in an extension from C++, but I'd have to do more research to figure out how. – Matthew Gertner Apr 12 '13 at 10:22