mirror of https://github.com/nodejs/node.git
core: make .deprecate() warn only once
parent
5403a8ce4c
commit
52bd0f93bb
13
src/node.js
13
src/node.js
|
@ -569,21 +569,30 @@
|
||||||
NativeModule._cache[this.id] = this;
|
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) {
|
NativeModule.prototype.deprecate = function(method, message) {
|
||||||
var original = this.exports[method];
|
var original = this.exports[method];
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var warned = false;
|
||||||
|
message = message || '';
|
||||||
|
|
||||||
Object.defineProperty(this.exports, method, {
|
Object.defineProperty(this.exports, method, {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
value: function() {
|
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))
|
var moduleIdCheck = new RegExp('\\b' + self.id + '\\b');
|
||||||
|
if (moduleIdCheck.test(process.env.NODE_DEBUG))
|
||||||
console.trace(message);
|
console.trace(message);
|
||||||
else
|
else
|
||||||
console.error(message);
|
console.error(message);
|
||||||
|
|
||||||
self.exports[method] = original;
|
self.exports[method] = original;
|
||||||
|
}
|
||||||
return original.apply(this, arguments);
|
return original.apply(this, arguments);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue