Don't call originalConsole methods when they don't exist

Reviewed By: @vjeux

Differential Revision: D2485562
This commit is contained in:
Pieter De Baets 2015-09-28 14:58:08 -07:00 committed by facebook-github-bot-4
parent d4f9750e38
commit c74f1e9bc9
1 changed files with 11 additions and 7 deletions

View File

@ -468,14 +468,18 @@
// If available, also call the original `console` method since that is // If available, also call the original `console` method since that is
// sometimes useful. Ex: on OS X, this will let you see rich output in // sometimes useful. Ex: on OS X, this will let you see rich output in
// the Safari Web Inspector console. // the Safari Web Inspector console.
if (__DEV__ && originalConsole) {
Object.keys(global.console).forEach(methodName => { Object.keys(global.console).forEach(methodName => {
var reactNativeMethod = global.console[methodName]; var reactNativeMethod = global.console[methodName];
if (originalConsole[methodName]) {
global.console[methodName] = function() { global.console[methodName] = function() {
originalConsole[methodName](...arguments); originalConsole[methodName](...arguments);
reactNativeMethod.apply(global.console, arguments); reactNativeMethod.apply(global.console, arguments);
}; };
}
}); });
} }
}
if (typeof module !== 'undefined') { if (typeof module !== 'undefined') {
module.exports = setupConsole; module.exports = setupConsole;