From 689dfb167924a61aef444ce7587fb987d8080990 Mon Sep 17 00:00:00 2001 From: Karl Seamon Date: Mon, 2 Dec 2013 18:20:50 -0500 Subject: [PATCH] chore($parse): micro-optimization for ensureSafeObject function This version matches the "alternate 2.2" version here: http://jsperf.com/ensuresafeobject/2 alternate 2.3 is a bit faster and simpler, but would break backwards compatibility. Closes #5246 --- src/ng/parse.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/ng/parse.js b/src/ng/parse.js index 3be985739243..8b3f145a8211 100644 --- a/src/ng/parse.js +++ b/src/ng/parse.js @@ -44,23 +44,24 @@ function ensureSafeMemberName(name, fullExpression) { function ensureSafeObject(obj, fullExpression) { // nifty check if obj is Function that is fast and works across iframes and other contexts - if (obj && obj.constructor === obj) { - throw $parseMinErr('isecfn', - 'Referencing Function in Angular expressions is disallowed! Expression: {0}', - fullExpression); - } else if (// isWindow(obj) - obj && obj.document && obj.location && obj.alert && obj.setInterval) { - throw $parseMinErr('isecwindow', - 'Referencing the Window in Angular expressions is disallowed! Expression: {0}', - fullExpression); - } else if (// isElement(obj) - obj && (obj.nodeName || (obj.on && obj.find))) { - throw $parseMinErr('isecdom', - 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}', - fullExpression); - } else { - return obj; + if (obj) { + if (obj.constructor === obj) { + throw $parseMinErr('isecfn', + 'Referencing Function in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } else if (// isWindow(obj) + obj.document && obj.location && obj.alert && obj.setInterval) { + throw $parseMinErr('isecwindow', + 'Referencing the Window in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } else if (// isElement(obj) + obj.children && (obj.nodeName || (obj.on && obj.find))) { + throw $parseMinErr('isecdom', + 'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}', + fullExpression); + } } + return obj; } var OPERATORS = {