diff options
author | isaacs <i@izs.me> | 2012-06-21 11:42:33 -0700 |
---|---|---|
committer | isaacs <i@izs.me> | 2012-06-21 12:05:33 -0700 |
commit | 5b39929d47f962fccafb4116f3c177ddc4fd3269 (patch) | |
tree | 7380f2e1b3a03b7a5b5483236465b1c05c486d86 /lib/util.js | |
parent | 260695afd07067254a704c050243d2e619bae8b7 (diff) | |
download | node-new-5b39929d47f962fccafb4116f3c177ddc4fd3269.tar.gz |
Add --no-deprecation and --trace-deprecation flags
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/lib/util.js b/lib/util.js index 50595fd3f7..580aa81192 100644 --- a/lib/util.js +++ b/lib/util.js @@ -54,6 +54,31 @@ exports.format = function(f) { }; +// Mark that a method should not be used. +// Returns a modified function which warns once by default. +// If --no-deprecation is set, then it is a no-op. +exports.deprecate = function(fn, msg) { + if (process.noDeprecation === true) { + return fn; + } + + var warned = false; + function deprecated() { + if (!warned) { + if (process.traceDeprecation) { + console.trace(msg); + } else { + console.error(msg); + } + warned = true; + } + return fn.apply(this, arguments); + } + + return deprecated; +}; + + exports.print = function() { for (var i = 0, len = arguments.length; i < len; ++i) { process.stdout.write(String(arguments[i])); @@ -407,12 +432,11 @@ function objectToString(o) { } -exports.p = function() { +exports.p = exports.deprecate(function() { for (var i = 0, len = arguments.length; i < len; ++i) { error(exports.inspect(arguments[i])); } -}; -module.deprecate('p', 'Use `util.puts(util.inspect())` instead.'); +}, 'util.p: Use console.error() instead.'); function pad(n) { @@ -438,10 +462,9 @@ exports.log = function(msg) { }; -exports.exec = function() { +exports.exec = exports.deprecate(function() { return require('child_process').exec.apply(this, arguments); -}; -module.deprecate('exec', 'It is now called `child_process.exec`.'); +}, 'util.exec is now called `child_process.exec`.'); exports.pump = function(readStream, writeStream, callback) { |