diff options
author | Alon Zakai <alonzakai@gmail.com> | 2011-10-16 21:01:22 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2011-10-16 21:01:22 -0700 |
commit | e91161817c388eb4d759cbf9730f11df9a949f45 (patch) | |
tree | c2ea81fc7b337f632dc81c7caf910f3ed6a89dc2 | |
parent | 350fa1956b8f3c371c964947070d5614aa8c9e78 (diff) |
properly use console.log on the web
-rw-r--r-- | src/library.js | 13 | ||||
-rw-r--r-- | src/preamble.js | 6 |
2 files changed, 5 insertions, 14 deletions
diff --git a/src/library.js b/src/library.js index f8112af9..efb6abee 100644 --- a/src/library.js +++ b/src/library.js @@ -330,18 +330,7 @@ LibraryManager.library = { output.buffer.push(String.fromCharCode(val)); } }; - if (!output.printer) { - if (typeof print == 'function') { - // Either console or custom print function defined. - output.printer = print; - } else if (console && typeof console.log == 'function') { - // Browser-like environment with a console. - output.printer = console.log; - } else { - // Fallback to a harmless no-op. - output.printer = function() {}; - } - } + if (!output.printer) output.printer = print; if (!output.buffer) output.buffer = []; if (!error) error = output; diff --git a/src/preamble.js b/src/preamble.js index c8f93b56..1fec1301 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -655,8 +655,10 @@ Module['String_copy'] = String_copy; // Tools -if (typeof print === 'undefined') { - this['print'] = console.log; // we are on the web +if (typeof console === 'object' && typeof console.log === 'function') { + this['print'] = function(x) { console.log(x) }; // web console +} else if (typeof print === 'undefined') { + this['print'] = function(){}; // harmless no-op } // This processes a JS string into a C-line array of numbers, 0-terminated. |