MCPcopy Create free account
hub / github.com/angular-ui/ui-router / getterFn

Function getterFn

test/angular/1.3/angular.js:12633–12698  ·  view source on GitHub ↗
(path, options, fullExp)

Source from the content-addressed store, hash-verified

12631}
12632
12633function getterFn(path, options, fullExp) {
12634 var expensiveChecks = options.expensiveChecks;
12635 var getterFnCache = (expensiveChecks ? getterFnCacheExpensive : getterFnCacheDefault);
12636 var fn = getterFnCache[path];
12637 if (fn) return fn;
12638
12639
12640 var pathKeys = path.split('.'),
12641 pathKeysLength = pathKeys.length;
12642
12643 // http://jsperf.com/angularjs-parse-getter/6
12644 if (options.csp) {
12645 if (pathKeysLength < 6) {
12646 fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp, expensiveChecks);
12647 } else {
12648 fn = function cspSafeGetter(scope, locals) {
12649 var i = 0, val;
12650 do {
12651 val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++],
12652 pathKeys[i++], fullExp, expensiveChecks)(scope, locals);
12653
12654 locals = undefined; // clear after first iteration
12655 scope = val;
12656 } while (i < pathKeysLength);
12657 return val;
12658 };
12659 }
12660 } else {
12661 var code = '';
12662 if (expensiveChecks) {
12663 code += 's = eso(s, fe);\nl = eso(l, fe);\n';
12664 }
12665 var needsEnsureSafeObject = expensiveChecks;
12666 forEach(pathKeys, function(key, index) {
12667 ensureSafeMemberName(key, fullExp);
12668 var lookupJs = (index
12669 // we simply dereference 's' on any .dot notation
12670 ? 's'
12671 // but if we are first then we check locals first, and if so read it first
12672 : '((l&&l.hasOwnProperty("' + key + '"))?l:s)') + '.' + key;
12673 if (expensiveChecks || isPossiblyDangerousMemberName(key)) {
12674 lookupJs = 'eso(' + lookupJs + ', fe)';
12675 needsEnsureSafeObject = true;
12676 }
12677 code += 'if(s == null) return undefined;\n' +
12678 's=' + lookupJs + ';\n';
12679 });
12680 code += 'return s;';
12681
12682 /* jshint -W054 */
12683 var evaledFnGetter = new Function('s', 'l', 'eso', 'fe', code); // s=scope, l=locals, eso=ensureSafeObject
12684 /* jshint +W054 */
12685 evaledFnGetter.toString = valueFn(code);
12686 if (needsEnsureSafeObject) {
12687 evaledFnGetter = getterFnWithEnsureSafeObject(evaledFnGetter, fullExp);
12688 }
12689 fn = evaledFnGetter;
12690 }

Callers 1

angular.jsFile · 0.70

Calls 7

cspSafeGetterFnFunction · 0.70
forEachFunction · 0.70
ensureSafeMemberNameFunction · 0.70
valueFnFunction · 0.70
setterFunction · 0.70

Tested by

no test coverage detected