many loading of the same object - Mozilla

This is a discussion on many loading of the same object - Mozilla ; Hi, I've got a problem with my script, it's loading several times. I use an object that create an access to a sqlite database. However, il this object is created twice, the access at the base is read-only. So, I ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: many loading of the same object

  1. many loading of the same object

    Hi,

    I've got a problem with my script, it's loading several times. I use
    an object that create an access to a sqlite database. However, il this
    object is created twice, the access at the base is read-only. So, I
    created a verification : if only the object is undefined, created it.
    Actually, it loads two scripts : the first is loading at start in
    browser.xui ; the second is loading when I type the adress in the bar
    adress. However, the two don't seem communicate, and recreate this
    object.
    However, my object is not created with the "var" instruction
    (javascript), so might it be global ?

    A last example, clearer I hope. In the same script, I use two
    functions because my extension has two modules, ergodoc and
    nattracer :
    function edDump(e)
    {
    try {
    edCount += 1;
    } catch(err) {
    edCount = 1;
    }
    dump("[ERGODOC " + edCount + "] " + e + "\n");
    }

    function ntDump(e)
    {
    try {
    edCount += 1;
    } catch(err) {
    edCount = 1;
    }
    dump("[NAVTRACER " + edCount + "] " + e + "\n");
    }
    There is on variable (edCount), and I get two counters (!) :
    [ERGODOC 253] tabRefresh : traceShowTable
    [NAVTRACER 85] NVonBlur : chrome://ergodoc/content/ergodoc.xul
    [NAVTRACER 86] NVonClick : [object MouseEvent] 916
    [ERGODOC 254] tabRefresh : initErgodoc


    Thanks for help,
    Thibaud.

  2. Re: many loading of the same object

    On 25 Sep, 23:33, thibaud wrote:
    > Hi,
    >
    > I've got a problem with my script, it's loading several times. I use
    > an object that create an access to a sqlite database. However, il this
    > object is created twice, the access at the base is read-only. So, I
    > created a verification : if only the object is undefined, created it.
    > Actually, it loads two scripts : the first is loading at start in
    > browser.xui ; the second is loading when I type the adress in the bar
    > adress. However, the two don't seem communicate, and recreate this
    > object.
    > However, my object is not created with the "var" instruction
    > (javascript), so might it be global ?
    >
    > A last example, clearer I hope. In the same script, I use two
    > functions because my extension has two modules, ergodoc and
    > nattracer :
    > function edDump(e)
    > {
    > * * * * try {
    > * * * * * * * * edCount += 1;
    > * * * * } catch(err) {
    > * * * * * * * * edCount = 1;
    > * * * * }
    > * * * * dump("[ERGODOC " + edCount + "] " + e *+ "\n");
    >
    > }
    >
    > function ntDump(e)
    > {
    > * * * * try {
    > * * * * * * * * edCount += 1;
    > * * * * } catch(err) {
    > * * * * * * * * edCount = 1;
    > * * * * }
    > * * * * dump("[NAVTRACER " + edCount + "] " + e *+ "\n");}
    >
    > There is on variable (edCount), and I get two counters (!) :
    > [ERGODOC 253] tabRefresh : traceShowTable
    > [NAVTRACER 85] NVonBlur : chrome://ergodoc/content/ergodoc.xul
    > [NAVTRACER 86] NVonClick : [object MouseEvent] 916
    > [ERGODOC 254] tabRefresh : initErgodoc
    >
    > Thanks for help,
    > Thibaud.


    The best way to incapsulate shared object is JavaScript module:
    https://developer.mozilla.org/en/Usi...t_code_modules

    Instance of object creates once even for two Firefox windows, so you
    can put interface to your database here.

  3. Re: many loading of the same object

    Thanks, I think this is the good way. I configured with the
    documentation, however I get an error with this instruction:
    Components.utils.import("ressource://modules//libraries.js");

    The error:
    [Exception... "Component returned failure code: 0x80070057
    (NS_ERROR_ILLEGAL_VALUE) [nsIXPCComponents_Utils.import]" nsresult:
    "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame ::
    chrome://ergodoc/content/navtracer/common.js :: :: line
    7" data: no]

    However, I added this line at my chrome.manifest :
    resource modules
    chrome://ergodoc/content/javscript/modules/

    And I added this above my modules :
    var EXPORTED_SYMBOLS = ["edDump", "ntDump"];

    What have I forgotten ?

    Thanks,
    Thibaud.

    On Sep 26, 10:24*am, ant_katcin wrote:
    > On 25 Sep, 23:33, thibaud wrote:
    >
    >
    >
    > > Hi,

    >
    > > I've got a problem with my script, it's loading several times. I use
    > > an object that create an access to a sqlite database. However, il this
    > > object is created twice, the access at the base is read-only. So, I
    > > created a verification : if only the object is undefined, created it.
    > > Actually, it loads two scripts : the first is loading at start in
    > > browser.xui ; the second is loading when I type the adress in the bar
    > > adress. However, the two don't seem communicate, and recreate this
    > > object.
    > > However, my object is not created with the "var" instruction
    > > (javascript), so might it be global ?

    >
    > > A last example, clearer I hope. In the same script, I use two
    > > functions because my extension has two modules, ergodoc and
    > > nattracer :
    > > function edDump(e)
    > > {
    > > * * * * try {
    > > * * * * * * * * edCount += 1;
    > > * * * * } catch(err) {
    > > * * * * * * * * edCount = 1;
    > > * * * * }
    > > * * * * dump("[ERGODOC " + edCount + "] " + e *+ "\n");

    >
    > > }

    >
    > > function ntDump(e)
    > > {
    > > * * * * try {
    > > * * * * * * * * edCount += 1;
    > > * * * * } catch(err) {
    > > * * * * * * * * edCount = 1;
    > > * * * * }
    > > * * * * dump("[NAVTRACER " + edCount + "] " + e *+ "\n");}

    >
    > > There is on variable (edCount), and I get two counters (!) :
    > > [ERGODOC 253] tabRefresh : traceShowTable
    > > [NAVTRACER 85] NVonBlur : chrome://ergodoc/content/ergodoc.xul
    > > [NAVTRACER 86] NVonClick : [object MouseEvent] 916
    > > [ERGODOC 254] tabRefresh : initErgodoc

    >
    > > Thanks for help,
    > > Thibaud.

    >
    > The best way to incapsulate shared object is JavaScript module:https://developer.mozilla.org/en/Usi...t_code_modules
    >
    > Instance of object creates once even for two Firefox windows, so you
    > can put interface to your database here.



  4. Re: many loading of the same object

    On 28 sep, 18:51, Neil wrote:
    > thibaud wrote:
    > >However, I added this line at my chrome.manifest :
    > >resource modules
    > >chrome://ergodoc/content/javscript/modules/

    >
    > I don't think you can import modules from chrome resources yet.
    >
    > --
    > Warning: May contain traces of nuts.


    In this case, I don't understand where to put my script, because I
    create an alias from resource in chrome.manifest :
    "The easiest way for extensions and XUL applications to add custom
    aliases is by registering an alias in the chrome manifest using a line
    like this: resource aliasname uri/to/files/"

  5. Re: many loading of the same object

    Example of using JavaScript modules you can find in DownThemAll!
    extension.

    https://addons.mozilla.org/en-US/firefox/addon/201

    Just look into xpi.

+ Reply to Thread