From 51a9fc8deafe7bebe3d6f1cd135be4324a0df9dc Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 7 Feb 2011 23:51:29 -0500 Subject: [PATCH] Add contexts.withContext. --HG-- branch : groups --- common/content/commandline.js | 8 ++++---- common/content/commands.js | 6 ++---- common/content/contexts.js | 8 +++++++- common/content/mow.js | 2 -- common/modules/io.jsm | 3 +-- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/common/content/commandline.js b/common/content/commandline.js index 003d1b3d..f2926ace 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -424,10 +424,10 @@ var CommandExMode = Class("CommandExMode", CommandMode, { }, onSubmit: function onSubmit(command) { - io.withSavedValues(["readHeredoc"], function () { - this.readHeredoc = commandline.readHeredoc; - contexts.withSavedValues(["context"], function () { - this.context = { file: "[Command Line]", line: 1 }; + contexts.withContext({ file: "[Command Line]", line: 1 }, + function () { + io.withSavedValues(["readHeredoc"], function () { + this.readHeredoc = commandline.readHeredoc; commands.repeat = command; dactyl.execute(command); }); diff --git a/common/content/commands.js b/common/content/commands.js index 7d67ecd0..c9118a6a 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -635,10 +635,8 @@ var Commands = Module("commands", { * command string. */ execute: function (string, tokens, silent, args, context) { - contexts.withSavedValues(["context"], function () { - context = update({}, context || this.context || { file: "[Command Line]", line: 1 }); - this.context = context; - + contexts.withContext(context || this.context || { file: "[Command Line]", line: 1 }, + function (context) { io.withSavedValues(["readHeredoc"], function () { this.readHeredoc = function (end) { let res = []; diff --git a/common/content/contexts.js b/common/content/contexts.js index c2a9806a..bed6f126 100644 --- a/common/content/contexts.js +++ b/common/content/contexts.js @@ -270,7 +270,13 @@ var Contexts = Module("contexts", { get default() (contexts.context && contexts.context.group || contexts.user)[name], completer: function (context) completion.group(context) - }) + }), + + withContext: function withContext(defaults, callback, self) + this.withSavedValues(["context"], function () { + this.context = defaults && update({}, defaults); + return callback.call(self, this.context); + }) }, { Context: modules.Script = function Context(file, group, args) { function Const(val) Class.Property({ enumerable: true, value: val }); diff --git a/common/content/mow.js b/common/content/mow.js index 9fdd6cee..e526efda 100644 --- a/common/content/mow.js +++ b/common/content/mow.js @@ -90,8 +90,6 @@ var MOW = Module("mow", { * @param {string} highlightGroup */ echo: function echo(data, highlightGroup, silent) { - this.document; - util.dump(String(this.widget), String(this.window), String(this.document)); let body = this.document.body; this.widgets.message = null; diff --git a/common/modules/io.jsm b/common/modules/io.jsm index 522b2832..b249f22a 100644 --- a/common/modules/io.jsm +++ b/common/modules/io.jsm @@ -150,8 +150,7 @@ var IO = Module("io", { params = params || {}; let time = Date.now(); - return contexts.withSavedValues(["context"], function _source() { - contexts.context = null; + return contexts.withContext(null, function () { try { var file = util.getFile(filename) || io.File(filename);