Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 05ee69e

Browse files
committed
perf($parse): remove getterFn wrapper for internal use
1 parent c074181 commit 05ee69e

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/ng/parse.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,7 @@ Lexer.prototype = {
317317
token.fn = fn;
318318
token.constant = true;
319319
} else {
320-
var getter = getterFn(ident, this.options, parserText);
321-
// TODO(perf): consider exposing the getter reference
322-
token.fn = extend(function $parsePathGetter(self, locals) {
323-
return getter(self, locals);
324-
}, {
325-
assign: function(self, value) {
326-
return setter(self, ident, value, parserText);
327-
}
328-
});
320+
token.fn = getterFn(ident, this.options, parserText);
329321
}
330322

331323
this.tokens.push(token);
@@ -413,6 +405,19 @@ Parser.prototype = {
413405
this.throwError('is an unexpected token', this.tokens[0]);
414406
}
415407

408+
//Every value returned must be unique.
409+
//If the top most value is shared, such as a getterFn, it must be wrapped
410+
// TODO(perf): consider exposing the getter reference, at least to $watch
411+
if (value.$$parseShared) {
412+
var exp = value;
413+
value = function $parsedWrapper(self, locals) {
414+
return exp(self, locals);
415+
};
416+
value.assign = exp.assign;
417+
value.literal = exp.literal;
418+
value.constant = exp.constant;
419+
}
420+
416421
value.literal = !!value.literal;
417422
value.constant = !!value.constant;
418423

@@ -935,6 +940,11 @@ function getterFn(path, options, fullExp) {
935940
var evaledFnGetter = new Function('s', 'l', code); // s=scope, l=locals
936941
/* jshint +W054 */
937942
evaledFnGetter.toString = valueFn(code);
943+
evaledFnGetter.assign = function(self, value) {
944+
return setter(self, path, value, path);
945+
};
946+
evaledFnGetter.$$parseShared = true;
947+
938948
fn = evaledFnGetter;
939949
}
940950

test/ng/parseSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ describe('parser', function() {
722722
scope.$eval('a.toString.constructor = 1', scope);
723723
}).toThrowMinErr(
724724
'$parse', 'isecfn', 'Referencing Function in Angular expressions is disallowed! ' +
725-
'Expression: a.toString.constructor = 1');
725+
'Expression: a.toString.constructor');
726726
});
727727

728728

0 commit comments

Comments
 (0)