1. Can we call XPCOM in js-ctype code?

2. What about this code in DeviceStorage implementation?
https://mxr.mozilla.org/mozilla-central/source/dom/devicestorage/nsDeviceStorage.cpp#1121

   nsCOMPtr<nsIEventTarget  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=nsIEventTarget>>target  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=target>  =do_GetService  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=do_GetService>(NS_STREAMTRANSPORTSERVICE_CONTRACTID  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=NS_STREAMTRANSPORTSERVICE_CONTRACTID>);
   NS_ASSERTION  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=NS_ASSERTION>(target,"Must
 have stream transport service");

   nsCOMPtr<InitCursorEvent  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=InitCursorEvent>>event  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=event>  =new  InitCursorEvent  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=InitCursorEvent>(this,mFile  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=mFile>);
   target  <http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=target>->Dispatch(  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=>event  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=event>,NS_DISPATCH_NORMAL  
<http://dxr.mozilla.org/search.cgi?tree=mozilla-central&string=NS_DISPATCH_NORMAL>);

I notice that there are assertions on both /NS_IsMainThread()/ and /!NS_IsMainThread()/. Seems like it really starts a backstage thread in DeviceStorage implementation. Is this true?/
/

--

Best regards,
??(Ray You)

On 12/20/12 7:35 PM, David Rajchenbach-Teller wrote:
On 12/20/12 7:27 AM, Ray You wrote:
How can we start a real thread in gecko using javascript and use XPCOM
in it?

Is dispatching events to /nsIStreamTransportService/ or
/nsIThreadManager.newThread(0) /the right way?
I don't think this is supported anymore. As far as I can tell, if you
truly need to call XPCOM from JS in a background thread, you need to do
the following:
- write extern "C" code that calls into XPCOM;
- launch a Chrome Worker from JS;
- link JS to your C shared lib through js-ctypes;
- call your C code from JS through js-ctypes.

Cheers,
  David


_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to