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

Commit 595cc2e

Browse files
committed
feat($parse): handle Infinity and NaN
Closes #9492
1 parent 4474633 commit 595cc2e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/ng/parse.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ 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; },
91+
'NaN': function() { return NaN; }
9092
}, function(constantGetter, name) {
9193
constantGetter.constant = constantGetter.literal = constantGetter.sharedGetter = true;
9294
CONSTANTS[name] = constantGetter;

test/ng/parseSpec.js

+32
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,38 @@ 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+
654+
it('should evaluate NaN', function() {
655+
expect(scope.$eval("NaN")).toBeNaN();
656+
expect(scope.$eval("a=NaN")).toBeNaN();
657+
expect(scope.a).toBeNaN();
658+
});
659+
660+
it('should dereference object properties named "NaN"', function() {
661+
scope.obj = { 'NaN': 42 };
662+
expect(scope.$eval("obj.NaN")).toBe(42);
663+
expect(scope.$eval("obj.NaN = 43")).toBe(43);
664+
expect(scope.obj.NaN).toBe(43);
665+
});
666+
635667
it('should allow assignment after array dereference', function() {
636668
scope.obj = [{}];
637669
scope.$eval('obj[0].name=1');

0 commit comments

Comments
 (0)