Skip to content

Commit

Permalink
[Fix] ensure ES3 Number constants don’t get lost in ES3 browsers.
Browse files Browse the repository at this point in the history
Fixes #402.
  • Loading branch information
ljharb committed Jan 27, 2016
1 parent 78e307c commit 1a6941f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
8 changes: 8 additions & 0 deletions es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,14 @@
return NumberShim;
}());
wrapConstructor(OrigNumber, NumberShim, {});
// this is necessary for ES3 browsers, where these properties are non-enumerable.
defineProperties(NumberShim, {
NaN: OrigNumber.NaN,
MAX_VALUE: OrigNumber.MAX_VALUE,
MIN_VALUE: OrigNumber.MIN_VALUE,
NEGATIVE_INFINITY: OrigNumber.NEGATIVE_INFINITY,
POSITIVE_INFINITY: OrigNumber.POSITIVE_INFINITY
});
/* globals Number: true */
/* eslint-disable no-undef */
/* jshint -W020 */
Expand Down
30 changes: 30 additions & 0 deletions test/number.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,36 @@ describe('Number', function () {
expect(Number.propertyIsEnumerable('EPSILON')).to.equal(false);
expect(Number.EPSILON).to.equal(2.2204460492503130808472633361816e-16);
});

it('should have NaN', function () {
expect(Number).to.have.property('NaN');
expect(Number.propertyIsEnumerable('NaN')).to.equal(false);
expect(isNaN(Number.NaN)).to.equal(true);
});

it('should have MAX_VALUE', function () {
expect(Number).to.have.property('MAX_VALUE');
expect(Number.propertyIsEnumerable('MAX_VALUE')).to.equal(false);
expect(Number.MAX_VALUE).to.equal(1.7976931348623157e+308);
});

it('should have MIN_VALUE', function () {
expect(Number).to.have.property('MIN_VALUE');
expect(Number.propertyIsEnumerable('MIN_VALUE')).to.equal(false);
expect(Number.MIN_VALUE).to.equal(5e-324);
});

it('should have NEGATIVE_INFINITY', function () {
expect(Number).to.have.property('NEGATIVE_INFINITY');
expect(Number.propertyIsEnumerable('NEGATIVE_INFINITY')).to.equal(false);
expect(Number.NEGATIVE_INFINITY).to.equal(-Infinity);
});

it('should have POSITIVE_INFINITY', function () {
expect(Number).to.have.property('POSITIVE_INFINITY');
expect(Number.propertyIsEnumerable('POSITIVE_INFINITY')).to.equal(false);
expect(Number.POSITIVE_INFINITY).to.equal(Infinity);
});
});

describe('.parseInt()', function () {
Expand Down

0 comments on commit 1a6941f

Please sign in to comment.