RN: Cleanup OSS JS & Flow Declarations

Reviewed By: vjeux

Differential Revision: D4210763

fbshipit-source-id: 5abaa547100b8badd13bcf311ceffc5b4098d252
This commit is contained in:
Tim Yung 2016-11-20 17:49:21 -08:00 committed by Facebook Github Bot
parent 4c74a3fe2e
commit 40c3857d23
16 changed files with 112 additions and 125 deletions

View File

@ -1,5 +1,4 @@
/* -*- Mode: js; js-indent-level: 2; -*- */
/*
/**
* Copyright 2011 Mozilla Foundation and contributors
* Licensed under the New BSD license. See LICENSE or:
* http://opensource.org/licenses/BSD-3-Clause
@ -33,9 +32,15 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @copyright
* @noflow
*/
/*eslint no-bitwise:0,quotes:0,global-strict:0*/
/* -*- Mode: js; js-indent-level: 2; -*- */
/* eslint-disable no-bitwise, quotes, global-strict */
'use strict';
var charToIntMap = {};
var intToCharMap = {};

View File

@ -1,10 +1,16 @@
/**
* Copyright 2013-2014 Facebook, Inc.
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @provides Array.es6
* @polyfill
*/
/*eslint-disable */
/* eslint-disable */
/**
* Creates an array from array like objects.

View File

@ -1,5 +1,10 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @provides Array.prototype.es6
* @polyfill

View File

@ -1,5 +1,5 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
@ -10,6 +10,8 @@
* @polyfill
*/
/* eslint-disable strict */
if (Number.EPSILON === undefined) {
Object.defineProperty(Number, 'EPSILON', {
value: Math.pow(2, -52),

View File

@ -1,18 +1,23 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @provides Object.es7
* @polyfill
*/
(function() {
'use strict';
const hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Returns an array of the given object's own enumerable entries.
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries
*
*/
if (typeof Object.entries !== 'function') {
Object.entries = function(object) {
@ -21,8 +26,8 @@
throw new TypeError('Object.entries called on non-object');
}
let entries = [];
for (let key in object) {
const entries = [];
for (const key in object) {
if (hasOwnProperty.call(object, key)) {
entries.push([key, object[key]]);
}
@ -34,7 +39,6 @@
/**
* Returns an array of the given object's own enumerable entries.
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/values
*
*/
if (typeof Object.values !== 'function') {
Object.values = function(object) {
@ -43,8 +47,8 @@
throw new TypeError('Object.values called on non-object');
}
let values = [];
for (let key in object) {
const values = [];
for (const key in object) {
if (hasOwnProperty.call(object, key)) {
values.push(object[key]);
}
@ -53,4 +57,4 @@
};
}
})();
})();

View File

@ -1,10 +1,16 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @provides String.prototype.es6
* @polyfill
*/
/*eslint global-strict:0, no-extend-native:0, no-bitwise:0 */
/*jshint bitwise:false*/
/* eslint-disable strict, no-extend-native, no-bitwise */
/*
* NOTE: We use (Number(x) || 0) to replace NaN values with zero.

View File

@ -1,79 +0,0 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
jest.disableAutomock();
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()', () => {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN#Examples
beforeEach(() => {
delete Number.isNaN;
jest.resetModuleRegistry();
require('../Number.es6');
});
it('returns true when fed something that is not-a-number', () => {
[
NaN,
Number.NaN,
0 / 0,
].forEach(value => expect(Number.isNaN(value)).toBe(true));
});
it('returns false when fed something other than not-a-number', () => {
[
'NaN',
undefined,
{},
'blabla',
true,
null,
37,
'37',
'37.37',
'',
' ',
].forEach(value => expect(Number.isNaN(value)).toBe(false));
});
});
});

View File

@ -1,10 +1,17 @@
/**
* Copyright 2004-present Facebook. All Rights Reserved.
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/
/* eslint-disable fb-www/object-create-only-one-param */
/* eslint-disable fb-www/object-create-only-one-param */
'use strict';
jest.disableAutomock();
@ -35,19 +42,19 @@ describe('Object (ES7)', () => {
});
it('should return enumerable entries', () => {
let foo = Object.defineProperties({}, {
const foo = Object.defineProperties({}, {
x: {value: 10, enumerable: true},
y: {value: 20},
});
expect(Object.entries(foo)).toEqual([['x', 10]]);
let bar = {x: 10, y: 20};
const bar = {x: 10, y: 20};
expect(Object.entries(bar)).toEqual([['x', 10], ['y', 20]]);
});
it('should work with proto-less objects', () => {
let foo = Object.create(null, {
const foo = Object.create(null, {
x: {value: 10, enumerable: true},
y: {value: 20},
});
@ -56,7 +63,7 @@ describe('Object (ES7)', () => {
});
it('should return only own entries', () => {
let foo = Object.create({z: 30}, {
const foo = Object.create({z: 30}, {
x: {value: 10, enumerable: true},
y: {value: 20},
});
@ -84,19 +91,19 @@ describe('Object (ES7)', () => {
});
it('should return enumerable values', () => {
let foo = Object.defineProperties({}, {
const foo = Object.defineProperties({}, {
x: {value: 10, enumerable: true},
y: {value: 20},
});
expect(Object.values(foo)).toEqual([10]);
let bar = {x: 10, y: 20};
const bar = {x: 10, y: 20};
expect(Object.values(bar)).toEqual([10, 20]);
});
it('should work with proto-less objects', () => {
let foo = Object.create(null, {
const foo = Object.create(null, {
x: {value: 10, enumerable: true},
y: {value: 20},
});
@ -105,7 +112,7 @@ describe('Object (ES7)', () => {
});
it('should return only own values', () => {
let foo = Object.create({z: 30}, {
const foo = Object.create({z: 30}, {
x: {value: 10, enumerable: true},
y: {value: 20},
});
@ -117,4 +124,4 @@ describe('Object (ES7)', () => {
expect(Object.values('ab')).toEqual(['a', 'b']);
});
});
});
});

View File

@ -5,6 +5,8 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @polyfill
*/
/* eslint-disable */

View File

@ -6,9 +6,6 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* This pipes all of our console logging functions to native logging so that
* JavaScript errors in required modules show up in Xcode via NSLog.
*
* @provides console
* @polyfill
* @nolint
@ -16,6 +13,10 @@
/* eslint-disable */
/**
* This pipes all of our console logging functions to native logging so that
* JavaScript errors in required modules show up in Xcode via NSLog.
*/
const inspect = (function() {
// Copyright Joyent, Inc. and other Node contributors.
//

View File

@ -6,15 +6,11 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* The particular require runtime that we are using looks for a global
* `ErrorUtils` object and if it exists, then it requires modules with the
* error handler specified via ErrorUtils.setGlobalHandler by calling the
* require function with applyWithGuard. Since the require module is loaded
* before any of the modules, this ErrorUtils must be defined (and the handler
* set) globally before requiring anything.
* @polyfill
*/
/* eslint strict:0 */
/* eslint-disable strict */
let _inGuard = 0;
/**
@ -26,6 +22,14 @@ let _globalHandler = function onError(e) {
throw e;
};
/**
* The particular require runtime that we are using looks for a global
* `ErrorUtils` object and if it exists, then it requires modules with the
* error handler specified via ErrorUtils.setGlobalHandler by calling the
* require function with applyWithGuard. Since the require module is loaded
* before any of the modules, this ErrorUtils must be defined (and the handler
* set) globally before requiring anything.
*/
const ErrorUtils = {
setGlobalHandler: function(fun) {
_globalHandler = fun;

View File

@ -6,17 +6,16 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* This pipes all of our console logging functions to native logging so that
* JavaScript errors in required modules show up in Xcode via NSLog.
*
* @provides Object.es6
* @polyfill
*/
/* eslint-disable strict */
// WARNING: This is an optimized version that fails on hasOwnProperty checks
// and non objects. It's not spec-compliant. It's a perf optimization.
// This is only needed for iOS 8 and current Android JSC.
/* eslint strict:0 */
// This is only needed for iOS 8 and current Android JSC.
Object.assign = function(target, sources) {
if (__DEV__) {
if (target == null) {

View File

@ -1,4 +1,16 @@
/* eslint strict:0 */
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @polyfill
*/
/* eslint-disable strict */
global.__DEV__ = false;
global.__BUNDLE_START_TIME__ = Date.now();

View File

@ -1,4 +1,16 @@
/* eslint strict:0 */
/**
* Copyright (c) 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @polyfill
*/
/* eslint-disable strict */
global.__DEV__ = true;
global.__BUNDLE_START_TIME__ = Date.now();

View File

@ -6,6 +6,7 @@
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @polyfill
* @flow
*/

View File

@ -1,4 +1,4 @@
/**
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*