MozillaZine

Execute javascript using c++ component

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

Post Posted April 9th, 2014, 6:02 am

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.

Return to Mozilla Development


Who is online

Users browsing this forum: No registered users and 1 guest