mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-23 10:47:59 +01:00
Wrap eval in try-catch in javascript completer
This commit is contained in:
@@ -304,6 +304,15 @@ liberator.Completion = function () //{{{
|
|||||||
|
|
||||||
javascript: function (str)
|
javascript: function (str)
|
||||||
{
|
{
|
||||||
|
let eval = function (arg)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return window.eval(arg);
|
||||||
|
}
|
||||||
|
catch(e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
/* Search the object for strings starting with @key.
|
/* Search the object for strings starting with @key.
|
||||||
* If @fn is defined, slice @offset characters from
|
* If @fn is defined, slice @offset characters from
|
||||||
* the results and map them via @fn.
|
* the results and map them via @fn.
|
||||||
@@ -317,7 +326,7 @@ liberator.Completion = function () //{{{
|
|||||||
for (let [,obj] in Iterator(objects))
|
for (let [,obj] in Iterator(objects))
|
||||||
{
|
{
|
||||||
if (typeof obj == "string")
|
if (typeof obj == "string")
|
||||||
obj = window.eval("with (liberator) {" + obj + "}");
|
obj = eval("with (liberator) {" + obj + "}");
|
||||||
if (typeof obj != "object")
|
if (typeof obj != "object")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -333,8 +342,10 @@ liberator.Completion = function () //{{{
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (["string", "number", "boolean", "function"].indexOf(type) > -1)
|
if (["string", "number", "boolean"].indexOf(type) > -1)
|
||||||
type += ": " + String(v).replace("\n", "\\n", "g");
|
type += ": " + String(v).replace("\n", "\\n", "g");
|
||||||
|
if (type == "function")
|
||||||
|
type += ": " + v.toSource.replace(/\{.*/, "{ ... }");
|
||||||
|
|
||||||
compl.push([k, type]);
|
compl.push([k, type]);
|
||||||
}
|
}
|
||||||
@@ -477,11 +488,11 @@ liberator.Completion = function () //{{{
|
|||||||
* key = "bar + ''"
|
* key = "bar + ''"
|
||||||
*/
|
*/
|
||||||
let string = str.substring(top[OFFSET] + 1);
|
let string = str.substring(top[OFFSET] + 1);
|
||||||
string = window.eval(last + string + last);
|
string = eval(last + string + last);
|
||||||
|
|
||||||
let obj = preEval + str.substring(get(-3, 0, STATEMENTS), get(-2)[OFFSET]);
|
let obj = preEval + str.substring(get(-3, 0, STATEMENTS), get(-2)[OFFSET]);
|
||||||
let key = preEval + str.substring(get(-2)[OFFSET] + 1, top[OFFSET]) + "''";
|
let key = preEval + str.substring(get(-2)[OFFSET] + 1, top[OFFSET]) + "''";
|
||||||
key = window.eval(key);
|
key = eval(key);
|
||||||
return [top[OFFSET], objectKeys(obj, key + string, liberator.util.escapeString, key.length, last)];
|
return [top[OFFSET], objectKeys(obj, key + string, liberator.util.escapeString, key.length, last)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user