Skip to content

Commit

Permalink
Oh, joy; now it works when run once at init time, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan Sundström committed Sep 13, 2009
1 parent e54f3cf commit 059f61d
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions components/greasemonkey.js
Expand Up @@ -10,8 +10,25 @@ const appSvc = Cc["@mozilla.org/appshell/appShellService;1"]

const gmSvcFilename = Components.stack.filename;

var jsds = Cc["@mozilla.org/js/jsd/debugger-service;1"].getService()
.QueryInterface(Ci.jsdIDebuggerService);
var maxJSVersion = (function getMaxJSVersion() {
var versions = [0];
var jsds = Cc["@mozilla.org/js/jsd/debugger-service;1"].getService()
.QueryInterface(Ci.jsdIDebuggerService);
jsds.on();
jsds.enumerateContexts({ enumerateContext: function(nsIContext) {
versions.push(nsIContext.version);
}});
jsds.off();

var max = Math.max.apply(Math, versions);
if (!max) return undefined; // worst case, evalInSandbox picks its default

// Ci.jsdIDebuggerService, in theory, has properties VERSION_<major>_<minor>
// constants whose value are the integer we have now -- but we can't reverse
// map them, as they are not fully populated (Firefox/3.5.3 supports 1.8 but
// has no constants beyond VERSION_1_5 = 150, for instance)
return (max / 100).toString();
})();

function alert(msg) {
Cc["@mozilla.org/embedcomp/prompt-service;1"]
Expand Down Expand Up @@ -287,25 +304,6 @@ var greasemonkeyService = {
}
},

// figure out the highest supported javascript version
getMaxJSVersion: function getMaxJSVersion() {
var versions = [0];
jsds.on();
jsds.enumerateContexts({ enumerateContext: function(nsIContext) {
versions.push(nsIContext.version);
}});
jsds.off();

var max = Math.max.apply(Math, versions);
if (!max) return undefined; // worst case, evalInSandbox picks its default

// Ci.jsdIDebuggerService, in theory, has properties VERSION_<major>_<minor>
// constants whose value are the integer we have now -- but we can't reverse
// map them, as they are not fully populated (Firefox/3.5.3 supports 1.8 but
// has no constants beyond VERSION_1_5 = 150, for instance)
return (max / 100).toString();
},

registerMenuCommand: function(unsafeContentWin, commandName, commandFunc,
accelKey, accelModifiers, accessKey) {
if (!GM_apiLeakCheck("GM_registerMenuCommand")) {
Expand Down Expand Up @@ -349,7 +347,7 @@ var greasemonkeyService = {
try {
// workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=307984
var lineFinder = new Error();
Components.utils.evalInSandbox(code, sandbox, this.getMaxJSVersion());
Components.utils.evalInSandbox(code, sandbox, maxJSVersion);
} catch (e) { // catches errors while running the script code
try {
if (e && "return not in function" == e.message)
Expand Down

2 comments on commit 059f61d

@Martii
Copy link

@Martii Martii commented on 059f61d Sep 13, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! "+1" from me :)

I'll post Linux older FF versions results here soon, but my Mac and Windows machine are sooooo slow... it took me several days to retest RC1 with the the simple first commit... so I would prefer and appreciate some help from the community as well as GM with those since I'm sure everyone has a faster machine.

I'm thinking about retesting FF 1.5.0 and FF 2.0.0 and FF 3.0.0 only to make things go quicker for retesting under Linux. Does this sound like a good idea?

@Martii
Copy link

@Martii Martii commented on 059f61d Sep 14, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you get another moment and hopefully ticket management is online... could you retake a look at this post. Thanks again for your hard work. :)

---- (this is just a link for those who are following you on their dashboard back to the ticket)
See also: #1026

Please sign in to comment.