Skip to content

Commit

Permalink
FnExpressions: actually check that it is a function we are about to call
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-brade committed Aug 23, 2016
1 parent af635c0 commit 92a217f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/expressions.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,20 +409,20 @@ FnExpression.prototype._lookupParent = function(context) {
// Lookup function in the model
var segments = this.parentSegments;
var parent = (segments) ? lookup(segments, context.controller.model.data) : undefined;
if (parent && parent[this.lastSegment]) return parent;
// Lookup function on current controller
if (parent && typeof parent[this.lastSegment] == 'function') return parent;
// Otherwise lookup function on current controller
var controller = context.controller;
parent = (segments) ? lookup(segments, controller) : controller;
if (parent && parent[this.lastSegment]) return parent;
if (parent && typeof parent[this.lastSegment] == 'function') return parent;
// Otherwise lookup function on page
var page = controller.page;
if (controller !== page) {
parent = (segments) ? lookup(segments, page) : page;
if (parent && parent[this.lastSegment]) return parent;
if (parent && typeof parent[this.lastSegment] == 'function') return parent;
}
// Otherwise lookup function on global
parent = (segments) ? lookup(segments, global) : global;
if (parent && parent[this.lastSegment]) return parent;
if (parent && typeof parent[this.lastSegment] == 'function') return parent;
// Throw if not found
throw new Error('Function not found for: ' + this.segments.join('.'));
};
Expand Down

0 comments on commit 92a217f

Please sign in to comment.