Add API for custom handling of deprecations
This commit is contained in:
parent
175449f096
commit
ccef805e9b
5 changed files with 58 additions and 1 deletions
|
@ -88,9 +88,13 @@ deprecate.warn = function(oldName, newName) {
|
||||||
return deprecate.log(oldName + " is deprecated. Use " + newName + " instead.");
|
return deprecate.log(oldName + " is deprecated. Use " + newName + " instead.");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var deprecationHandler = null;
|
||||||
|
|
||||||
// Print deprecation message.
|
// Print deprecation message.
|
||||||
deprecate.log = function(message) {
|
deprecate.log = function(message) {
|
||||||
if (process.throwDeprecation) {
|
if (typeof deprecationHandler === 'function') {
|
||||||
|
deprecationHandler(message);
|
||||||
|
} else if (process.throwDeprecation) {
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
} else if (process.traceDeprecation) {
|
} else if (process.traceDeprecation) {
|
||||||
return console.trace(message);
|
return console.trace(message);
|
||||||
|
@ -99,4 +103,12 @@ deprecate.log = function(message) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
deprecate.setHandler = function(handler) {
|
||||||
|
deprecationHandler = handler;
|
||||||
|
};
|
||||||
|
|
||||||
|
deprecate.getHandler = function() {
|
||||||
|
return deprecationHandler;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = deprecate;
|
module.exports = deprecate;
|
||||||
|
|
11
atom/common/api/lib/deprecations.js
Normal file
11
atom/common/api/lib/deprecations.js
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const deprecate = require('electron').deprecate;
|
||||||
|
|
||||||
|
exports.setHandler = function (deprecationHandler) {
|
||||||
|
deprecate.setHandler(deprecationHandler);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.getHandler = function () {
|
||||||
|
return deprecate.getHandler();
|
||||||
|
}
|
|
@ -31,6 +31,12 @@ exports.defineProperties = function(exports) {
|
||||||
return require('../crash-reporter');
|
return require('../crash-reporter');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
deprecations: {
|
||||||
|
enumerable: true,
|
||||||
|
get: function() {
|
||||||
|
return require('../deprecations');
|
||||||
|
}
|
||||||
|
},
|
||||||
nativeImage: {
|
nativeImage: {
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
get: function() {
|
get: function() {
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
'atom/common/api/lib/clipboard.js',
|
'atom/common/api/lib/clipboard.js',
|
||||||
'atom/common/api/lib/crash-reporter.js',
|
'atom/common/api/lib/crash-reporter.js',
|
||||||
'atom/common/api/lib/deprecate.js',
|
'atom/common/api/lib/deprecate.js',
|
||||||
|
'atom/common/api/lib/deprecations.js',
|
||||||
'atom/common/api/lib/exports/electron.js',
|
'atom/common/api/lib/exports/electron.js',
|
||||||
'atom/common/api/lib/native-image.js',
|
'atom/common/api/lib/native-image.js',
|
||||||
'atom/common/api/lib/shell.js',
|
'atom/common/api/lib/shell.js',
|
||||||
|
|
27
spec/api-deprecations-spec.js
Normal file
27
spec/api-deprecations-spec.js
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
const assert = require('assert');
|
||||||
|
const deprecations = require('electron').deprecations;
|
||||||
|
|
||||||
|
describe('deprecations', function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
deprecations.setHandler(null);
|
||||||
|
process.throwDeprecation = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('allows a deprecation handler function to be specified', function() {
|
||||||
|
var messages = [];
|
||||||
|
|
||||||
|
deprecations.setHandler(function (message) {
|
||||||
|
messages.push(message)
|
||||||
|
});
|
||||||
|
|
||||||
|
require('electron').webFrame.registerUrlSchemeAsSecure('some-scheme')
|
||||||
|
|
||||||
|
assert.deepEqual(messages, ['registerUrlSchemeAsSecure is deprecated. Use registerURLSchemeAsSecure instead.']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws an exception if no deprecation handler is specified', function() {
|
||||||
|
assert.throws(function() {
|
||||||
|
require('electron').webFrame.registerUrlSchemeAsPrivileged('some-scheme')
|
||||||
|
}, "registerUrlSchemeAsPrivileged is deprecated. Use registerURLSchemeAsPrivileged instead.");
|
||||||
|
});
|
||||||
|
})
|
Loading…
Add table
Reference in a new issue