* 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, options)
| 11078 | * - http://jsperf.com/path-evaluation-simplified/7 |
| 11079 | */ |
| 11080 | function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, options) { |
| 11081 | ensureSafeMemberName(key0, fullExp); |
| 11082 | ensureSafeMemberName(key1, fullExp); |
| 11083 | ensureSafeMemberName(key2, fullExp); |
| 11084 | ensureSafeMemberName(key3, fullExp); |
| 11085 | ensureSafeMemberName(key4, fullExp); |
| 11086 | var eso = function(o) { |
| 11087 | return ensureSafeObject(o, fullExp); |
| 11088 | }; |
| 11089 | var expensiveChecks = options.expensiveChecks; |
| 11090 | var eso0 = (expensiveChecks || isPossiblyDangerousMemberName(key0)) ? eso : identity; |
| 11091 | var eso1 = (expensiveChecks || isPossiblyDangerousMemberName(key1)) ? eso : identity; |
| 11092 | var eso2 = (expensiveChecks || isPossiblyDangerousMemberName(key2)) ? eso : identity; |
| 11093 | var eso3 = (expensiveChecks || isPossiblyDangerousMemberName(key3)) ? eso : identity; |
| 11094 | var eso4 = (expensiveChecks || isPossiblyDangerousMemberName(key4)) ? eso : identity; |
| 11095 | |
| 11096 | return !options.unwrapPromises |
| 11097 | ? function cspSafeGetter(scope, locals) { |
| 11098 | var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope; |
| 11099 | |
| 11100 | if (pathVal == null) return pathVal; |
| 11101 | pathVal = eso0(pathVal[key0]); |
| 11102 | |
| 11103 | if (!key1) return pathVal; |
| 11104 | if (pathVal == null) return undefined; |
| 11105 | pathVal = eso1(pathVal[key1]); |
| 11106 | |
| 11107 | if (!key2) return pathVal; |
| 11108 | if (pathVal == null) return undefined; |
| 11109 | pathVal = eso2(pathVal[key2]); |
| 11110 | |
| 11111 | if (!key3) return pathVal; |
| 11112 | if (pathVal == null) return undefined; |
| 11113 | pathVal = eso3(pathVal[key3]); |
| 11114 | |
| 11115 | if (!key4) return pathVal; |
| 11116 | if (pathVal == null) return undefined; |
| 11117 | pathVal = eso4(pathVal[key4]); |
| 11118 | |
| 11119 | return pathVal; |
| 11120 | } |
| 11121 | : function cspSafePromiseEnabledGetter(scope, locals) { |
| 11122 | var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope, |
| 11123 | promise; |
| 11124 | |
| 11125 | if (pathVal == null) return pathVal; |
| 11126 | |
| 11127 | pathVal = eso0(pathVal[key0]); |
| 11128 | if (pathVal && pathVal.then) { |
| 11129 | promiseWarning(fullExp); |
| 11130 | if (!("$$v" in pathVal)) { |
| 11131 | promise = pathVal; |
| 11132 | promise.$$v = undefined; |
| 11133 | promise.then(function(val) { promise.$$v = eso0(val); }); |
| 11134 | } |
| 11135 | pathVal = eso0(pathVal.$$v); |
| 11136 | } |
| 11137 |
no test coverage detected