From 871085f9178e0701911e2146b39d1029d6381e03 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Mon, 4 Oct 2010 17:15:37 -0400 Subject: [PATCH] Deprecate :let and dactyl.globalVariables. --- common/content/buffer.js | 2 +- common/content/commands.js | 5 +++++ common/content/dactyl-overlay.js | 2 +- common/content/dactyl.js | 18 +++++++++++++++++- common/content/help.xsl | 8 ++++++++ common/content/options.js | 15 +++++++++------ common/locale/en-US/eval.xml | 6 ++++++ 7 files changed, 47 insertions(+), 9 deletions(-) diff --git a/common/content/buffer.js b/common/content/buffer.js index 2c0d59a7..0ffe198e 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -974,7 +974,7 @@ const Buffer = Module("buffer", { * Portions copyright Kris Maglione licensable under the * MIT license. */ - viewSourceExternally: Class("viewSourceExternally", + viewSourceExternally: Class("viewSourceExternally", XPCOM([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference]), { init: function (doc) { let url = isString(doc) ? doc : doc.location.href; diff --git a/common/content/commands.js b/common/content/commands.js index 916dca46..88575384 100644 --- a/common/content/commands.js +++ b/common/content/commands.js @@ -131,6 +131,11 @@ const Command = Class("Command", { * @param {Object} modifiers Any modifiers to be passed to {@link #action}. */ execute: function (args, modifiers) { + if (this.deprecated) { + let loc = io.sourcing ? io.sourcing.file + ":" + io.sourcing.line + ": " : ""; + dactyl.echoerr(loc + ":" + this.name + " is deprecated"); + } + let self = this; modifiers = modifiers || {}; diff --git a/common/content/dactyl-overlay.js b/common/content/dactyl-overlay.js index f1b66d4c..fadaef41 100644 --- a/common/content/dactyl-overlay.js +++ b/common/content/dactyl-overlay.js @@ -46,6 +46,7 @@ "modules", "storage", "util", + "dactyl", "modes", "abbreviations", "autocommands", @@ -55,7 +56,6 @@ "completion", "configbase", "config", - "dactyl", "editor", "events", "finder", diff --git a/common/content/dactyl.js b/common/content/dactyl.js index a19dd8a6..0492edec 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -25,6 +25,19 @@ const FailedAssertion = Class("FailedAssertion", Error, { } }); +deprecated.seen = {}; +function deprecated(fn) + function deprecatedMethod() { + let frame = Components.stack.caller; + let caller = frame.filename + ":" + frame.lineNumber; + if (frame.filename != "chrome://dactyl/content/javascript.js" && + !set.add(deprecated.seen, caller)) + dactyl.echoerr(caller + ": " + + (this.className || this.constructor.className) + "." + fn.name + + " is deprecated"); + return fn.apply(this, arguments); + } + const Dactyl = Module("dactyl", { init: function () { window.dactyl = this; @@ -689,7 +702,10 @@ const Dactyl = Module("dactyl", { * * These are set and accessed with the "g:" prefix. */ - globalVariables: {}, + _globalVariables: {}, + globalVariables: Class.Property({ + get: deprecated(function globalVariables() this._globalVariables) + }), loadPlugins: function () { function sourceDirectory(dir) { diff --git a/common/content/help.xsl b/common/content/help.xsl index 1727dd42..e844c9d0 100644 --- a/common/content/help.xsl +++ b/common/content/help.xsl @@ -406,6 +406,14 @@ [] + +

+ + Deprecated: + + +

+

diff --git a/common/content/options.js b/common/content/options.js index 3b7d73b0..abef2bd4 100644 --- a/common/content/options.js +++ b/common/content/options.js @@ -1246,6 +1246,7 @@ const Options = Module("options", { commands.add(["let"], "Set or list a variable", function (args) { + let globalVariables = dactyl._globalVariables; args = (args[0] || "").trim(); function fmt(value) (typeof value == "number" ? "#" : typeof value == "function" ? "*" : @@ -1254,7 +1255,7 @@ const Options = Module("options", { let str = { - template.map(dactyl.globalVariables, function ([i, value]) { + template.map(globalVariables, function ([i, value]) { return @@ -1276,11 +1277,11 @@ const Options = Module("options", { dactyl.assert(scope == "g:" || scope == null, "E461: Illegal variable name: " + scope + name); - dactyl.assert(dactyl.globalVariables.hasOwnProperty(name) || (expr && !op), + dactyl.assert(globalVariables.hasOwnProperty(name) || (expr && !op), "E121: Undefined variable: " + fullName); if (!expr) - dactyl.echo(fullName + "\t\t" + fmt(dactyl.globalVariables[name])); + dactyl.echo(fullName + "\t\t" + fmt(globalVariables[name])); else { try { var newValue = dactyl.userEval(expr); @@ -1291,7 +1292,7 @@ const Options = Module("options", { let value = newValue; if (op) { - value = dactyl.globalVariables[name]; + value = globalVariables[name]; if (op == "+") value += newValue; else if (op == "-") @@ -1299,13 +1300,14 @@ const Options = Module("options", { else if (op == ".") value += String(newValue); } - dactyl.globalVariables[name] = value; + globalVariables[name] = value; } } else dactyl.echoerr("E18: Unexpected characters in :let"); }, { + deprecated: true, literal: 0 } ); @@ -1386,7 +1388,8 @@ const Options = Module("options", { }, { argCount: "+", - bang: true + bang: true, + deprecated: true }); }, completion: function () { diff --git a/common/locale/en-US/eval.xml b/common/locale/en-US/eval.xml index 7bd87320..1decd6db 100644 --- a/common/locale/en-US/eval.xml +++ b/common/locale/en-US/eval.xml @@ -140,6 +140,9 @@ :let var-name:let + All scripts which make use of :let should be + updated to use the simpler and more powerful options system + instead.

Sets or lists a variable. Sets the variable var-name to the value of the expression expr1. If no expression is given, the value of the variable is @@ -153,6 +156,9 @@ :unl :unlet :unlet! name + All scripts which make use of :let should be + updated to use the simpler and more powerful options system + instead.

Deletes the named variables. When ! is given, no error message is output for non-existing variables.

{i} {fmt(value)}