aboutsummaryrefslogtreecommitdiffstats
path: root/src/Scope.js
diff options
context:
space:
mode:
authorMisko Hevery2010-10-14 21:01:25 -0700
committerMisko Hevery2010-10-14 21:49:59 -0700
commit7903f4d9407b0ffe478341f9f88779f34efb218e (patch)
treee4002306744cbab1a7b26e04e5b1ed2fa9bc00cf /src/Scope.js
parenta7da160c1d5f1614a7fa66ca9c31edb6edc7e0d8 (diff)
downloadangular.js-7903f4d9407b0ffe478341f9f88779f34efb218e.tar.bz2
use new Function instead of eval()
Close #52
Diffstat (limited to 'src/Scope.js')
-rw-r--r--src/Scope.js27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/Scope.js b/src/Scope.js
index 5c15246b..b83d47db 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -60,28 +60,25 @@ function getterFn(path){
var fn = getterFnCache[path];
if (fn) return fn;
- var code = 'function (s){\n';
- code += ' var l, fn, t;\n';
+ var code = 'var l, fn, t;\n';
foreach(path.split('.'), function(key) {
key = (JS_KEYWORDS[key]) ? '["' + key + '"]' : '.' + key;
- code += ' if(!s) return s;\n';
- code += ' l = s;\n';
- code += ' s = s' + key + ';\n';
- code += ' if(typeof s == "'+$function+'") \n';
- code += ' s = function(){ return l'+key+'.apply(l, arguments); };\n';
+ code += 'if(!s) return s;\n' +
+ 'l=s;\n' +
+ 's=s' + key + ';\n' +
+ 'if(typeof s=="function") s = function(){ return l'+key+'.apply(l, arguments); };\n';
if (key.charAt(1) == '$') {
// special code for super-imposed functions
var name = key.substr(2);
- code += ' if(!s) {\n';
- code += ' t = angular.Global.typeOf(l);\n';
- code += ' fn = (angular[t.charAt(0).toUpperCase() + t.substring(1)]||{})["' + name + '"];\n';
- code += ' if (fn)\n';
- code += ' s = function(){ return fn.apply(l, [l].concat(Array.prototype.slice.call(arguments, 0, arguments.length))); };\n';
- code += ' }\n';
+ code += 'if(!s) {\n' +
+ ' t = angular.Global.typeOf(l);\n' +
+ ' fn = (angular[t.charAt(0).toUpperCase() + t.substring(1)]||{})["' + name + '"];\n' +
+ ' if (fn) s = function(){ return fn.apply(l, [l].concat(Array.prototype.slice.call(arguments, 0, arguments.length))); };\n' +
+ '}\n';
}
});
- code += ' return s;\n}';
- fn = eval('fn = ' + code);
+ code += 'return s;';
+ fn = Function('s', code);
fn["toString"] = function(){ return code; };
return getterFnCache[path] = fn;