Execute javascript using c++ component

Discuss building things with or for the Mozilla Platform.
Post Reply
aarkan
Posts: 6
Joined: April 8th, 2014, 8:33 am

Execute javascript using c++ component

Post by aarkan »

I am embedding browser in my own c++ application using gecko sdk #28. To execute the javascipt from c++, I am using following code:

Code: Select all

       nsCOMPtr< nsIDocShell > docShell = do_GetInterface( mWebBrowser ); 
      if (docShell)
      {
         nsIScriptGlobalObject *theGlobalObject ;
         theGlobalObject = docShell->GetScriptGlobalObject();
         nsIScriptContext *theScriptContext = theGlobalObject->GetContext(); 
         nsresult rv ;
         auto ctx = theScriptContext->GetNativeContext();
         JS::CompileOptions options(ctx);
         JS::Rooted<JSObject *> handle(ctx);

         options.setFileAndLine("", 1);
         
         rv = theScriptContext->EvaluateString(script,
            handle, options, false, nullptr);      
      }


The program crashes while calling EvaluateString. I am unable to understand the reason. Please help.
Post Reply