mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-27 19:25:11 +08:00
[react-packager][streamline oss] Move open sourced JS source to react-native-github
This commit is contained in:
364
Libraries/vendor/core/ES6Promise.js
vendored
Normal file
364
Libraries/vendor/core/ES6Promise.js
vendored
Normal file
@@ -0,0 +1,364 @@
|
||||
/**
|
||||
* @generated SignedSource<<d169e3bbcd91c2e26877882e0d02f289>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule ES6Promise
|
||||
*
|
||||
* This module implements the minimum functionality necessary to comply
|
||||
* with chapter 25.4 of the ES6 specification. Any extensions to Promise
|
||||
* or Promise.prototype should be added in the Promise module.
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-objects
|
||||
*/
|
||||
|
||||
module.exports = (function(global, undefined) {
|
||||
'use strict';
|
||||
|
||||
var setImmediate = require('setImmediate');
|
||||
|
||||
// These are the possible values for slots(promise).state.
|
||||
var PENDING_STATE = 'pending';
|
||||
var FULFILLED_STATE = 'fulfilled';
|
||||
var REJECTED_STATE = 'rejected';
|
||||
|
||||
// The ES6 specification makes heavy use of a notion of internal slots.
|
||||
// Some of these slots are best implemented as closure variables, such
|
||||
// as the alreadySettled variable in createResolvingFunctions, which
|
||||
// corresponds to the resolve.[[AlreadyResolved]].value property in the
|
||||
// specification. Other slots are best implemented as properties of a
|
||||
// slots object attached to the host object by a pseudo-private
|
||||
// property. The latter kind of slots may be accessed by passing the
|
||||
// host object (such as a Promise or a resolve/reject function object)
|
||||
// to the slots function; e.g., the slots(promise).state slot, which
|
||||
// corresponds to promise.[[PromiseState]] in the specification.
|
||||
var slotsKey = '__slots$' + Math.random().toString(36).slice(2);
|
||||
function slots(obj) {
|
||||
var result = obj[slotsKey];
|
||||
if (!result) {
|
||||
// In ES5+ environments, this property will be safely non-writable,
|
||||
// non-configurable, and non-enumerable. This implementation does
|
||||
// not logically rely on those niceties, however, so this code works
|
||||
// just fine in pre-ES5 environments, too.
|
||||
obj[slotsKey] = result = {};
|
||||
if (Object.defineProperty) try {
|
||||
Object.defineProperty(obj, slotsKey, { value: result });
|
||||
} catch (definePropertyIsBrokenInIE8) {}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Reusable callback functions. The identify function is the default
|
||||
// when onFulfilled is undefined or null, and the raise function is the
|
||||
// default when onRejected is undefined or null.
|
||||
function identity(x) { return x; }
|
||||
function raise(x) { throw x; }
|
||||
|
||||
/**
|
||||
* When the Promise function is called with argument executor, the
|
||||
* following steps are taken:
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise
|
||||
*
|
||||
* The executor argument must be a function object. It is called for
|
||||
* initiating and reporting completion of the possibly deferred action
|
||||
* represented by this Promise object. The executor is called with two
|
||||
* arguments: resolve and reject. These are functions that may be used
|
||||
* by the executor function to report eventual completion or failure of
|
||||
* the deferred computation. Returning from the executor function does
|
||||
* not mean that the deferred action has been completed, but only that
|
||||
* the request to eventually perform the deferred action has been
|
||||
* accepted.
|
||||
*
|
||||
* The resolve function that is passed to an executor function accepts a
|
||||
* single argument. The executor code may eventually call the resolve
|
||||
* function to indicate that it wishes to resolve the associated Promise
|
||||
* object. The argument passed to the resolve function represents the
|
||||
* eventual value of the deferred action and can be either the actual
|
||||
* fulfillment value or another Promise object which will provide the
|
||||
* value if it is fullfilled.
|
||||
*
|
||||
* The reject function that is passed to an executor function accepts a
|
||||
* single argument. The executor code may eventually call the reject
|
||||
* function to indicate that the associated Promise is rejected and will
|
||||
* never be fulfilled. The argument passed to the reject function is
|
||||
* used as the rejection value of the promise. Typically it will be an
|
||||
* Error object.
|
||||
*
|
||||
* When Promise is called as a function rather than as a constructor, it
|
||||
* initializes its this value with the internal state necessary to
|
||||
* support the Promise.prototype methods.
|
||||
*
|
||||
* The Promise constructor is designed to be subclassable. It may be
|
||||
* used as the value in an extends clause of a class
|
||||
* definition. Subclass constructors that intend to inherit the
|
||||
* specified Promise behaviour must include a super call to Promise,
|
||||
* e.g. by invoking Promise.call(this, executor).
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise-constructor
|
||||
*/
|
||||
function Promise(executor) {
|
||||
var promiseSlots = slots(this);
|
||||
promiseSlots.state = PENDING_STATE;
|
||||
promiseSlots.fulfillReactions = [];
|
||||
promiseSlots.rejectReactions = [];
|
||||
|
||||
var resolvingFunctions = createResolvingFunctions(this);
|
||||
var reject = resolvingFunctions.reject;
|
||||
|
||||
try {
|
||||
executor(resolvingFunctions.resolve, reject);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
function createResolvingFunctions(promise) {
|
||||
var alreadySettled = false;
|
||||
|
||||
return {
|
||||
resolve: function(resolution) {
|
||||
if (!alreadySettled) {
|
||||
alreadySettled = true;
|
||||
|
||||
if (resolution === promise) {
|
||||
return settlePromise(
|
||||
promise,
|
||||
REJECTED_STATE,
|
||||
new TypeError('Cannot resolve promise with itself')
|
||||
);
|
||||
}
|
||||
|
||||
// To be treated as a Promise-like object, the resolution only
|
||||
// needs to be an object with a callable .then method.
|
||||
if (!resolution ||
|
||||
typeof resolution !== "object" ||
|
||||
typeof resolution.then !== "function") {
|
||||
return settlePromise(promise, FULFILLED_STATE, resolution);
|
||||
}
|
||||
|
||||
var resolvingFunctions = createResolvingFunctions(promise);
|
||||
var reject = resolvingFunctions.reject;
|
||||
|
||||
try {
|
||||
resolution.then(resolvingFunctions.resolve, reject);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
reject: function(reason) {
|
||||
if (!alreadySettled) {
|
||||
alreadySettled = true;
|
||||
settlePromise(promise, REJECTED_STATE, reason);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// This function unifies the FulfillPromise and RejectPromise functions
|
||||
// defined in the ES6 specification.
|
||||
function settlePromise(promise, state, result) {
|
||||
var promiseSlots = slots(promise);
|
||||
if (promiseSlots.state !== PENDING_STATE) {
|
||||
throw new Error('Settling a ' + promiseSlots.state + ' promise');
|
||||
}
|
||||
|
||||
var reactions;
|
||||
if (state === FULFILLED_STATE) {
|
||||
reactions = promiseSlots.fulfillReactions;
|
||||
} else if (state === REJECTED_STATE) {
|
||||
reactions = promiseSlots.rejectReactions;
|
||||
}
|
||||
|
||||
promiseSlots.result = result;
|
||||
promiseSlots.fulfillReactions = undefined;
|
||||
promiseSlots.rejectReactions = undefined;
|
||||
promiseSlots.state = state;
|
||||
|
||||
var count = reactions.length;
|
||||
count && setImmediate(function() {
|
||||
for (var i = 0; i < count; ++i) {
|
||||
reactions[i](promiseSlots.result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The Promise.all function returns a new promise which is fulfilled
|
||||
* with an array of fulfillment values for the passed promises, or
|
||||
* rejects with the reason of the first passed promise that rejects. It
|
||||
* resoves all elements of the passed iterable to promises as it runs
|
||||
* this algorithm.
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise.all
|
||||
*/
|
||||
Promise.all = function(array) {
|
||||
var Promise = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
var results = [];
|
||||
var remaining = 0;
|
||||
array.forEach(function(element, index) {
|
||||
++remaining; // Array might be sparse.
|
||||
Promise.resolve(element).then(function(result) {
|
||||
if (!results.hasOwnProperty(index)) {
|
||||
results[index] = result;
|
||||
--remaining || resolve(results);
|
||||
}
|
||||
}, reject);
|
||||
});
|
||||
remaining || resolve(results);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* The Promise.race function returns a new promise which is settled in
|
||||
* the same way as the first passed promise to settle. It resolves all
|
||||
* elements of the passed iterable to promises as it runs this
|
||||
* algorithm.
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise.race
|
||||
*/
|
||||
Promise.race = function(array) {
|
||||
var Promise = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
array.forEach(function(element) {
|
||||
Promise.resolve(element).then(resolve, reject);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* The Promise.resolve function returns either a new promise resolved
|
||||
* with the passed argument, or the argument itself if the argument a
|
||||
* promise produced by this construtor.
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise.resolve
|
||||
*/
|
||||
Promise.resolve = function(x) {
|
||||
return x instanceof Promise && x.constructor === this
|
||||
? x // Refuse to create promises for promises.
|
||||
: new this(function(resolve) { resolve(x); });
|
||||
};
|
||||
|
||||
/**
|
||||
* The Promise.reject function returns a new promise rejected with the
|
||||
* passed argument.
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise.reject
|
||||
*/
|
||||
Promise.reject = function(r) {
|
||||
return new this(function(_, reject) { reject(r); });
|
||||
};
|
||||
|
||||
var Pp = Promise.prototype;
|
||||
|
||||
/**
|
||||
* When the .then method is called with arguments onFulfilled and
|
||||
* onRejected, the following steps are taken:
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise.prototype.then
|
||||
*/
|
||||
Pp.then = function(onFulfilled, onRejected) {
|
||||
var capabilityResolve;
|
||||
var capabilityReject;
|
||||
var capabilityPromise = new this.constructor(function(resolve, reject) {
|
||||
capabilityResolve = resolve;
|
||||
capabilityReject = reject;
|
||||
});
|
||||
|
||||
if (typeof capabilityResolve !== "function") {
|
||||
throw new TypeError('Uncallable Promise resolve function');
|
||||
}
|
||||
|
||||
if (typeof capabilityReject !== "function") {
|
||||
throw new TypeError('Uncallable Promise reject function');
|
||||
}
|
||||
|
||||
if (onFulfilled === undefined || onFulfilled === null) {
|
||||
onFulfilled = identity;
|
||||
}
|
||||
|
||||
if (onRejected === undefined || onRejected === null) {
|
||||
onRejected = raise;
|
||||
}
|
||||
|
||||
var promiseSlots = slots(this);
|
||||
var state = promiseSlots.state;
|
||||
if (state === PENDING_STATE) {
|
||||
promiseSlots.fulfillReactions.push(makeReaction(
|
||||
capabilityResolve,
|
||||
capabilityReject,
|
||||
onFulfilled
|
||||
));
|
||||
|
||||
promiseSlots.rejectReactions.push(makeReaction(
|
||||
capabilityResolve,
|
||||
capabilityReject,
|
||||
onRejected
|
||||
));
|
||||
|
||||
} else if (state === FULFILLED_STATE || state === REJECTED_STATE) {
|
||||
setImmediate(makeReaction(
|
||||
capabilityResolve,
|
||||
capabilityReject,
|
||||
state === FULFILLED_STATE ? onFulfilled : onRejected,
|
||||
promiseSlots.result
|
||||
));
|
||||
}
|
||||
|
||||
return capabilityPromise;
|
||||
};
|
||||
|
||||
function makeReaction(resolve, reject, handler, argument) {
|
||||
var hasArgument = arguments.length > 3;
|
||||
return function(result) {
|
||||
try {
|
||||
result = handler(hasArgument ? argument : result);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve(result);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* When the .catch method is called with argument onRejected, the
|
||||
* following steps are taken:
|
||||
*
|
||||
* people.mozilla.org/~jorendorff/es6-draft.html#sec-promise.prototype.catch
|
||||
*/
|
||||
Pp['catch'] = function(onRejected) {
|
||||
return this.then(undefined, onRejected);
|
||||
};
|
||||
|
||||
Pp.toString = function() {
|
||||
return '[object Promise]';
|
||||
};
|
||||
|
||||
return Promise;
|
||||
}(/* jslint evil: true */ Function('return this')()));
|
||||
626
Libraries/vendor/core/Map.js
vendored
Normal file
626
Libraries/vendor/core/Map.js
vendored
Normal file
@@ -0,0 +1,626 @@
|
||||
/**
|
||||
* @generated SignedSource<<375749f44ce7c0f681fc1297943eaf74>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
* @providesModule Map
|
||||
* @preventMunge
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
var guid = require('guid');
|
||||
var isNode = require('isNode');
|
||||
var toIterator = require('toIterator');
|
||||
var _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection');
|
||||
|
||||
module.exports = (function(global, undefined) {
|
||||
// Since our implementation is spec-compliant for the most part we can safely
|
||||
// delegate to a built-in version if exists and is implemented correctly.
|
||||
// Firefox had gotten a few implementation details wrong across different
|
||||
// versions so we guard against that.
|
||||
if (!_shouldPolyfillES6Collection('Map')) {
|
||||
return global.Map;
|
||||
}
|
||||
|
||||
/**
|
||||
* == ES6 Map Collection ==
|
||||
*
|
||||
* This module is meant to implement a Map collection as described in chapter
|
||||
* 23.1 of the ES6 specification.
|
||||
*
|
||||
* Map objects are collections of key/value pairs where both the keys and
|
||||
* values may be arbitrary ECMAScript language values. A distinct key value
|
||||
* may only occur in one key/value pair within the Map's collection.
|
||||
*
|
||||
* https://people.mozilla.org/~jorendorff/es6-draft.html#sec-map-objects
|
||||
*
|
||||
* There only two -- rather small -- diviations from the spec:
|
||||
*
|
||||
* 1. The use of frozen objects as keys.
|
||||
* We decided not to allow and simply throw an error. The reason being is
|
||||
* we store a "hash" on the object for fast access to it's place in the
|
||||
* internal map entries.
|
||||
* If this turns out to be a popular use case it's possible to implement by
|
||||
* overiding `Object.freeze` to store a "hash" property on the object
|
||||
* for later use with the map.
|
||||
*
|
||||
* 2. The `size` property on a map object is a regular property and not a
|
||||
* computed property on the prototype as described by the spec.
|
||||
* The reason being is that we simply want to support ES3 environments
|
||||
* which doesn't implement computed properties.
|
||||
*
|
||||
* == Usage ==
|
||||
*
|
||||
* var map = new Map(iterable);
|
||||
*
|
||||
* map.set(key, value);
|
||||
* map.get(key); // value
|
||||
* map.has(key); // true
|
||||
* map.delete(key); // true
|
||||
*
|
||||
* var iterator = map.keys();
|
||||
* iterator.next(); // {value: key, done: false}
|
||||
*
|
||||
* var iterator = map.values();
|
||||
* iterator.next(); // {value: value, done: false}
|
||||
*
|
||||
* var iterator = map.entries();
|
||||
* iterator.next(); // {value: [key, value], done: false}
|
||||
*
|
||||
* map.forEach(function(value, key){ this === thisArg }, thisArg);
|
||||
*
|
||||
* map.clear(); // resets map.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
// Kinds of map iterations 23.1.5.3
|
||||
var KIND_KEY = 'key';
|
||||
var KIND_VALUE = 'value';
|
||||
var KIND_KEY_VALUE = 'key+value';
|
||||
|
||||
// In older browsers we can't create a null-prototype object so we have to
|
||||
// defend against key collisions with built-in methods.
|
||||
var KEY_PREFIX = '$map_';
|
||||
|
||||
// This property will be used as the internal size variable to disallow
|
||||
// writing and to issue warnings for writings in development.
|
||||
var SECRET_SIZE_PROP;
|
||||
if (__DEV__) {
|
||||
SECRET_SIZE_PROP = '$size' + guid();
|
||||
}
|
||||
|
||||
// In oldIE we use the DOM Node `uniqueID` property to get create the hash.
|
||||
var OLD_IE_HASH_PREFIX = 'IE_HASH_';
|
||||
|
||||
class Map {
|
||||
|
||||
/**
|
||||
* 23.1.1.1
|
||||
* Takes an `iterable` which is basically any object that implements a
|
||||
* Symbol.iterator (@@iterator) method. The iterable is expected to be a
|
||||
* collection of pairs. Each pair is a key/value pair that will be used
|
||||
* to instantiate the map.
|
||||
*
|
||||
* @param {*} iterable
|
||||
*/
|
||||
constructor(iterable) {
|
||||
if (!isObject(this)) {
|
||||
throw new TypeError('Wrong map object type.');
|
||||
}
|
||||
|
||||
initMap(this);
|
||||
|
||||
if (iterable != null) {
|
||||
var it = toIterator(iterable);
|
||||
var next;
|
||||
while (!(next = it.next()).done) {
|
||||
if (!isObject(next.value)) {
|
||||
throw new TypeError('Expected iterable items to be pair objects.');
|
||||
}
|
||||
this.set(next.value[0], next.value[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.1
|
||||
* Clears the map from all keys and values.
|
||||
*/
|
||||
clear() {
|
||||
initMap(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.7
|
||||
* Check if a key exists in the collection.
|
||||
*
|
||||
* @param {*} key
|
||||
* @return {boolean}
|
||||
*/
|
||||
has(key) {
|
||||
var index = getIndex(this, key);
|
||||
return !!(index != null && this._mapData[index]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.9
|
||||
* Adds a key/value pair to the collection.
|
||||
*
|
||||
* @param {*} key
|
||||
* @param {*} value
|
||||
* @return {map}
|
||||
*/
|
||||
set(key, value) {
|
||||
var index = getIndex(this, key);
|
||||
|
||||
if (index != null && this._mapData[index]) {
|
||||
this._mapData[index][1] = value;
|
||||
} else {
|
||||
index = this._mapData.push([
|
||||
key,
|
||||
value
|
||||
]) - 1;
|
||||
setIndex(this, key, index);
|
||||
if (__DEV__) {
|
||||
this[SECRET_SIZE_PROP] += 1;
|
||||
} else {
|
||||
this.size += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.6
|
||||
* Gets a value associated with a key in the collection.
|
||||
*
|
||||
* @param {*} key
|
||||
* @return {*}
|
||||
*/
|
||||
get(key) {
|
||||
var index = getIndex(this, key);
|
||||
if (index == null) {
|
||||
return undefined;
|
||||
} else {
|
||||
return this._mapData[index][1];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 23.1.3.3
|
||||
* Delete a key/value from the collection.
|
||||
*
|
||||
* @param {*} key
|
||||
* @return {boolean} Whether the key was found and deleted.
|
||||
*/
|
||||
delete(key) {
|
||||
var index = getIndex(this, key);
|
||||
if (index != null && this._mapData[index]) {
|
||||
setIndex(this, key, undefined);
|
||||
this._mapData[index] = undefined;
|
||||
if (__DEV__) {
|
||||
this[SECRET_SIZE_PROP] -= 1;
|
||||
} else {
|
||||
this.size -= 1;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.4
|
||||
* Returns an iterator over the key/value pairs (in the form of an Array) in
|
||||
* the collection.
|
||||
*
|
||||
* @return {MapIterator}
|
||||
*/
|
||||
entries() {
|
||||
return new MapIterator(this, KIND_KEY_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.8
|
||||
* Returns an iterator over the keys in the collection.
|
||||
*
|
||||
* @return {MapIterator}
|
||||
*/
|
||||
keys() {
|
||||
return new MapIterator(this, KIND_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.11
|
||||
* Returns an iterator over the values pairs in the collection.
|
||||
*
|
||||
* @return {MapIterator}
|
||||
*/
|
||||
values() {
|
||||
return new MapIterator(this, KIND_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.3.5
|
||||
* Iterates over the key/value pairs in the collection calling `callback`
|
||||
* with [value, key, map]. An optional `thisArg` can be passed to set the
|
||||
* context when `callback` is called.
|
||||
*
|
||||
* @param {function} callback
|
||||
* @param {?object} thisArg
|
||||
*/
|
||||
forEach(callback, thisArg) {
|
||||
if (typeof callback !== 'function') {
|
||||
throw new TypeError('Callback must be callable.');
|
||||
}
|
||||
|
||||
var boundCallback = callback.bind(thisArg || undefined);
|
||||
var mapData = this._mapData;
|
||||
|
||||
// Note that `mapData.length` should be computed on each iteration to
|
||||
// support iterating over new items in the map that were added after the
|
||||
// start of the iteration.
|
||||
for (var i = 0; i < mapData.length; i++) {
|
||||
var entry = mapData[i];
|
||||
if (entry != null) {
|
||||
boundCallback(entry[1], entry[0], this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 23.1.3.12
|
||||
Map.prototype[toIterator.ITERATOR_SYMBOL] = Map.prototype.entries;
|
||||
|
||||
class MapIterator {
|
||||
|
||||
/**
|
||||
* 23.1.5.1
|
||||
* Create a `MapIterator` for a given `map`. While this class is private it
|
||||
* will create objects that will be passed around publicily.
|
||||
*
|
||||
* @param {map} map
|
||||
* @param {string} kind
|
||||
*/
|
||||
constructor(map, kind) {
|
||||
if (!(isObject(map) && map['_mapData'])) {
|
||||
throw new TypeError('Object is not a map.');
|
||||
}
|
||||
|
||||
if ([KIND_KEY, KIND_KEY_VALUE, KIND_VALUE].indexOf(kind) === -1) {
|
||||
throw new Error('Invalid iteration kind.');
|
||||
}
|
||||
|
||||
this._map = map;
|
||||
this._nextIndex = 0;
|
||||
this._kind = kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.1.5.2.1
|
||||
* Get the next iteration.
|
||||
*
|
||||
* @return {object}
|
||||
*/
|
||||
next() {
|
||||
if (!this instanceof Map) {
|
||||
throw new TypeError('Expected to be called on a MapIterator.');
|
||||
}
|
||||
|
||||
var map = this._map;
|
||||
var index = this._nextIndex;
|
||||
var kind = this._kind;
|
||||
|
||||
if (map == null) {
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
|
||||
var entries = map['_mapData'];
|
||||
|
||||
while (index < entries.length) {
|
||||
var record = entries[index];
|
||||
|
||||
index += 1;
|
||||
this._nextIndex = index;
|
||||
|
||||
if (record) {
|
||||
if (kind === KIND_KEY) {
|
||||
return createIterResultObject(record[0], false);
|
||||
} else if (kind === KIND_VALUE) {
|
||||
return createIterResultObject(record[1], false);
|
||||
} else if (kind) {
|
||||
return createIterResultObject(record, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._map = undefined;
|
||||
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
}
|
||||
|
||||
// We can put this in the class definition once we have computed props
|
||||
// transform.
|
||||
// 23.1.5.2.2
|
||||
MapIterator.prototype[toIterator.ITERATOR_SYMBOL] = function() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper Functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Return an index to map.[[MapData]] array for a given Key.
|
||||
*
|
||||
* @param {map} map
|
||||
* @param {*} key
|
||||
* @return {?number}
|
||||
*/
|
||||
function getIndex(map, key) {
|
||||
if (isObject(key)) {
|
||||
var hash = getHash(key);
|
||||
return map._objectIndex[hash];
|
||||
} else {
|
||||
var prefixedKey = KEY_PREFIX + key;
|
||||
if (typeof key === 'string') {
|
||||
return map._stringIndex[prefixedKey];
|
||||
} else {
|
||||
return map._otherIndex[prefixedKey];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup an index that refer to the key's location in map.[[MapData]].
|
||||
*
|
||||
* @param {map} map
|
||||
* @param {*} key
|
||||
*/
|
||||
function setIndex(map, key, index) {
|
||||
var shouldDelete = index == null;
|
||||
|
||||
if (isObject(key)) {
|
||||
var hash = getHash(key);
|
||||
if (shouldDelete) {
|
||||
delete map._objectIndex[hash];
|
||||
} else {
|
||||
map._objectIndex[hash] = index;
|
||||
}
|
||||
} else {
|
||||
var prefixedKey = KEY_PREFIX + key;
|
||||
if (typeof key === 'string') {
|
||||
if (shouldDelete) {
|
||||
delete map._stringIndex[prefixedKey];
|
||||
} else {
|
||||
map._stringIndex[prefixedKey] = index;
|
||||
}
|
||||
} else {
|
||||
if (shouldDelete) {
|
||||
delete map._otherIndex[prefixedKey];
|
||||
} else {
|
||||
map._otherIndex[prefixedKey] = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiate a map with internal slots.
|
||||
*
|
||||
* @param {map} map
|
||||
*/
|
||||
function initMap(map) {
|
||||
// Data structure design inspired by Traceur's Map implementation.
|
||||
// We maintain an internal array for all the entries. The array is needed
|
||||
// to remember order. However, to have a reasonable HashMap performance
|
||||
// i.e. O(1) for insertion, deletion, and retrieval. We maintain indices
|
||||
// in objects for fast look ups. Indices are split up according to data
|
||||
// types to avoid collisions.
|
||||
map._mapData = [];
|
||||
|
||||
// Object index maps from an object "hash" to index. The hash being a unique
|
||||
// property of our choosing that we associate with the object. Association
|
||||
// is done by ways of keeping a non-enumerable property on the object.
|
||||
// Ideally these would be `Object.create(null)` objects but since we're
|
||||
// trying to support ES3 we'll have to gaurd against collisions using
|
||||
// prefixes on the keys rather than rely on null prototype objects.
|
||||
map._objectIndex = {};
|
||||
|
||||
// String index maps from strings to index.
|
||||
map._stringIndex = {};
|
||||
|
||||
// Numbers, booleans, undefined, and null.
|
||||
map._otherIndex = {};
|
||||
|
||||
// Unfortunately we have to support ES3 and cannot have `Map.prototype.size`
|
||||
// be a getter method but just a regular method. The biggest problem with
|
||||
// this is safety. Clients can change the size property easily and possibly
|
||||
// without noticing (e.g. `if (map.size = 1) {..}` kind of typo). What we
|
||||
// can do to mitigate use getters and setters in development to disallow
|
||||
// and issue a warning for changing the `size` property.
|
||||
if (__DEV__) {
|
||||
if (isES5) {
|
||||
// If the `SECRET_SIZE_PROP` property is already defined then we're not
|
||||
// in the first call to `initMap` (e.g. coming from `map.clear()`) so
|
||||
// all we need to do is reset the size without defining the properties.
|
||||
if (map.hasOwnProperty(SECRET_SIZE_PROP)) {
|
||||
map[SECRET_SIZE_PROP] = 0;
|
||||
} else {
|
||||
Object.defineProperty(map, SECRET_SIZE_PROP, {
|
||||
value: 0,
|
||||
writable: true
|
||||
});
|
||||
Object.defineProperty(map, 'size', {
|
||||
set: (v) => {
|
||||
console.error(
|
||||
'PLEASE FIX ME: You are changing the map size property which ' +
|
||||
'should not be writable and will break in production.'
|
||||
);
|
||||
throw new Error('The map size property is not writable.');
|
||||
},
|
||||
get: () => map[SECRET_SIZE_PROP]
|
||||
});
|
||||
}
|
||||
|
||||
// NOTE: Early return to implement immutable `.size` in DEV.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// This is a diviation from the spec. `size` should be a getter on
|
||||
// `Map.prototype`. However, we have to support IE8.
|
||||
map.size = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if something is an object.
|
||||
*
|
||||
* @param {*} o
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isObject(o) {
|
||||
return o != null && (typeof o === 'object' || typeof o === 'function');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an iteration object.
|
||||
*
|
||||
* @param {*} value
|
||||
* @param {boolean} done
|
||||
* @return {object}
|
||||
*/
|
||||
function createIterResultObject(value, done) {
|
||||
return {value, done};
|
||||
}
|
||||
|
||||
// Are we in a legit ES5 environment. Spoiler alert: that doesn't include IE8.
|
||||
var isES5 = (function() {
|
||||
try {
|
||||
Object.defineProperty({}, 'x', {});
|
||||
return true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Check if an object can be extended.
|
||||
*
|
||||
* @param {object|array|function|regexp} o
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isExtensible(o) {
|
||||
if (!isES5) {
|
||||
return true;
|
||||
} else {
|
||||
return Object.isExtensible(o);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* IE has a `uniqueID` set on every DOM node. So we construct the hash from
|
||||
* this uniqueID to avoid memory leaks and the IE cloneNode bug where it
|
||||
* clones properties in addition to the attributes.
|
||||
*
|
||||
* @param {object} node
|
||||
* @return {?string}
|
||||
*/
|
||||
function getIENodeHash(node) {
|
||||
var uniqueID;
|
||||
switch (node.nodeType) {
|
||||
case 1: // Element
|
||||
uniqueID = node.uniqueID;
|
||||
break;
|
||||
case 9: // Document
|
||||
uniqueID = node.documentElement.uniqueID;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uniqueID) {
|
||||
return OLD_IE_HASH_PREFIX + uniqueID;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
var getHash = (function() {
|
||||
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
||||
var hashProperty = guid();
|
||||
var hashCounter = 0;
|
||||
|
||||
/**
|
||||
* Get the "hash" associated with an object.
|
||||
*
|
||||
* @param {object|array|function|regexp} o
|
||||
* @return {number}
|
||||
*/
|
||||
return function getHash(o) {
|
||||
if (o[hashProperty]) {
|
||||
return o[hashProperty];
|
||||
} else if (!isES5 &&
|
||||
o.propertyIsEnumerable &&
|
||||
o.propertyIsEnumerable[hashProperty]) {
|
||||
return o.propertyIsEnumerable[hashProperty];
|
||||
} else if (!isES5 &&
|
||||
isNode(o) &&
|
||||
getIENodeHash(o)) {
|
||||
return getIENodeHash(o);
|
||||
} else if (!isES5 && o[hashProperty]) {
|
||||
return o[hashProperty];
|
||||
}
|
||||
|
||||
if (isExtensible(o)) {
|
||||
hashCounter += 1;
|
||||
if (isES5) {
|
||||
Object.defineProperty(o, hashProperty, {
|
||||
enumerable: false,
|
||||
writable: false,
|
||||
configurable: false,
|
||||
value: hashCounter
|
||||
});
|
||||
} else if (o.propertyIsEnumerable) {
|
||||
// Since we can't define a non-enumerable property on the object
|
||||
// we'll hijack one of the less-used non-enumerable properties to
|
||||
// save our hash on it. Addiotionally, since this is a function it
|
||||
// will not show up in `JSON.stringify` which is what we want.
|
||||
o.propertyIsEnumerable = function() {
|
||||
return propIsEnumerable.apply(this, arguments);
|
||||
};
|
||||
o.propertyIsEnumerable[hashProperty] = hashCounter;
|
||||
} else if (isNode(o)) {
|
||||
// At this point we couldn't get the IE `uniqueID` to use as a hash
|
||||
// and we couldn't use a non-enumerable property to exploit the
|
||||
// dontEnum bug so we simply add the `hashProperty` on the node
|
||||
// itself.
|
||||
o[hashProperty] = hashCounter;
|
||||
} else {
|
||||
throw new Error('Unable to set a non-enumerable property on object.');
|
||||
}
|
||||
return hashCounter;
|
||||
} else {
|
||||
throw new Error('Non-extensible objects are not allowed as keys.');
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
return Map;
|
||||
})(/* jslint evil: true */ Function('return this')());
|
||||
88
Libraries/vendor/core/Promise.js
vendored
Normal file
88
Libraries/vendor/core/Promise.js
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* @generated SignedSource<<a34c32acc93f914fafb29ca64341d514>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* @providesModule Promise
|
||||
*
|
||||
* This module wraps and augments the minimally ES6-compliant Promise
|
||||
* implementation provided by the ES6Promise module.
|
||||
*/
|
||||
|
||||
var Promise = require('ES6Promise');
|
||||
var Pp = Promise.prototype;
|
||||
|
||||
var invariant = require('invariant');
|
||||
var setImmediate = require('setImmediate');
|
||||
var throwImmediate = require('throwImmediate');
|
||||
|
||||
/**
|
||||
* Handle either fulfillment or rejection with the same callback.
|
||||
*/
|
||||
Pp.finally = function(onSettled) {
|
||||
return this.then(onSettled, onSettled);
|
||||
};
|
||||
|
||||
/**
|
||||
* Throw any unhandled error in a separate tick of the event loop.
|
||||
*/
|
||||
Pp.done = function(onFulfilled, onRejected) {
|
||||
this.then(onFulfilled, onRejected).then(null, throwImmediate);
|
||||
};
|
||||
|
||||
/**
|
||||
* This function takes an object with promises as keys and returns a promise.
|
||||
* The returned promise is resolved when all promises from the object are
|
||||
* resolved and gets rejected when the first promise is rejected.
|
||||
*
|
||||
* EXAMPLE:
|
||||
* var promisedMuffin = Promise.allObject({
|
||||
* dough: promisedDough,
|
||||
* frosting: promisedFrosting
|
||||
* }).then(function(results) {
|
||||
* return combine(results.dough, results.frosting);
|
||||
* });
|
||||
*/
|
||||
Promise.allObject = function(/*object*/ promises) {
|
||||
// Throw instead of warn here to make sure people use this only with object.
|
||||
invariant(
|
||||
!Array.isArray(promises),
|
||||
'expected an object, got an array instead'
|
||||
);
|
||||
|
||||
var keys = Object.keys(promises);
|
||||
return Promise.all(keys.map(function(key) {
|
||||
return promises[key];
|
||||
})).then(function(values) {
|
||||
var answers = {};
|
||||
values.forEach(function(value, i) {
|
||||
answers[keys[i]] = value;
|
||||
});
|
||||
return answers;
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Promise;
|
||||
201
Libraries/vendor/core/Set.js
vendored
Normal file
201
Libraries/vendor/core/Set.js
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @generated SignedSource<<1fe20877e83ba5d4d0ea68ab240df21c>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
* @providesModule Set
|
||||
* @preventMunge
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
var Map = require('Map');
|
||||
var toIterator = require('toIterator');
|
||||
var _shouldPolyfillES6Collection = require('_shouldPolyfillES6Collection');
|
||||
|
||||
module.exports = (function(global, undefined) {
|
||||
// Since our implementation is spec-compliant for the most part we can safely
|
||||
// delegate to a built-in version if exists and is implemented correctly.
|
||||
// Firefox had gotten a few implementation details wrong across different
|
||||
// versions so we guard against that.
|
||||
// These checks are adapted from es6-shim https://fburl.com/34437854
|
||||
if (!_shouldPolyfillES6Collection('Set')) {
|
||||
return global.Set;
|
||||
}
|
||||
|
||||
/**
|
||||
* == ES6 Set Collection ==
|
||||
*
|
||||
* This module is meant to implement a Set collection as described in chapter
|
||||
* 23.2 of the ES6 specification.
|
||||
*
|
||||
* Set objects are collections of unique values. Where values can be any
|
||||
* JavaScript value.
|
||||
* https://people.mozilla.org/~jorendorff/es6-draft.html#sec-map-objects
|
||||
*
|
||||
* There only two -- rather small -- diviations from the spec:
|
||||
*
|
||||
* 1. The use of frozen objects as keys. @see Map module for more on this.
|
||||
*
|
||||
* 2. The `size` property on a map object is a regular property and not a
|
||||
* computed property on the prototype as described by the spec.
|
||||
* The reason being is that we simply want to support ES3 environments
|
||||
* which doesn't implement computed properties.
|
||||
*
|
||||
* == Usage ==
|
||||
*
|
||||
* var set = new set(iterable);
|
||||
*
|
||||
* set.set(value);
|
||||
* set.has(value); // true
|
||||
* set.delete(value); // true
|
||||
*
|
||||
* var iterator = set.keys();
|
||||
* iterator.next(); // {value: value, done: false}
|
||||
*
|
||||
* var iterator = set.values();
|
||||
* iterator.next(); // {value: value, done: false}
|
||||
*
|
||||
* var iterator = set.entries();
|
||||
* iterator.next(); // {value: [value, value], done: false}
|
||||
*
|
||||
* set.forEach(function(value, value){ this === thisArg }, thisArg);
|
||||
*
|
||||
* set.clear(); // resets set.
|
||||
*/
|
||||
|
||||
class Set {
|
||||
|
||||
/**
|
||||
* 23.2.1.1
|
||||
*
|
||||
* Takes an optional `iterable` (which is basically any object that
|
||||
* implements a Symbol.iterator (@@iterator) method). That is a collection
|
||||
* of values used to instantiate the set.
|
||||
*
|
||||
* @param {*} iterable
|
||||
*/
|
||||
constructor(iterable) {
|
||||
if (this == null ||
|
||||
(typeof this !== 'object' && typeof this !== 'function')) {
|
||||
throw new TypeError('Wrong set object type.');
|
||||
}
|
||||
|
||||
initSet(this);
|
||||
|
||||
if (iterable != null) {
|
||||
var it = toIterator(iterable);
|
||||
var next;
|
||||
while (!(next = it.next()).done) {
|
||||
this.add(next.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.1
|
||||
*
|
||||
* If it doesn't already exist in the collection a `value` is added.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {set}
|
||||
*/
|
||||
add(value) {
|
||||
this._map.set(value, value);
|
||||
this.size = this._map.size;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.2
|
||||
*
|
||||
* Clears the set.
|
||||
*/
|
||||
clear() {
|
||||
initSet(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.4
|
||||
*
|
||||
* Deletes a `value` from the collection if it exists.
|
||||
* Returns true if the value was found and deleted and false otherwise.
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
delete(value) {
|
||||
var ret = this._map.delete(value);
|
||||
this.size = this._map.size;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.5
|
||||
*
|
||||
* Returns an iterator over a collection of [value, value] tuples.
|
||||
*/
|
||||
entries() {
|
||||
return this._map.entries();
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.6
|
||||
*
|
||||
* Iterate over the collection calling `callback` with (value, value, set).
|
||||
*
|
||||
* @param {function} callback
|
||||
*/
|
||||
forEach(callback) {
|
||||
var thisArg = arguments[1];
|
||||
var it = this._map.keys();
|
||||
var next;
|
||||
while (!(next = it.next()).done) {
|
||||
callback.call(thisArg, next.value, next.value, this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.7
|
||||
*
|
||||
* Iterate over the collection calling `callback` with (value, value, set).
|
||||
*
|
||||
* @param {*} value
|
||||
* @return {boolean}
|
||||
*/
|
||||
has(value) {
|
||||
return this._map.has(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 23.2.3.7
|
||||
*
|
||||
* Returns an iterator over the colleciton of values.
|
||||
*/
|
||||
values() {
|
||||
return this._map.values();
|
||||
}
|
||||
}
|
||||
|
||||
// 23.2.3.11
|
||||
Set.prototype[toIterator.ITERATOR_SYMBOL] = Set.prototype.values;
|
||||
|
||||
// 23.2.3.7
|
||||
Set.prototype.keys = Set.prototype.values;
|
||||
|
||||
function initSet(set) {
|
||||
set._map = new Map();
|
||||
set.size = set._map.size;
|
||||
}
|
||||
|
||||
return Set;
|
||||
})(/* jslint evil: true */ Function('return this')());
|
||||
78
Libraries/vendor/core/_shouldPolyfillES6Collection.js
vendored
Normal file
78
Libraries/vendor/core/_shouldPolyfillES6Collection.js
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* @generated SignedSource<<6c1a82d2f5918f03f3f0e5825e1f32f3>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2013-2014 Facebook, Inc.
|
||||
* @providesModule _shouldPolyfillES6Collection
|
||||
* @preventMunge
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
/**
|
||||
* Given a collection class name (Map or Set) return whether it's safe to use
|
||||
* the native polyfill.
|
||||
*
|
||||
* @param {string} collectionName
|
||||
*/
|
||||
function shouldPolyfillES6Collection(collectionName) {
|
||||
var Collection = global[collectionName];
|
||||
if (Collection == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var proto = Collection.prototype;
|
||||
|
||||
// These checks are adapted from es6-shim https://fburl.com/34437854
|
||||
return Collection == null ||
|
||||
typeof Collection !== 'function' ||
|
||||
typeof proto.clear !== 'function' ||
|
||||
new Collection().size !== 0 ||
|
||||
typeof proto.keys !== 'function' ||
|
||||
typeof proto.forEach !== 'function' ||
|
||||
isCallableWithoutNew(Collection) ||
|
||||
!supportsSubclassing(Collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a class can we subclass it?
|
||||
*
|
||||
* @param {function} Collection
|
||||
*/
|
||||
function supportsSubclassing(Collection) {
|
||||
class SubCollection extends Collection {}
|
||||
try {
|
||||
var s = (new SubCollection([]));
|
||||
// Firefox 32 will throw a type error when any operation is called on a
|
||||
// subclass.
|
||||
s.size;
|
||||
return s instanceof Collection;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a constructor can we call it without `new`?
|
||||
*
|
||||
* @param {function} Collection
|
||||
*/
|
||||
function isCallableWithoutNew(Collection) {
|
||||
try {
|
||||
Collection();
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
module.exports = shouldPolyfillES6Collection;
|
||||
36
Libraries/vendor/core/getObjectValues.js
vendored
Normal file
36
Libraries/vendor/core/getObjectValues.js
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @generated SignedSource<<d15b8e694c4a339791cddebd93264270>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* @providesModule getObjectValues
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
/**
|
||||
* Retrieve an object's values as an array.
|
||||
*
|
||||
* If you are looking for a function that creates an Array instance based
|
||||
* on an "Array-like" object, use createArrayFrom instead.
|
||||
*
|
||||
* @param {object} obj An object.
|
||||
* @return {array} The object's values.
|
||||
*/
|
||||
function getObjectValues(obj) {
|
||||
var values = [];
|
||||
for (var key in obj) {
|
||||
values.push(obj[key]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
module.exports = getObjectValues;
|
||||
31
Libraries/vendor/core/guid.js
vendored
Normal file
31
Libraries/vendor/core/guid.js
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @generated SignedSource<<4425c6f5a34b56ee4707e090f43fd075>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* Module that provides a function for creating a unique identifier.
|
||||
* The returned value does not conform to the GUID standard, but should
|
||||
* be globally unique in the context of the browser.
|
||||
*
|
||||
* @providesModule guid
|
||||
*
|
||||
*/
|
||||
|
||||
/*jshint bitwise: false*/
|
||||
|
||||
function guid() {
|
||||
return 'f' + (Math.random() * (1 << 30)).toString(16).replace('.', '');
|
||||
}
|
||||
|
||||
module.exports = guid;
|
||||
201
Libraries/vendor/core/immediate/setImmediate.js
vendored
Normal file
201
Libraries/vendor/core/immediate/setImmediate.js
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
* @generated SignedSource<<57d0446bbd1186485d372efe6b323dca>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright (c) 2012 Barnesandnoble.com, llc, Donavon West, and Domenic
|
||||
* Denicola
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* @preserve-header
|
||||
* @providesModule ImmediateImplementation
|
||||
*/
|
||||
|
||||
(function(global, undefined) {
|
||||
"use strict";
|
||||
|
||||
var nextHandle = 1; // Spec says greater than zero
|
||||
var tasksByHandle = {};
|
||||
var queueHead = {};
|
||||
var queueTail = queueHead;
|
||||
var currentlyRunningATask = false;
|
||||
var doc = global.document;
|
||||
var setImmediate;
|
||||
|
||||
function addFromSetImmediateArguments(args) {
|
||||
var handler = args[0];
|
||||
args = Array.prototype.slice.call(args, 1);
|
||||
tasksByHandle[nextHandle] = function() {
|
||||
handler.apply(undefined, args);
|
||||
};
|
||||
queueTail = (queueTail.next = { handle: nextHandle++ });
|
||||
return queueTail.handle;
|
||||
}
|
||||
|
||||
function flushQueue() {
|
||||
var next, task;
|
||||
while (!currentlyRunningATask && (next = queueHead.next)) {
|
||||
queueHead = next; // If this task fails, don't retry it.
|
||||
if ((task = tasksByHandle[next.handle])) {
|
||||
currentlyRunningATask = true;
|
||||
try {
|
||||
task();
|
||||
currentlyRunningATask = false;
|
||||
} finally {
|
||||
clearImmediate(next.handle);
|
||||
if (currentlyRunningATask) {
|
||||
currentlyRunningATask = false;
|
||||
// The call to task() must have thrown an
|
||||
// exception if we reach this point, so, just in
|
||||
// case there are tasks remaining to be executed,
|
||||
// we schedule another flushQueue in a later tick
|
||||
// of the event loop, and let the exception
|
||||
// propagate uncaught.
|
||||
if (queueHead.next) {
|
||||
setImmediate(flushQueue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function clearImmediate(handle) {
|
||||
delete tasksByHandle[handle];
|
||||
}
|
||||
|
||||
function canUsePostMessage() {
|
||||
// The test against `importScripts` prevents this implementation from being installed inside a web worker,
|
||||
// where `global.postMessage` means something completely different and can't be used for this purpose.
|
||||
if (global.postMessage && !global.importScripts) {
|
||||
var postMessageIsAsynchronous = true;
|
||||
|
||||
var onMessage = function() {
|
||||
postMessageIsAsynchronous = false;
|
||||
if (global.removeEventListener) {
|
||||
global.removeEventListener("message", onMessage, false);
|
||||
} else {
|
||||
global.detachEvent("onmessage", onMessage);
|
||||
}
|
||||
};
|
||||
|
||||
if (global.addEventListener) {
|
||||
global.addEventListener("message", onMessage, false);
|
||||
} else if (global.attachEvent) {
|
||||
global.attachEvent("onmessage", onMessage);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
global.postMessage("", "*");
|
||||
return postMessageIsAsynchronous;
|
||||
}
|
||||
}
|
||||
|
||||
function installPostMessageImplementation() {
|
||||
// Installs an event handler on `global` for the `message` event: see
|
||||
// * https://developer.mozilla.org/en/DOM/window.postMessage
|
||||
var messagePrefix = "setImmediate$" + Math.random() + "$";
|
||||
var onGlobalMessage = function(event) {
|
||||
if (event.source === global &&
|
||||
typeof event.data === "string" &&
|
||||
event.data.indexOf(messagePrefix) === 0) {
|
||||
flushQueue();
|
||||
}
|
||||
};
|
||||
|
||||
if (global.addEventListener) {
|
||||
global.addEventListener("message", onGlobalMessage, false);
|
||||
} else {
|
||||
global.attachEvent("onmessage", onGlobalMessage);
|
||||
}
|
||||
|
||||
setImmediate = function() {
|
||||
var handle = addFromSetImmediateArguments(arguments);
|
||||
global.postMessage(messagePrefix + handle, "*");
|
||||
return handle;
|
||||
};
|
||||
}
|
||||
|
||||
function installMessageChannelImplementation() {
|
||||
var channel = new MessageChannel();
|
||||
channel.port1.onmessage = flushQueue;
|
||||
setImmediate = function() {
|
||||
var handle = addFromSetImmediateArguments(arguments);
|
||||
channel.port2.postMessage(handle);
|
||||
return handle;
|
||||
};
|
||||
}
|
||||
|
||||
function installReadyStateChangeImplementation() {
|
||||
var html = doc.documentElement;
|
||||
setImmediate = function() {
|
||||
var handle = addFromSetImmediateArguments(arguments);
|
||||
// Create a <script> element; its readystatechange event will be fired asynchronously once it is inserted
|
||||
// into the document. Do so, thus queuing up the task. Remember to clean up once it's been called.
|
||||
var script = doc.createElement("script");
|
||||
script.onreadystatechange = function () {
|
||||
script.onreadystatechange = null;
|
||||
html.removeChild(script);
|
||||
script = null;
|
||||
flushQueue();
|
||||
};
|
||||
html.appendChild(script);
|
||||
return handle;
|
||||
};
|
||||
}
|
||||
|
||||
function installSetTimeoutImplementation() {
|
||||
setImmediate = function() {
|
||||
setTimeout(flushQueue, 0);
|
||||
return addFromSetImmediateArguments(arguments);
|
||||
};
|
||||
}
|
||||
|
||||
if (canUsePostMessage()) {
|
||||
// For non-IE10 modern browsers
|
||||
installPostMessageImplementation();
|
||||
|
||||
} else if (global.MessageChannel) {
|
||||
// For web workers, where supported
|
||||
installMessageChannelImplementation();
|
||||
|
||||
} else if (doc && "onreadystatechange" in doc.createElement("script")) {
|
||||
// For IE 6-8
|
||||
installReadyStateChangeImplementation();
|
||||
|
||||
} else {
|
||||
// For older browsers
|
||||
installSetTimeoutImplementation();
|
||||
}
|
||||
|
||||
exports.setImmediate = setImmediate;
|
||||
exports.clearImmediate = clearImmediate;
|
||||
}(/* jslint evil: true */ Function("return this")()));
|
||||
34
Libraries/vendor/core/isEmpty.js
vendored
Normal file
34
Libraries/vendor/core/isEmpty.js
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* @generated SignedSource<<97ffcebc9ae390e734026a4f3964bff6>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* @providesModule isEmpty
|
||||
*/
|
||||
|
||||
/**
|
||||
* Mimics empty from PHP.
|
||||
*/
|
||||
function isEmpty(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
return obj.length === 0;
|
||||
} else if (typeof obj === 'object') {
|
||||
for (var i in obj) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return !obj;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = isEmpty;
|
||||
19
Libraries/vendor/core/setImmediate.js
vendored
Normal file
19
Libraries/vendor/core/setImmediate.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @generated SignedSource<<9715e66cd259f4d1a1c3d39c97cd0b92>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* @providesModule setImmediate
|
||||
*/
|
||||
|
||||
module.exports = global.setImmediate ||
|
||||
require('ImmediateImplementation').setImmediate;
|
||||
38
Libraries/vendor/core/throwImmediate.js
vendored
Normal file
38
Libraries/vendor/core/throwImmediate.js
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @generated SignedSource<<5c985f16e4f2e576657ab2b1551adf97>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule throwImmediate
|
||||
* @typechecks
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var setImmediate = require('setImmediate');
|
||||
|
||||
function throwArg(error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws the supplied error in a new execution loop.
|
||||
*
|
||||
* @param {*} error
|
||||
*/
|
||||
function throwImmediate(error) {
|
||||
setImmediate(throwArg, error);
|
||||
}
|
||||
|
||||
module.exports = throwImmediate;
|
||||
180
Libraries/vendor/core/toIterator.js
vendored
Normal file
180
Libraries/vendor/core/toIterator.js
vendored
Normal file
@@ -0,0 +1,180 @@
|
||||
/**
|
||||
* @generated SignedSource<<32241616e13b8a54d1a7baadce8eae5d>>
|
||||
*
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
* !! This file is a check-in of a static_upstream project! !!
|
||||
* !! !!
|
||||
* !! You should not modify this file directly. Instead: !!
|
||||
* !! 1) Use `fjs use-upstream` to temporarily replace this with !!
|
||||
* !! the latest version from upstream. !!
|
||||
* !! 2) Make your changes, test them, etc. !!
|
||||
* !! 3) Use `fjs push-upstream` to copy your changes back to !!
|
||||
* !! static_upstream. !!
|
||||
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
*
|
||||
* Copyright 2004-present Facebook. All Rights Reserved.
|
||||
*
|
||||
* @providesModule toIterator
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Given an object `toIterator` will return the itrator for that object. If the
|
||||
* object has a `Symbol.iterator` method we just call that. Otherwise we
|
||||
* implement the ES6 `Array` and `String` Iterator.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var KIND_KEY = 'key';
|
||||
var KIND_VALUE = 'value';
|
||||
var KIND_KEY_VAL = 'key+value';
|
||||
/*global Symbol: true*/
|
||||
var ITERATOR_SYMBOL = (typeof Symbol === 'function')
|
||||
? Symbol.iterator
|
||||
: '@@iterator';
|
||||
|
||||
var toIterator = (function() {
|
||||
if (!(Array.prototype[ITERATOR_SYMBOL] &&
|
||||
String.prototype[ITERATOR_SYMBOL])) {
|
||||
// IIFE to avoid creating classes for no reason because of hoisting.
|
||||
return (function() {
|
||||
class ArrayIterator {
|
||||
// 22.1.5.1 CreateArrayIterator Abstract Operation
|
||||
constructor(array, kind) {
|
||||
if (!Array.isArray(array)) {
|
||||
throw new TypeError('Object is not an Array');
|
||||
}
|
||||
this._iteratedObject = array;
|
||||
this._kind = kind;
|
||||
this._nextIndex = 0;
|
||||
}
|
||||
|
||||
// 22.1.5.2.1 %ArrayIteratorPrototype%.next()
|
||||
next() {
|
||||
if (!this instanceof ArrayIterator) {
|
||||
throw new TypeError('Object is not an ArrayIterator');
|
||||
}
|
||||
|
||||
if (this._iteratedObject == null) {
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
|
||||
var array = this._iteratedObject;
|
||||
var len = this._iteratedObject.length;
|
||||
var index = this._nextIndex;
|
||||
var kind = this._kind;
|
||||
|
||||
if (index >= len) {
|
||||
this._iteratedObject = undefined;
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
|
||||
this._nextIndex = index + 1;
|
||||
|
||||
if (kind === KIND_KEY) {
|
||||
return createIterResultObject(index, false);
|
||||
} else if (kind === KIND_VALUE) {
|
||||
return createIterResultObject(array[index], false);
|
||||
} else if (kind === KIND_KEY_VAL) {
|
||||
return createIterResultObject([index, array[index]], false);
|
||||
}
|
||||
}
|
||||
|
||||
// 22.1.5.2.2 %ArrayIteratorPrototype%[@@iterator]()
|
||||
'@@iterator'() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
class StringIterator {
|
||||
// 21.1.5.1 CreateStringIterator Abstract Operation
|
||||
constructor(string) {
|
||||
if (typeof string !== 'string') {
|
||||
throw new TypeError('Object is not a string');
|
||||
}
|
||||
this._iteratedString = string;
|
||||
this._nextIndex = 0;
|
||||
}
|
||||
|
||||
// 21.1.5.2.1 %StringIteratorPrototype%.next()
|
||||
next() {
|
||||
if (!this instanceof StringIterator) {
|
||||
throw new TypeError('Object is not a StringIterator');
|
||||
}
|
||||
|
||||
if (this._iteratedString == null) {
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
|
||||
var index = this._nextIndex;
|
||||
var s = this._iteratedString;
|
||||
var len = s.length;
|
||||
|
||||
if (index >= len) {
|
||||
this._iteratedString = undefined;
|
||||
return createIterResultObject(undefined, true);
|
||||
}
|
||||
|
||||
var ret;
|
||||
var first = s.charCodeAt(index);
|
||||
|
||||
if (first < 0xD800 || first > 0xDBFF || index + 1 === len) {
|
||||
ret = s[index];
|
||||
} else {
|
||||
var second = s.charCodeAt(index + 1);
|
||||
if (second < 0xDC00 || second > 0xDFFF) {
|
||||
ret = s[index];
|
||||
} else {
|
||||
ret = s[index] + s[index + 1];
|
||||
}
|
||||
}
|
||||
|
||||
this._nextIndex = index + ret.length;
|
||||
|
||||
return createIterResultObject(ret, false);
|
||||
}
|
||||
|
||||
// 21.1.5.2.2 %StringIteratorPrototype%[@@ITERATOR_SYMBOL]()
|
||||
'@@iterator'() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
// 7.4.7 createIterResultObject(value, done)
|
||||
function createIterResultObject(value, done) {
|
||||
return {value: value, done: done};
|
||||
}
|
||||
|
||||
return function(object, kind) {
|
||||
if (typeof object === 'string') {
|
||||
return new StringIterator(object);
|
||||
} else if (Array.isArray(object)) {
|
||||
return new ArrayIterator(object, kind || KIND_VALUE);
|
||||
} else {
|
||||
return object[ITERATOR_SYMBOL]();
|
||||
}
|
||||
};
|
||||
})();
|
||||
} else {
|
||||
return function(object) {
|
||||
return object[ITERATOR_SYMBOL]();
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Export constants
|
||||
*/
|
||||
|
||||
Object.assign(toIterator, {
|
||||
KIND_KEY,
|
||||
KIND_VALUE,
|
||||
KIND_KEY_VAL,
|
||||
ITERATOR_SYMBOL
|
||||
});
|
||||
|
||||
module.exports = toIterator;
|
||||
Reference in New Issue
Block a user