MCPcopy Create free account
hub / github.com/apache/cloudstack / getterFn

Function getterFn

tools/ngui/static/js/lib/angular.js:6528–6577  ·  view source on GitHub ↗
(path, csp)

Source from the content-addressed store, hash-verified

6526}
6527
6528function getterFn(path, csp) {
6529 if (getterFnCache.hasOwnProperty(path)) {
6530 return getterFnCache[path];
6531 }
6532
6533 var pathKeys = path.split('.'),
6534 pathKeysLength = pathKeys.length,
6535 fn;
6536
6537 if (csp) {
6538 fn = (pathKeysLength < 6)
6539 ? cspSafeGetterFn(pathKeys[0], pathKeys[1], pathKeys[2], pathKeys[3], pathKeys[4])
6540 : function(scope, locals) {
6541 var i = 0, val;
6542 do {
6543 val = cspSafeGetterFn(
6544 pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++], pathKeys[i++]
6545 )(scope, locals);
6546
6547 locals = undefined; // clear after first iteration
6548 scope = val;
6549 } while (i < pathKeysLength);
6550 return val;
6551 }
6552 } else {
6553 var code = 'var l, fn, p;\n';
6554 forEach(pathKeys, function(key, index) {
6555 code += 'if(s === null || s === undefined) return s;\n' +
6556 'l=s;\n' +
6557 's='+ (index
6558 // we simply dereference 's' on any .dot notation
6559 ? 's'
6560 // but if we are first then we check locals first, and if so read it first
6561 : '((k&&k.hasOwnProperty("' + key + '"))?k:s)') + '["' + key + '"]' + ';\n' +
6562 'if (s && s.then) {\n' +
6563 ' if (!("$$v" in s)) {\n' +
6564 ' p=s;\n' +
6565 ' p.$$v = undefined;\n' +
6566 ' p.then(function(v) {p.$$v=v;});\n' +
6567 '}\n' +
6568 ' s=s.$$v\n' +
6569 '}\n';
6570 });
6571 code += 'return s;';
6572 fn = Function('s', 'k', code); // s=scope, k=locals
6573 fn.toString = function() { return code; };
6574 }
6575
6576 return getterFnCache[path] = fn;
6577}
6578
6579///////////////////////////////////
6580

Callers 2

readIdentFunction · 0.85
_fieldAccessFunction · 0.85

Calls 2

cspSafeGetterFnFunction · 0.85
forEachFunction · 0.85

Tested by

no test coverage detected