MCPcopy Create free account
hub / github.com/EricSimons/ionic-course / getterFn

Function getterFn

code/songhop/www/lib/angular/angular.js:12452–12517  ·  view source on GitHub ↗
(path, options, fullExp)

Source from the content-addressed store, hash-verified

12450}
12451
12452function getterFn(path, options, fullExp) {
12453 var expensiveChecks = options.expensiveChecks;
12454 var getterFnCache = (expensiveChecks ? getterFnCacheExpensive : getterFnCacheDefault);
12455 var fn = getterFnCache[path];
12456 if (fn) return fn;
12457
12458
12459 var pathKeys = path.split('.'),
12460 pathKeysLength = pathKeys.length;
12461
12462 // http://jsperf.com/angularjs-parse-getter/6
12463 if (options.csp) {
12464 if (pathKeysLength < 6) {
12465 fn = cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4], fullExp, expensiveChecks);
12466 } else {
12467 fn = function cspSafeGetter(scope, locals) {
12468 var i = 0, val;
12469 do {
12470 val = cspSafeGetterFn(pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++],
12471 pathKeys[i++], fullExp, expensiveChecks)(scope, locals);
12472
12473 locals = undefined; // clear after first iteration
12474 scope = val;
12475 } while (i < pathKeysLength);
12476 return val;
12477 };
12478 }
12479 } else {
12480 var code = '';
12481 if (expensiveChecks) {
12482 code += 's = eso(s, fe);\nl = eso(l, fe);\n';
12483 }
12484 var needsEnsureSafeObject = expensiveChecks;
12485 forEach(pathKeys, function(key, index) {
12486 ensureSafeMemberName(key, fullExp);
12487 var lookupJs = (index
12488 // we simply dereference 's' on any .dot notation
12489 ? 's'
12490 // but if we are first then we check locals first, and if so read it first
12491 : '((l&&l.hasOwnProperty("' + key + '"))?l:s)') + '.' + key;
12492 if (expensiveChecks || isPossiblyDangerousMemberName(key)) {
12493 lookupJs = 'eso(' + lookupJs + ', fe)';
12494 needsEnsureSafeObject = true;
12495 }
12496 code += 'if(s == null) return undefined;\n' +
12497 's=' + lookupJs + ';\n';
12498 });
12499 code += 'return s;';
12500
12501 /* jshint -W054 */
12502 var evaledFnGetter = new Function('s', 'l', 'eso', 'fe', code); // s=scope, l=locals, eso=ensureSafeObject
12503 /* jshint +W054 */
12504 evaledFnGetter.toString = valueFn(code);
12505 if (needsEnsureSafeObject) {
12506 evaledFnGetter = getterFnWithEnsureSafeObject(evaledFnGetter, fullExp);
12507 }
12508 fn = evaledFnGetter;
12509 }

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