From 787f0636922a2b490a68d6559c1196d69bfce84d Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 26 Jan 2011 14:35:58 -0500 Subject: [PATCH] Give *.penta plugins their own JS sandboxen. --HG-- branch : key-processing --- common/content/dactyl.js | 7 ++++--- common/content/mappings.js | 2 +- common/modules/base.jsm | 9 +++++++++ common/modules/io.jsm | 4 +++- common/modules/javascript.jsm | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index c53cb34b..0e3e10a1 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -380,15 +380,16 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { }, userEval: function (str, context, fileName, lineNumber) { + let ctxt; if (jsmodules.__proto__ != window) str = "with (window) { with (modules) { (this.eval || eval)(" + str.quote() + ") } }"; if (fileName == null) if (io.sourcing && io.sourcing.file[0] !== "[") - ({ file: fileName, line: lineNumber }) = io.sourcing; + ({ file: fileName, line: lineNumber, context: ctxt }) = io.sourcing; else try { if (!context) - context = userContext; + context = userContext || ctxt; context[EVAL_ERROR] = null; context[EVAL_STRING] = str; @@ -411,7 +412,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { } if (!context) - context = _userContext; + context = _userContext || ctxt; return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber); }, diff --git a/common/content/mappings.js b/common/content/mappings.js index 1beae7bb..3e86257c 100644 --- a/common/content/mappings.js +++ b/common/content/mappings.js @@ -515,7 +515,7 @@ var Mappings = Module("mappings", { description: "Accept a count before the requisite key press" }, { - names: ["-description", "-d"], + names: ["-description", "-desc", "-d"], description: "A description of this mapping", default: "User-defined mapping", type: CommandOption.STRING diff --git a/common/modules/base.jsm b/common/modules/base.jsm index 1de0923f..da094eff 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -1214,6 +1214,15 @@ update(iter, { func.call(self, val); }, + indexOf: function indexOf(iter, elem) { + let i = 0; + for (let item in iter) { + if (item == elem) + return i; + i++; + } + }, + /** * Returns the array that results from applying *func* to each property of * *obj*. diff --git a/common/modules/io.jsm b/common/modules/io.jsm index d49f2349..e8fb057f 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -185,8 +185,10 @@ var IO = Module("io", { else if (/\.css$/.test(filename)) styles.registerSheet(uri.spec, false, true); else { + if (!(file.path in plugins)) + plugins[file.path] = modules.newContext(modules.userContext); modules.commands.execute(file.read(), null, silent || "loud", null, - { file: file.path, line: 1 }); + { file: file.path, line: 1, context: plugins[file.path] }); } if (this._scriptNames.indexOf(file.path) == -1) diff --git a/common/modules/javascript.jsm b/common/modules/javascript.jsm index ab76a98a..9d83a52f 100644 --- a/common/modules/javascript.jsm +++ b/common/modules/javascript.jsm @@ -478,7 +478,7 @@ var JavaScript = Module("javascript", { if (obj.length) { let func = obj[0][0][funcName]; if (callable(func)) { - let [, prefix, args] = /^(function .*?)\((.*)?\)/.exec(Function.prototype.toString.call(func)); + let [, prefix, args] = /^(function .*?)\((.*?)\)/.exec(Function.prototype.toString.call(func)); let n = this._get(i).comma.length; args = template.map(Iterator(args.split(", ")), function ([i, arg]) {arg},