I’ve been able to embed webkit control into a windows (c++) application, and registered my custom object for javascript to access (using JSGlobalContextRef, JSObjectMake etc.). Successfully tested calls from JavaScript to c++ layer for simple methods that returns string or int.
Now i want to expose one custom method that would internally use a COM library & ultimately return a IDispatch pointer (wrapped as VARIANT or otherwise). How to I convert IDispatch pointer to JSValueRef, JSObjectRef or anything else that JavaScript (inside webkit) would understand ?
In the IE browser control world, I could simply expose the IDispatch via the “getExternal” (IDocHostUIHandler interface) or even wrap it up in a VARIANT and return as Out-Param of any other API inside the custom “external” object.
This question doesn’t have an easy, n-step answer. I found code via Google searching that addressed a similar problem, that of accessing COM objects from SpiderMonkey. I can give you the approach you might take, the actual code I no longer have a link to, and it is SpiderMonkey-specific anyway.
Your Javascript engine has some means to extend it with custom objects, which you are clearly already using. You need to define that this new method you’re implementing returns yet another type of custom object, and put the IDispatch pointer in that custom object’s custom data. Your JS engine won’t “understand” or care that the custom object is a facade over an ActiveX object. You just set up this type of custom object so that when its Frob method is invoked your facade delegates the call down to the Frob DISPID on IDispatch.
If this answer is unclear, give me a clue that we are at least speaking the same language.