* 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)
| 12403 | * - http://jsperf.com/path-evaluation-simplified/7 |
| 12404 | */ |
| 12405 | function cspSafeGetterFn(key0, key1, key2, key3, key4, fullExp, expensiveChecks) { |
| 12406 | ensureSafeMemberName(key0, fullExp); |
| 12407 | ensureSafeMemberName(key1, fullExp); |
| 12408 | ensureSafeMemberName(key2, fullExp); |
| 12409 | ensureSafeMemberName(key3, fullExp); |
| 12410 | ensureSafeMemberName(key4, fullExp); |
| 12411 | var eso = function(o) { |
| 12412 | return ensureSafeObject(o, fullExp); |
| 12413 | }; |
| 12414 | var eso0 = (expensiveChecks || isPossiblyDangerousMemberName(key0)) ? eso : identity; |
| 12415 | var eso1 = (expensiveChecks || isPossiblyDangerousMemberName(key1)) ? eso : identity; |
| 12416 | var eso2 = (expensiveChecks || isPossiblyDangerousMemberName(key2)) ? eso : identity; |
| 12417 | var eso3 = (expensiveChecks || isPossiblyDangerousMemberName(key3)) ? eso : identity; |
| 12418 | var eso4 = (expensiveChecks || isPossiblyDangerousMemberName(key4)) ? eso : identity; |
| 12419 | |
| 12420 | return function cspSafeGetter(scope, locals) { |
| 12421 | var pathVal = (locals && locals.hasOwnProperty(key0)) ? locals : scope; |
| 12422 | |
| 12423 | if (pathVal == null) return pathVal; |
| 12424 | pathVal = eso0(pathVal[key0]); |
| 12425 | |
| 12426 | if (!key1) return pathVal; |
| 12427 | if (pathVal == null) return undefined; |
| 12428 | pathVal = eso1(pathVal[key1]); |
| 12429 | |
| 12430 | if (!key2) return pathVal; |
| 12431 | if (pathVal == null) return undefined; |
| 12432 | pathVal = eso2(pathVal[key2]); |
| 12433 | |
| 12434 | if (!key3) return pathVal; |
| 12435 | if (pathVal == null) return undefined; |
| 12436 | pathVal = eso3(pathVal[key3]); |
| 12437 | |
| 12438 | if (!key4) return pathVal; |
| 12439 | if (pathVal == null) return undefined; |
| 12440 | pathVal = eso4(pathVal[key4]); |
| 12441 | |
| 12442 | return pathVal; |
| 12443 | }; |
| 12444 | } |
| 12445 | |
| 12446 | function getterFnWithEnsureSafeObject(fn, fullExpression) { |
| 12447 | return function(s, l) { |
no test coverage detected