* Implementation of the "Black Hole" variant from: * - http://jsperf.com/angularjs-parse-getter/4 * - http://jsperf.com/path-evaluation-simplified/7
(key0, key1, key2, key3, key4, fullExp, expensiveChecks)
| 12584 | * - http://jsperf.com/path-evaluation-simplified/7 |
| 12585 | */ |
| 12586 | function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, expensiveChecks) { |
| 12587 | ensureSafeMemberName(key0, fullExp); |
| 12588 | ensureSafeMemberName(key1, fullExp); |
| 12589 | ensureSafeMemberName(key2, fullExp); |
| 12590 | ensureSafeMemberName(key3, fullExp); |
| 12591 | ensureSafeMemberName(key4, fullExp); |
| 12592 | var eso = function(o) { |
| 12593 | return ensureSafeObject(o, fullExp); |
| 12594 | }; |
| 12595 | var eso0 = (expensiveChecks || isPossiblyDangerousMemberName(key0)) ? eso : identity; |
| 12596 | var eso1 = (expensiveChecks || isPossiblyDangerousMemberName(key1)) ? eso : identity; |
| 12597 | var eso2 = (expensiveChecks || isPossiblyDangerousMemberName(key2)) ? eso : identity; |
| 12598 | var eso3 = (expensiveChecks || isPossiblyDangerousMemberName(key3)) ? eso : identity; |
| 12599 | var eso4 = (expensiveChecks || isPossiblyDangerousMemberName(key4)) ? eso : identity; |
| 12600 | |
| 12601 | return function cspSafeGetter(scope, locals) { |
| 12602 | var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope; |
| 12603 | |
| 12604 | if (pathVal == null) return pathVal; |
| 12605 | pathVal = eso0(pathVal[key0]); |
| 12606 | |
| 12607 | if (!key1) return pathVal; |
| 12608 | if (pathVal == null) return undefined; |
| 12609 | pathVal = eso1(pathVal[key1]); |
| 12610 | |
| 12611 | if (!key2) return pathVal; |
| 12612 | if (pathVal == null) return undefined; |
| 12613 | pathVal = eso2(pathVal[key2]); |
| 12614 | |
| 12615 | if (!key3) return pathVal; |
| 12616 | if (pathVal == null) return undefined; |
| 12617 | pathVal = eso3(pathVal[key3]); |
| 12618 | |
| 12619 | if (!key4) return pathVal; |
| 12620 | if (pathVal == null) return undefined; |
| 12621 | pathVal = eso4(pathVal[key4]); |
| 12622 | |
| 12623 | return pathVal; |
| 12624 | }; |
| 12625 | } |
| 12626 | |
| 12627 | function getterFnWithEnsureSafeObject(fn, fullExpression) { |
| 12628 | return function(s, l) { |
no test coverage detected