Skip to content

Commit

Permalink
Unify isArray/isFunction/toString implementations
Browse files Browse the repository at this point in the history
Restores Array.isArray polyfill for all use cases.

Fixes #645
  • Loading branch information
kpdecker committed Nov 6, 2013
1 parent 96a45a4 commit affbcbb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
20 changes: 3 additions & 17 deletions lib/handlebars/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,11 @@ export var REVISION_CHANGES = {
4: '>= 1.0.0'
};

var toString = Object.prototype.toString,
var isArray = Utils.isArray,
isFunction = Utils.isFunction,
toString = Utils.toString,
objectType = '[object Object]';

// Sourced from lodash
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
var isFunction = function(value) {
return typeof value === 'function';
};
// fallback for older versions of Chrome and Safari
if (isFunction(/x/)) {
isFunction = function(value) {
return typeof value === 'function' && toString.call(value) === '[object Function]';
};
}

function isArray(value) {
return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
}

export function HandlebarsEnvironment(helpers, partials) {
this.helpers = helpers || {};
this.partials = partials || {};
Expand Down
22 changes: 20 additions & 2 deletions lib/handlebars/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import SafeString from "./safe-string";

var isArray = Array.isArray;

var escape = {
"&": "&",
"<": "&lt;",
Expand All @@ -26,6 +24,26 @@ export function extend(obj, value) {
}
}

export var toString = Object.prototype.toString;

// Sourced from lodash
// https://github.com/bestiejs/lodash/blob/master/LICENSE.txt
var isFunction = function(value) {
return typeof value === 'function';
};
// fallback for older versions of Chrome and Safari
if (isFunction(/x/)) {
isFunction = function(value) {
return typeof value === 'function' && toString.call(value) === '[object Function]';
};
}
export var isFunction;

export var isArray = Array.isArray || function(value) {
return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false;
};


export function escapeExpression(string) {
// don't escape SafeStrings, since they're already safe
if (string instanceof SafeString) {
Expand Down

0 comments on commit affbcbb

Please sign in to comment.