From c74f1e9bc92a3b4227a4cadc98e99793fdfb8f03 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 28 Sep 2015 14:58:08 -0700 Subject: [PATCH] Don't call originalConsole methods when they don't exist Reviewed By: @vjeux Differential Revision: D2485562 --- .../DependencyResolver/polyfills/console.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/react-packager/src/DependencyResolver/polyfills/console.js b/react-packager/src/DependencyResolver/polyfills/console.js index e841aebb..b6f20c76 100644 --- a/react-packager/src/DependencyResolver/polyfills/console.js +++ b/react-packager/src/DependencyResolver/polyfills/console.js @@ -468,13 +468,17 @@ // 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 // the Safari Web Inspector console. - Object.keys(global.console).forEach(methodName => { - var reactNativeMethod = global.console[methodName]; - global.console[methodName] = function() { - originalConsole[methodName](...arguments); - reactNativeMethod.apply(global.console, arguments); - }; - }); + if (__DEV__ && originalConsole) { + Object.keys(global.console).forEach(methodName => { + var reactNativeMethod = global.console[methodName]; + if (originalConsole[methodName]) { + global.console[methodName] = function() { + originalConsole[methodName](...arguments); + reactNativeMethod.apply(global.console, arguments); + }; + } + }); + } } if (typeof module !== 'undefined') {