Skip to content

Commit fc72040

Browse files
ccheeveride
authored andcommitted
Also call the original console methods if they exist
Ex. When `console.log` or similar is called, this will call the original method, which can be quite useful. For example, under iOS, this will log to the Safari console debugger, which has an expandable UI for inspecting objects, etc., and is also just useful if you are using that as a REPL. I don't believe this incurs a meaningful performance penalty unless the console is open, but it would be easy to stick behind a flag if that is a problem. A slightly different version of this patch was submitted a while ago and merged but something got screwed up with the merge and this change was not actually pulled in. (See the weird unrelated commits and changes attached to the PR facebook#205)
1 parent 5af1545 commit fc72040

File tree

1 file changed

+20
-0
lines changed
  • packager/react-packager/src/DependencyResolver/haste/polyfills

1 file changed

+20
-0
lines changed

packager/react-packager/src/DependencyResolver/haste/polyfills/console.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
error: 4
2727
};
2828

29+
var originalConsole = global.console;
30+
2931
function setupConsole(global) {
3032

3133
if (!global.nativeLoggingHook) {
@@ -135,6 +137,24 @@
135137
table: consoleTablePolyfill
136138
};
137139

140+
// If available, also call the original `console` method since that is sometimes useful
141+
// Ex. On OS X, this will let you see rich output to the Safari REPL console
142+
if (originalConsole) {
143+
for (var methodName in global.console) {
144+
if (global.console.hasOwnProperty(methodName)) {
145+
if (originalConsole[methodName]) {
146+
(function () {
147+
var nativeMethod = global.console[methodName];
148+
global.console[methodName] = function () {
149+
originalConsole[methodName].apply(originalConsole, arguments);
150+
nativeMethod.apply(global.console, arguments);
151+
};
152+
})();
153+
}
154+
}
155+
}
156+
}
157+
138158
}
139159

140160
if (typeof module !== 'undefined') {

0 commit comments

Comments
 (0)