From:  Vasu Yadav <vasuyadavkrishn@gmail.com>
Date:  10 Oct 2013 18:48:37 Hong Kong Time
Newsgroup:  news.mozilla.org/mozilla.announce.compatibility
Subject:  

How to instantiate JavaScript component from C++ XPCOM component.

NNTP-Posting-Host:  59.163.206.21

Hi


Could you please help me " Instantiate JavaScript XPCOM Component from C++ XPCOM Component/ C++ Code"

I have tried one same code given below.

HellowWorld.js
------------------------------------
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");

function HelloWorld()
 {
 }

HelloWorld.prototype = {
  classDescription: "My Hello World Javascript XPCOM Component",
  classID:          Components.ID("{1b635320-30a8-11e3-aa6e-0800200c9a66}"),
  contractID:       "@keynote.com/firefox/helloworld;1",
  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIHelloWorld]),
  Hellovasu: function() { 
  //alert(" Welcome to JS -XPCOM");
  return "Hello World!"; }
};
var components = [HelloWorld];
if ("generateNSGetFactory" in XPCOMUtils)
  var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);  // Firefox 4.0 and higher
else
  var NSGetModule = XPCOMUtils.generateNSGetModule(components);    // Firefox 3.x

--------------------------------------------------------------------------------

HelloWorld.idl
----------------------------------------------------
#include "nsISupports.idl"

[scriptable, uuid(1b635320-30a8-11e3-aa6e-0800200c9a66)]
interface nsIHelloWorld : nsISupports
{
  string Hellovasu();
};  
--------------------------------------------------------------------

I create header and .xpt file using python.

Instantiate JavaScript XPCOM Component from C++ code.
nsresult rvp; 
nsCOMPtr hello = do_CreateInstance("@keynote.com/Firefox/helloworld;1", &rvp));

 Not able to instantiate nsIHelloWorld component. do you fell anything wrong or incorrect in code?


why is it generating string Hellovasu () function to Hellovasu(char * *_retval) in header file.



/* string Hellovasu (); */
NS_IMETHODIMP nsHelloWorld::Hellovasu(char * *_retval)
{
    return NS_ERROR_NOT_IMPLEMENTED;
}

Regards
Vasu