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

Commit 61289a5

Browse files
committed
feat($parse): handle Infinity
Closes #9492
1 parent e6ece7d commit 61289a5

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/ng/parse.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ forEach({
8686
'null': function() { return null; },
8787
'true': function() { return true; },
8888
'false': function() { return false; },
89-
'undefined': function() {}
89+
'undefined': function() {},
90+
'Infinity': function() { return Infinity; }
9091
}, function(constantGetter, name) {
9192
constantGetter.constant = constantGetter.literal = constantGetter.sharedGetter = true;
9293
CONSTANTS[name] = constantGetter;

test/ng/parseSpec.js

+19
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,25 @@ describe('parser', function() {
632632
expect(scope.a).not.toBeDefined();
633633
});
634634

635+
it('should evaluate Infinity', function() {
636+
expect(scope.$eval("Infinity")).toBe(Infinity);
637+
expect(scope.$eval("a=Infinity")).toBe(Infinity);
638+
expect(scope.a).toBe(Infinity);
639+
});
640+
641+
it('should evaluate -Infinity', function() {
642+
expect(scope.$eval("-Infinity")).toBe(-Infinity);
643+
expect(scope.$eval("a=-Infinity")).toBe(-Infinity);
644+
expect(scope.a).toBe(-Infinity);
645+
});
646+
647+
it('should dereference object properties named "Infinity"', function() {
648+
scope.obj = { 'Infinity': 42 };
649+
expect(scope.$eval("obj.Infinity")).toBe(42);
650+
expect(scope.$eval("obj.Infinity = 43")).toBe(43);
651+
expect(scope.obj.Infinity).toBe(43);
652+
});
653+
635654
it('should allow assignment after array dereference', function() {
636655
scope.obj = [{}];
637656
scope.$eval('obj[0].name=1');

0 commit comments

Comments
 (0)