Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Problem calling GM_getValue from GM_xmlhttpRequest onload function

#19

When the GM_xmlhttpRequest object's onload function calls GM_getValue I get the following error:

Error: Webmonkey access violation: file:///C:/github/webmonkey/src/modules/script/xhr.jsm cannot call GM_getValue().
Source File: file:///C:/Documents%20and%20Settings/erikvold/Application%20Data/Mozilla/Firefox/Profiles/elr5khso.erikvold/userscripts/uso-installwith/68219.js
Line: 15

The above was produced when using the uso - installWith userscript, and I tested userscript out on GM and it works fine.

Reported by Erik Vold · March 22nd, 2010 @ 03:09 PM

State: resolved
Milestone: none
Assigned to: Olivier Cornu Olivier Cornu

Activity

  1. Erik Vold
    Erik Vold

    I've made a simple test case here which works in GM and produces the following error in WM:

    Error: Webmonkey access violation: file:///C:/github/webmonkey/src/modules/script/xhr.jsm cannot call GM_getValue().
    Source File: file:///C:/Documents%20and%20Settings/erikvold/Application%20Data/Mozilla/Firefox/Profiles/elr5khso.erikvold/userscripts/wm_ticket_19_test_case/wm_ticket_19_test_case.user.js
    Line: 22

    March 22nd, 2010 @ 03:14 PM

  2. Erik Vold
    Erik Vold
    • Tag changed from #bug to #annoyance, #bug, :big
    • Assigned user set to Olivier Cornu

    March 22nd, 2010 @ 03:14 PM

  3. Erik Vold
    Erik Vold
    • Assigned user cleared.

    March 22nd, 2010 @ 03:15 PM

  4. Olivier Cornu
    Olivier Cornu
    • Assigned user set to Olivier Cornu

    Interesting. I don't recall changing many things in the xhr code, i'm curious to see where this comes from…

    Edit:
    Alright, it's not the xhr code: it's probably the apiLeakCheck code.
    I wish i could see the stack filenames (line 177) -- can't test it now.

    March 22nd, 2010 @ 03:44 PM

  5. Erik Vold
    Erik Vold

    Well the errors above are generated when the GM_getValue() function does the api check, and the api check function does appear to be slightly different..

    A difference appears to be between using the following for Greasemonkey:

    stack.filename != gmSvcFilename
    

    And the following for Webmonkey:

    stack.filename != FILE && this._files.indexOf(stack.filename) == -1
    

    I'm not sure if that makes any difference yet though..

    March 22nd, 2010 @ 04:09 PM

  6. Erik Vold
    Erik Vold

    bah I can't seem to edit my previous comment.. -1 point for lighthouse.. I meant apiLeakCheck* where I said "api check function"..

    March 22nd, 2010 @ 04:11 PM

  7. Erik Vold
    Erik Vold

    Well I was able to identify the problem..

    GM /components/greasemonkey.js line 48 is stack.filename != gmSvcFilename where gmSvcFilename is file:///C:/github/greasemonkey/components/greasemonkey.js for my test and stack,filename is chrome://greasemonkey/content/xmlhttprequester.js so line 48 fails, but line 49 stack.filename.substr(0, 6) != "chrome" is true in that case.

    WM /modules/script/api.jsm line 180 is stack.filename != FILE where FILE is file:///C:/github/webmonkey/src/modules/script/api.jsm and stack.filename is file:///C:/github/webmonkey/src/modules/script/xhr.jsm when the error is thrown.

    March 23rd, 2010 @ 06:45 AM

  8. Erik Vold
    Erik Vold

    One solution would be to export Components.stack.filename from xhr.jsm in some variable which is added to the if check started on line 177. The xhr.jsm is only used in api.jsm.

    March 23rd, 2010 @ 07:24 AM

  9. Olivier Cornu
    Olivier Cornu

    Alright, good catch. :-)

    In GM, every sub-script is loaded inside the GM service XPCOM thanks to mozIJSSubScriptLoader, thus appearing with a chrome:// URI in the call-stack. Whereas in WM, the script engine is divided in JS modules, which appear under their own file:// URI.
    Injection logic is also different: GM concatenates all userscript files (including its dependencies) in a string that is passed to evalInSandbox(), whereas WM uses a new evalInSandbox syntax that is called for each userscript file in turn. It makes for simpler and more accurate error-reporting code, and allows Firebug debugging of userscripts and their dependencies.
    Altogether, it makes for a slightly different approach to apiLeakCheck(). Of course it does not change its purpose: we must still make sure that calls to privileged GM API do not include a un-privileged URI in their stack. Privileged URI are either chrome, current userscript files, or the api.jsm file where all GM API functions are located.

    One solution would be to export Components.stack.filename from xhr.jsm in some variable which is added to the if check started on line 177.

    Yes, some trick like this is needed.
    An alternative would be to put xhr code into api.jsm, as it's only used there anyway. This way we'd stick to the current philosophy: api.jsm includes all API functions as well as API objects.

    bah I can't seem to edit my previous comment.. -1 point for lighthouse..

    Really? I could edit mine without problems yesterday…
    Perhaps there's an "edit timeout"?

    March 23rd, 2010 @ 11:41 AM

  10. Erik Vold
    Erik Vold

    An alternative would be to put xhr code into api.jsm, as it's only used there anyway. This way we'd stick to the current philosophy: api.jsm includes all API functions as well as API objects.

    I like this idea, the api.jsm file is a place that makes sense for this code imo.

    bah I can't seem to edit my previous comment.. -1 point for lighthouse..

    Really? I could edit mine without problems yesterday… Perhaps there's an "edit timeout"?

    I don't see an 'edit' link anywhere..

    March 23rd, 2010 @ 12:17 PM

  11. Olivier Cornu
    Olivier Cornu

    I like this idea, the api.jsm file is a place that makes sense for this code imo.

    Yes.
    By the way, the xhr code could use some cleaning too. :-)

    I don't see an 'edit' link anywhere..

    I see one on your post! Perhaps i'm the only one (admin) who can edit stuff?

    March 23rd, 2010 @ 12:27 PM

  12. Olivier Cornu

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.