mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 14:27:58 +01:00
Give *.penta plugins their own JS sandboxen.
--HG-- branch : key-processing
This commit is contained in:
@@ -380,15 +380,16 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
},
|
},
|
||||||
|
|
||||||
userEval: function (str, context, fileName, lineNumber) {
|
userEval: function (str, context, fileName, lineNumber) {
|
||||||
|
let ctxt;
|
||||||
if (jsmodules.__proto__ != window)
|
if (jsmodules.__proto__ != window)
|
||||||
str = "with (window) { with (modules) { (this.eval || eval)(" + str.quote() + ") } }";
|
str = "with (window) { with (modules) { (this.eval || eval)(" + str.quote() + ") } }";
|
||||||
|
|
||||||
if (fileName == null)
|
if (fileName == null)
|
||||||
if (io.sourcing && io.sourcing.file[0] !== "[")
|
if (io.sourcing && io.sourcing.file[0] !== "[")
|
||||||
({ file: fileName, line: lineNumber }) = io.sourcing;
|
({ file: fileName, line: lineNumber, context: ctxt }) = io.sourcing;
|
||||||
else try {
|
else try {
|
||||||
if (!context)
|
if (!context)
|
||||||
context = userContext;
|
context = userContext || ctxt;
|
||||||
|
|
||||||
context[EVAL_ERROR] = null;
|
context[EVAL_ERROR] = null;
|
||||||
context[EVAL_STRING] = str;
|
context[EVAL_STRING] = str;
|
||||||
@@ -411,7 +412,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!context)
|
if (!context)
|
||||||
context = _userContext;
|
context = _userContext || ctxt;
|
||||||
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
|
return Cu.evalInSandbox(str, context, "1.8", fileName, lineNumber);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -515,7 +515,7 @@ var Mappings = Module("mappings", {
|
|||||||
description: "Accept a count before the requisite key press"
|
description: "Accept a count before the requisite key press"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
names: ["-description", "-d"],
|
names: ["-description", "-desc", "-d"],
|
||||||
description: "A description of this mapping",
|
description: "A description of this mapping",
|
||||||
default: "User-defined mapping",
|
default: "User-defined mapping",
|
||||||
type: CommandOption.STRING
|
type: CommandOption.STRING
|
||||||
|
|||||||
@@ -1214,6 +1214,15 @@ update(iter, {
|
|||||||
func.call(self, val);
|
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
|
* Returns the array that results from applying *func* to each property of
|
||||||
* *obj*.
|
* *obj*.
|
||||||
|
|||||||
@@ -185,8 +185,10 @@ var IO = Module("io", {
|
|||||||
else if (/\.css$/.test(filename))
|
else if (/\.css$/.test(filename))
|
||||||
styles.registerSheet(uri.spec, false, true);
|
styles.registerSheet(uri.spec, false, true);
|
||||||
else {
|
else {
|
||||||
|
if (!(file.path in plugins))
|
||||||
|
plugins[file.path] = modules.newContext(modules.userContext);
|
||||||
modules.commands.execute(file.read(), null, silent || "loud", null,
|
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)
|
if (this._scriptNames.indexOf(file.path) == -1)
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ var JavaScript = Module("javascript", {
|
|||||||
if (obj.length) {
|
if (obj.length) {
|
||||||
let func = obj[0][0][funcName];
|
let func = obj[0][0][funcName];
|
||||||
if (callable(func)) {
|
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;
|
let n = this._get(i).comma.length;
|
||||||
args = template.map(Iterator(args.split(", ")),
|
args = template.map(Iterator(args.split(", ")),
|
||||||
function ([i, arg]) <span highlight={i == n ? "Filter" : ""}>{arg}</span>,
|
function ([i, arg]) <span highlight={i == n ? "Filter" : ""}>{arg}</span>,
|
||||||
|
|||||||
Reference in New Issue
Block a user