From 99eb79adec1e230ae2019a0bcdc02ceac1280b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sundstr=C3=B6m?= Date: Sat, 12 Sep 2009 23:14:42 -0700 Subject: [PATCH] Always use the latest available JavaScript engine. Fixes #1026 --- components/greasemonkey.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/components/greasemonkey.js b/components/greasemonkey.js index 1caeab1fa..1f86e5773 100644 --- a/components/greasemonkey.js +++ b/components/greasemonkey.js @@ -10,6 +10,21 @@ const appSvc = Cc["@mozilla.org/appshell/appShellService;1"] const gmSvcFilename = Components.stack.filename; +const maxJSVersion = (function getMaxJSVersion() { + // Default to version 1.6, which FF1.5 and later support. + var jsVersion = 160; + + var jsds = Cc["@mozilla.org/js/jsd/debugger-service;1"].getService() + .QueryInterface(Ci.jsdIDebuggerService); + jsds.on(); + jsds.enumerateContexts({ enumerateContext: function(context) { + if (context.version > jsVersion) jsVersion = context.version; + }}); + jsds.off(); + + return (jsVersion / 100).toString(); +})(); + function alert(msg) { Cc["@mozilla.org/embedcomp/prompt-service;1"] .getService(Ci.nsIPromptService) @@ -326,7 +341,7 @@ var greasemonkeyService = { try { // workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=307984 var lineFinder = new Error(); - Components.utils.evalInSandbox(code, sandbox); + Components.utils.evalInSandbox(code, sandbox, maxJSVersion); } catch (e) { // catches errors while running the script code try { if (e && "return not in function" == e.message)