Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Only warn once when the deprecation warning wrapper is called multipl…

…e times.
  • Loading branch information...
commit 93540a357e0cbf2d0f36eecb26ae1924812e5acb 1 parent 5403a8c
@Benvie authored
Showing with 15 additions and 6 deletions.
  1. +15 −6 src/node.js
View
21 src/node.js
@@ -569,21 +569,30 @@
NativeModule._cache[this.id] = this;
};
+ // Wrap a core module's method in a wrapper that will warn on first use
+ // and then return the result of invoking the original function. After
+ // first being called the original method is restored.
NativeModule.prototype.deprecate = function(method, message) {
var original = this.exports[method];
var self = this;
+ var warned = false;
+ message = message || '';
Object.defineProperty(this.exports, method, {
enumerable: false,
value: function() {
- message = self.id + '.' + method + ' is deprecated. ' + (message || '');
+ if (!warned) {
+ warned = true;
+ message = self.id + '.' + method + ' is deprecated. ' + message;
- if ((new RegExp('\\b' + self.id + '\\b')).test(process.env.NODE_DEBUG))
- console.trace(message);
- else
- console.error(message);
+ var moduleIdCheck = new RegExp('\\b' + self.id + '\\b');
+ if (moduleIdCheck.test(process.env.NODE_DEBUG))
+ console.trace(message);
+ else
+ console.error(message);
- self.exports[method] = original;
+ self.exports[method] = original;
+ }
return original.apply(this, arguments);
}
});
Please sign in to comment.
Something went wrong with that request. Please try again.