Using Jslib from other Xpcom Components

View: New views
4 Messages — Rating Filter:   Alert me  

Using Jslib from other Xpcom Components

by Daniel Aquino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can I use jslib from my own xpcom components ?

My first attempt has shown that 'jslib' is not defined ever after 'final-ui-startup' has been observed...

_______________________________________________
Jslib mailing list
Jslib@...
http://mozdev.org/mailman/listinfo/jslib

Re: Using Jslib from other Xpcom Components

by Daniel Aquino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I tried to use the following code to load jslib from my component:

                try {
                  var jslib = Components.classes["@mozilla.org/jslib;1"]
                                        .createInstance(Components.interfaces.mozIJSLib);
                } catch (anError) {
                  dump("\t ERROR: " + anError + "\n");
                }

But I got the error:

-*- jsLib component: Not an nsIDOMChromeWindow

You can clearly see that the error is originating from the jsLib.prototype.init...

But from looking at how the constructor behaives,
I fear jslib is very tied to being in a window context...




_______________________________________________
Jslib mailing list
Jslib@...
http://mozdev.org/mailman/listinfo/jslib

Re: Using Jslib from other Xpcom Components

by Pete Collins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



Daniel Aquino wrote:

> Can I use jslib from my own xpcom components ?
>
> My first attempt has shown that 'jslib' is not defined ever after
> 'final-ui-startup' has been observed...


Sure I do it all the time. You need to use the subscript loader.

const CC = Components.classes;
const CI = Components.interfaces;


function initJSLib ()
{
  const jsLib = "chrome://jslib/content/jslib.js";
  CC["@mozilla.org/moz/jssubscript-loader;1"].
    getService(CI.mozIJSSubScriptLoader).loadSubScript(jsLib);

  JS_LIB_DEBUG = JS_LIB_ON;
  jslibTurnDumpOn();
  jslibTurnStrictOn();
}


Then just call this func from somewhere in your component to initialize it.

initJSLib();

--pete

--
Pete Collins - Founder, Mozdev Group Inc.
www.mozdevgroup.com
Mozilla Software Development Solutions
tel: 1-719-302-5811
fax: 1-719-302-5813

_______________________________________________
Jslib mailing list
Jslib@...
http://mozdev.org/mailman/listinfo/jslib

Re: Using Jslib from other Xpcom Components

by Daniel Aquino :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

awesome thanks!

_______________________________________________
Jslib mailing list
Jslib@...
http://mozdev.org/mailman/listinfo/jslib
LightInTheBox - Buy quality products at wholesale price