mirror of https://github.com/status-im/metro.git
Move `Number` polyfills into the `/polyfills/` directory
Reviewed By: vjeux Differential Revision: D3223317 fb-gh-sync-id: a49a14f217b27d6542b65c4780c557e73da2443f fbshipit-source-id: a49a14f217b27d6542b65c4780c557e73da2443f
This commit is contained in:
parent
ca409964fc
commit
d07a52d887
|
@ -10,6 +10,21 @@
|
||||||
* @polyfill
|
* @polyfill
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (Number.EPSILON === undefined) {
|
||||||
|
Object.defineProperty(Number, 'EPSILON', {
|
||||||
|
value: Math.pow(2, -52),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (Number.MAX_SAFE_INTEGER === undefined) {
|
||||||
|
Object.defineProperty(Number, 'MAX_SAFE_INTEGER', {
|
||||||
|
value: Math.pow(2, 53) - 1,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (Number.MIN_SAFE_INTEGER === undefined) {
|
||||||
|
Object.defineProperty(Number, 'MIN_SAFE_INTEGER', {
|
||||||
|
value: -(Math.pow(2, 53) - 1),
|
||||||
|
});
|
||||||
|
}
|
||||||
if (!Number.isNaN) {
|
if (!Number.isNaN) {
|
||||||
// https://github.com/dherman/tc39-codex-wiki/blob/master/data/es6/number/index.md#polyfill-for-numberisnan
|
// https://github.com/dherman/tc39-codex-wiki/blob/master/data/es6/number/index.md#polyfill-for-numberisnan
|
||||||
const globalIsNaN = global.isNaN;
|
const globalIsNaN = global.isNaN;
|
||||||
|
|
|
@ -12,6 +12,40 @@
|
||||||
jest.autoMockOff();
|
jest.autoMockOff();
|
||||||
|
|
||||||
describe('Number (ES6)', () => {
|
describe('Number (ES6)', () => {
|
||||||
|
describe('EPSILON', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
delete Number.EPSILON;
|
||||||
|
jest.resetModuleRegistry();
|
||||||
|
require('../Number.es6');
|
||||||
|
});
|
||||||
|
it('is 2^(-52)', () => {
|
||||||
|
expect(Number.EPSILON).toBe(Math.pow(2, -52));
|
||||||
|
});
|
||||||
|
it('can be used to test equality', () => {
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/EPSILON#Testing_equality
|
||||||
|
expect(Number.EPSILON).toBeGreaterThan(Math.abs(0.2 - 0.3 + 0.1));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('MAX_SAFE_INTEGER', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
delete Number.MAX_SAFE_INTEGER;
|
||||||
|
jest.resetModuleRegistry();
|
||||||
|
require('../Number.es6');
|
||||||
|
});
|
||||||
|
it('is 2^53 - 1', () => {
|
||||||
|
expect(Number.MAX_SAFE_INTEGER).toBe(Math.pow(2, 53) - 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('MIN_SAFE_INTEGER', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
delete Number.MIN_SAFE_INTEGER;
|
||||||
|
jest.resetModuleRegistry();
|
||||||
|
require('../Number.es6');
|
||||||
|
});
|
||||||
|
it('is -(2^53 - 1)', () => {
|
||||||
|
expect(Number.MIN_SAFE_INTEGER).toBe(-(Math.pow(2, 53) - 1));
|
||||||
|
});
|
||||||
|
});
|
||||||
describe('isNaN()', () => {
|
describe('isNaN()', () => {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#Examples
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#Examples
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
Loading…
Reference in New Issue