mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-22 17:57:58 +01:00
Co-opt :js! for REPL. Add optional context argument. Add docs. Fix history bug.
This commit is contained in:
@@ -402,7 +402,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
if (info && info.file[0] !== "[")
|
if (info && info.file[0] !== "[")
|
||||||
({ file: fileName, line: lineNumber, context: ctxt }) = info;
|
({ file: fileName, line: lineNumber, context: ctxt }) = info;
|
||||||
|
|
||||||
if (!context)
|
if (!context && fileName && fileName[0] !== "[")
|
||||||
context = _userContext || ctxt;
|
context = _userContext || ctxt;
|
||||||
|
|
||||||
if (isinstance(context, ["Sandbox"]))
|
if (isinstance(context, ["Sandbox"]))
|
||||||
|
|||||||
@@ -90,7 +90,6 @@
|
|||||||
<tags>:js :javas :javascript</tags>
|
<tags>:js :javas :javascript</tags>
|
||||||
<spec>:javas<oa>cript</oa> <a>cmd</a></spec>
|
<spec>:javas<oa>cript</oa> <a>cmd</a></spec>
|
||||||
<spec>:javascript <<<a>endpattern</a>\n<a>cmd</a>\n<a>endpattern</a></spec>
|
<spec>:javascript <<<a>endpattern</a>\n<a>cmd</a>\n<a>endpattern</a></spec>
|
||||||
<spec>:javascript<oa>!</oa></spec>
|
|
||||||
<description>
|
<description>
|
||||||
<p>
|
<p>
|
||||||
Evaluates the given <a>cmd</a> as JavaScript. Behaves exactly as
|
Evaluates the given <a>cmd</a> as JavaScript. Behaves exactly as
|
||||||
@@ -137,6 +136,32 @@
|
|||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
<item>
|
||||||
|
<tags>REPL</tags>
|
||||||
|
<spec>:javascript<oa>!</oa> <oa>context</oa></spec>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Starts the JavaScript Read Eval Print Loop, where JavaScript
|
||||||
|
statements are entered and evaluated, their results printed, and the
|
||||||
|
input modified and entered again. Within the REPL, the results of a
|
||||||
|
given evaluation are available as variables named for the given
|
||||||
|
prompt.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
If <oa>context</oa> is given, then statements are executed in that
|
||||||
|
global context.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<example><code><hl key="REPL">
|
||||||
|
<hl key="REPL-E"><hl key="REPL-R">js1></hl> ({ <hl key="Key">foo</hl>: <str>bar</str> })</hl
|
||||||
|
><hl key="REPL-P" style="display: block;"><hl key="Title Object">[object Object]</hl>::
|
||||||
|
<hl key="Key">foo</hl>: <hl key="String">"bar"</hl></hl
|
||||||
|
><hl key="REPL-E"><hl key="REPL-R">js2></hl> js1.foo</hl
|
||||||
|
><hl key="REPL-P" style="display: block;"><str>bar</str></hl></hl></code></example>
|
||||||
|
</description>
|
||||||
|
</item>
|
||||||
|
|
||||||
<h2 tag="global-variables">Global Variables</h2>
|
<h2 tag="global-variables">Global Variables</h2>
|
||||||
|
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ defineModule("javascript", {
|
|||||||
use: ["services", "template", "util"]
|
use: ["services", "template", "util"]
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
let isPrototypeOf = Object.prototype.isPrototypeOf;
|
||||||
|
|
||||||
// TODO: Clean this up.
|
// TODO: Clean this up.
|
||||||
|
|
||||||
var JavaScript = Module("javascript", {
|
var JavaScript = Module("javascript", {
|
||||||
@@ -40,6 +42,14 @@ var JavaScript = Module("javascript", {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
globals: Class.memoize(function () [
|
||||||
|
[this.modules.userContext, "Global Variables"],
|
||||||
|
[this.modules, "modules"],
|
||||||
|
[this.window, "window"]
|
||||||
|
]),
|
||||||
|
|
||||||
|
toplevel: Class.memoize(function () this.modules.jsmodules),
|
||||||
|
|
||||||
lazyInit: true,
|
lazyInit: true,
|
||||||
|
|
||||||
newContext: function () this.modules.newContext(this.modules.userContext),
|
newContext: function () this.modules.newContext(this.modules.userContext),
|
||||||
@@ -83,7 +93,7 @@ var JavaScript = Module("javascript", {
|
|||||||
return [];
|
return [];
|
||||||
if (isinstance(obj, ["Sandbox"]) && !toplevel) // Temporary hack.
|
if (isinstance(obj, ["Sandbox"]) && !toplevel) // Temporary hack.
|
||||||
return [];
|
return [];
|
||||||
if (this.modules.jsmodules.isPrototypeOf(obj) && !toplevel)
|
if (isPrototypeOf.call(this.toplevel, obj) && !toplevel)
|
||||||
return [];
|
return [];
|
||||||
|
|
||||||
let completions = [k for (k in this.iter(obj, toplevel))];
|
let completions = [k for (k in this.iter(obj, toplevel))];
|
||||||
@@ -310,11 +320,7 @@ var JavaScript = Module("javascript", {
|
|||||||
let end = (frame == -1 ? this._lastIdx : this._get(frame + 1).offset);
|
let end = (frame == -1 ? this._lastIdx : this._get(frame + 1).offset);
|
||||||
|
|
||||||
this._cacheKey = null;
|
this._cacheKey = null;
|
||||||
let obj = [[this.cache.evalContext, "Local Variables"],
|
let obj = [[this.cache.evalContext, "Local Variables"]].concat(this.globals);
|
||||||
[this.replContext, "REPL Variables"],
|
|
||||||
[this.modules.userContext, "Global Variables"],
|
|
||||||
[this.modules, "modules"],
|
|
||||||
[this.window, "window"]]; // Default objects;
|
|
||||||
// Is this an object dereference?
|
// Is this an object dereference?
|
||||||
if (dot < statement) // No.
|
if (dot < statement) // No.
|
||||||
dot = statement - 1;
|
dot = statement - 1;
|
||||||
@@ -751,15 +757,34 @@ var JavaScript = Module("javascript", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, {
|
modules.CommandREPLMode = Class("CommandREPLMode", modules.CommandMode, {
|
||||||
open: function open() {
|
init: function init(context) {
|
||||||
let self = this;
|
init.supercall(this);
|
||||||
|
|
||||||
this.context = modules.newContext(modules.userContext, true);
|
let self = this;
|
||||||
|
let sandbox = isinstance(context, ["Sandbox"]);
|
||||||
|
|
||||||
|
this.context = modules.newContext(context, !sandbox);
|
||||||
this.js = modules.JavaScript();
|
this.js = modules.JavaScript();
|
||||||
this.js.replContext = this.context;
|
this.js.replContext = this.context;
|
||||||
this.js.newContext = function newContext() modules.newContext(self.context, true);
|
this.js.newContext = function newContext() modules.newContext(self.context, !sandbox);
|
||||||
this.repl = REPL(this.context);
|
|
||||||
|
|
||||||
|
this.js.globals = [
|
||||||
|
[this.context, "REPL Variables"],
|
||||||
|
[context, "REPL Global"]
|
||||||
|
].concat(this.js.globals.filter(function ([global]) isPrototypeOf.call(global, context)));
|
||||||
|
|
||||||
|
if (!isPrototypeOf.call(modules.jsmodules, context))
|
||||||
|
this.js.toplevel = context;
|
||||||
|
|
||||||
|
if (!isPrototypeOf.call(window, context))
|
||||||
|
this.js.window = context;
|
||||||
|
|
||||||
|
if (this.js.globals.slice(2).some(function ([global]) global === context))
|
||||||
|
this.js.globals.splice(1);
|
||||||
|
|
||||||
|
this.repl = REPL(this.context);
|
||||||
|
},
|
||||||
|
open: function open(context) {
|
||||||
this.updatePrompt();
|
this.updatePrompt();
|
||||||
|
|
||||||
modules.mow.echo(this.repl);
|
modules.mow.echo(this.repl);
|
||||||
@@ -803,14 +828,14 @@ var JavaScript = Module("javascript", {
|
|||||||
commands.add(["javas[cript]", "js"],
|
commands.add(["javas[cript]", "js"],
|
||||||
"Evaluate a JavaScript string",
|
"Evaluate a JavaScript string",
|
||||||
function (args) {
|
function (args) {
|
||||||
if (args.bang) // open JavaScript console
|
modules.commandline;
|
||||||
dactyl.open("chrome://global/content/console.xul",
|
|
||||||
{ from: "javascript" });
|
if (args[0] && !args.bang)
|
||||||
else if (args[0])
|
|
||||||
dactyl.userEval(args[0]);
|
dactyl.userEval(args[0]);
|
||||||
else {
|
else {
|
||||||
modules.commandline;
|
modules.commandline;
|
||||||
modules.CommandREPLMode().open();
|
modules.CommandREPLMode(args[0] ? dactyl.userEval(args[0]) : modules.userContext)
|
||||||
|
.open();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
bang: true,
|
bang: true,
|
||||||
|
|||||||
@@ -86,6 +86,7 @@
|
|||||||
and linking to source code locations). [b4]
|
and linking to source code locations). [b4]
|
||||||
- :downloads now opens a download list in the multi-line output
|
- :downloads now opens a download list in the multi-line output
|
||||||
buffer. [b6]
|
buffer. [b6]
|
||||||
|
- :javascript! now opens a Read Eval Print Loop. [b6]
|
||||||
- Added -arg flag to :map. [b6]
|
- Added -arg flag to :map. [b6]
|
||||||
- :extensions has been replaced with a more powerful :addons.
|
- :extensions has been replaced with a more powerful :addons.
|
||||||
- Added -literal flag to :command. [b6]
|
- Added -literal flag to :command. [b6]
|
||||||
|
|||||||
Reference in New Issue
Block a user