From d02c90c0fbc984523a7a8950e15435938979acbe Mon Sep 17 00:00:00 2001 From: Parker Selbert Date: Thu, 23 May 2013 16:18:53 -0500 Subject: [PATCH] Use the ('' + string) form of string coercion Using string.toString() will throw errors in current versions of Safari (6.0.5 currently) for some values. The error is a particularly cryptic "Type Error: type error", which no indication as to the value that caused the error. By using the '' + string form of coercion the error doesn't seem to occur. Depending on the browser used there is a sizable performance increase in using the concatenation form of coercion. In instances where there is not a performance improvement (i.e. Firefox), the speed difference is entirely negligable. See: http://jsperf.com/convert-to-string-bj/3 --- lib/handlebars/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/handlebars/utils.js b/lib/handlebars/utils.js index 1e0e4c90..e104dcf7 100644 --- a/lib/handlebars/utils.js +++ b/lib/handlebars/utils.js @@ -21,7 +21,7 @@ Handlebars.SafeString = function(string) { this.string = string; }; Handlebars.SafeString.prototype.toString = function() { - return this.string.toString(); + return "" + this.string; }; var escape = { @@ -60,7 +60,7 @@ Handlebars.Utils = { // Force a string conversion as this will be done by the append regardless and // the regex test will do this transparently behind the scenes, causing issues if // an object's to string has escaped characters in it. - string = string.toString(); + string = "" + string; if(!possible.test(string)) { return string; } return string.replace(badChars, escapeChar);