diff --git a/content/commands.js b/content/commands.js index 58834b55..94176fff 100644 --- a/content/commands.js +++ b/content/commands.js @@ -499,7 +499,8 @@ vimperator.Commands = function () //{{{ try { // TODO: move to vimperator.eval()? - arg = eval(arg); + // with (vimperator) means, vimperator is the default namespace "inside" eval + arg = eval("with(vimperator){" + arg + "}"); } catch (e) { @@ -666,7 +667,7 @@ vimperator.Commands = function () //{{{ { try { - eval(args); + eval("with(vimperator){" + args + "}"); } catch (e) { @@ -1567,7 +1568,7 @@ vimperator.Commands = function () //{{{ else { while (i--) - eval(args); + eval("with(vimperator){" + args + "}"); } if (special) @@ -1613,7 +1614,7 @@ vimperator.Commands = function () //{{{ if (args && args[0] == ":") vimperator.execute(args); else - eval(args); + eval("with(vimperator){" + args + "}"); if (special) return; diff --git a/content/completion.js b/content/completion.js index d5b34c78..315c1279 100644 --- a/content/completion.js +++ b/content/completion.js @@ -459,7 +459,7 @@ vimperator.Completion = function () //{{{ { substrings = []; var matches = str.match(/^(.*?)(\s*\.\s*)?(\w*)$/); - var object = "window"; + var objects = []; var filter = matches[3] || ""; var start = matches[1].length - 1; if (matches[2]) @@ -491,32 +491,37 @@ vimperator.Completion = function () //{{{ break outer; } } - object = matches[1].substr(start+1) || "window"; + + if (matches[1].substr(start+1)) + { + objects.push(matches[1].substr(start+1)); + } + else + { + objects.push("vimperator"); + objects.push("window"); + } var completions = []; try { - completions = eval( - "var comp = [];" + - "var type = '';" + - "var value = '';" + - "var obj = eval(" + object + ");" + - "for (var i in obj) {" + - " try { type = typeof(obj[i]); } catch (e) { type = 'unknown type'; };" + - " if (type == 'number' || type == 'string' || type == 'boolean') {" + - " value = obj[i];" + - " comp.push([[i], type + ': ' + value]); }" + - // The problem with that is that you complete vimperator. - // but can't press to complete sub items - // so it's better to complete vimperator and the user can do - // . to get the sub items - //" else if (type == 'function') {" + - //" comp.push([[i+'('], type]); }" + - //" else if (type == 'object') {" + - //" comp.push([[i+'.'], type]); }" + - " else {" + - " comp.push([[i], type]); }" + - "} comp;"); + for (var o = 0; o < objects.length; o++) + { + completions = completions.concat(eval( + "var comp = [];" + + "var type = '';" + + "var value = '';" + + "var obj = eval('with(vimperator){" + objects[o] + "}');" + + "for (var i in obj) {" + + " try { type = typeof(obj[i]); } catch (e) { type = 'unknown type'; };" + + " if (type == 'number' || type == 'string' || type == 'boolean') {" + + " value = obj[i];" + + " comp.push([[i], type + ': ' + value]); }" + + " else {" + + " comp.push([[i], type]); }" + + "} comp;" + )); + } } catch (e) { diff --git a/content/vimperator.js b/content/vimperator.js index b6a7bbdb..48257a76 100644 --- a/content/vimperator.js +++ b/content/vimperator.js @@ -623,7 +623,7 @@ const vimperator = (function () //{{{ // handle pure javascript files specially if (filename.search("\.js$") != -1) { - eval(str); + eval("with(vimperator){" + str + "}"); } else { @@ -635,7 +635,7 @@ const vimperator = (function () //{{{ { if (heredocEnd.test(line)) { - eval(heredoc); + eval("with(vimperator){" + heredoc + "}"); heredoc = ""; heredocEnd = null; }