summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-02-07 13:22:31 -0600
committerkpdecker <kpdecker@gmail.com>2015-02-07 13:23:10 -0600
commitcfbef2585df36a92d2bcac0a025c39aea37fedb1 (patch)
treeeaaf21f00ce9811ab9c6349e06a85c3cba01467d
parent95421271e3badfcb340cda53434109feed44889a (diff)
downloadhandlebars.js-cfbef2585df36a92d2bcac0a025c39aea37fedb1.zip
handlebars.js-cfbef2585df36a92d2bcac0a025c39aea37fedb1.tar.gz
handlebars.js-cfbef2585df36a92d2bcac0a025c39aea37fedb1.tar.bz2
Fail over to console.log if lacking console method
This improves logger resiliency under older browsers.
-rw-r--r--lib/handlebars/base.js6
-rw-r--r--spec/builtins.js6
2 files changed, 7 insertions, 5 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index f8ac50a..20c49ae 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -225,11 +225,9 @@ export var logger = {
// Can be overridden in the host environment
log: function(level, message) {
- if (logger.level <= level) {
+ if (typeof console !== 'undefined' && logger.level <= level) {
var method = logger.methodMap[level];
- if (typeof console !== 'undefined' && console[method]) {
- console[method].call(console, message);
- }
+ (console[method] || console.log).call(console, message);
}
}
};
diff --git a/spec/builtins.js b/spec/builtins.js
index 8f20da1..75af236 100644
--- a/spec/builtins.js
+++ b/spec/builtins.js
@@ -276,7 +276,7 @@ describe('builtin helpers', function() {
equals(3, levelArg);
equals("whee", logArg);
});
- it('should not output to info', function() {
+ it('should output to info', function() {
var string = "{{log blah}}";
var hash = { blah: "whee" };
@@ -284,6 +284,10 @@ describe('builtin helpers', function() {
equals("whee", log);
called = true;
};
+ console.log = function(log) {
+ equals("whee", log);
+ called = true;
+ };
shouldCompileTo(string, hash, "");
equals(true, called);