Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 689dfb1

Browse files
kseamonIgorMinar
authored andcommitted
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
1 parent 1169b54 commit 689dfb1

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/ng/parse.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,24 @@ function ensureSafeMemberName(name, fullExpression) {
4444

4545
function ensureSafeObject(obj, fullExpression) {
4646
// nifty check if obj is Function that is fast and works across iframes and other contexts
47-
if (obj && obj.constructor === obj) {
48-
throw $parseMinErr('isecfn',
49-
'Referencing Function in Angular expressions is disallowed! Expression: {0}',
50-
fullExpression);
51-
} else if (// isWindow(obj)
52-
obj && obj.document && obj.location && obj.alert && obj.setInterval) {
53-
throw $parseMinErr('isecwindow',
54-
'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
55-
fullExpression);
56-
} else if (// isElement(obj)
57-
obj && (obj.nodeName || (obj.on && obj.find))) {
58-
throw $parseMinErr('isecdom',
59-
'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
60-
fullExpression);
61-
} else {
62-
return obj;
47+
if (obj) {
48+
if (obj.constructor === obj) {
49+
throw $parseMinErr('isecfn',
50+
'Referencing Function in Angular expressions is disallowed! Expression: {0}',
51+
fullExpression);
52+
} else if (// isWindow(obj)
53+
obj.document && obj.location && obj.alert && obj.setInterval) {
54+
throw $parseMinErr('isecwindow',
55+
'Referencing the Window in Angular expressions is disallowed! Expression: {0}',
56+
fullExpression);
57+
} else if (// isElement(obj)
58+
obj.children && (obj.nodeName || (obj.on && obj.find))) {
59+
throw $parseMinErr('isecdom',
60+
'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
61+
fullExpression);
62+
}
6363
}
64+
return obj;
6465
}
6566

6667
var OPERATORS = {

0 commit comments

Comments
 (0)