;(function() { /** Used as a safe reference for `undefined` in pre ES5 environments */ var undefined; /** Used to detect when a function becomes hot */ var HOT_COUNT = 150; /** Used as the size to cover large array optimizations */ var LARGE_ARRAY_SIZE = 200; /** Used as the maximum length an array-like object */ var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; /** Used as a reference to the global object */ var root = (typeof global == 'object' && global) || this; /** Used to store Lo-Dash to test for bad extensions/shims */ var lodashBizarro = root.lodashBizarro; /** Used for native method references */ var arrayProto = Array.prototype, errorProto = Error.prototype, funcProto = Function.prototype, objectProto = Object.prototype, stringProto = String.prototype; /** Method and object shortcuts */ var phantom = root.phantom, amd = root.define && define.amd, argv = root.process && process.argv, ArrayBuffer = root.ArrayBuffer, document = !phantom && root.document, body = root.document && root.document.body, create = Object.create, freeze = Object.freeze, JSON = root.JSON, noop = function() {}, params = root.arguments, push = arrayProto.push, slice = arrayProto.slice, system = root.system, toString = objectProto.toString, Uint8Array = root.Uint8Array; /** The file path of the Lo-Dash file to test */ var filePath = (function() { var min = 0, result = []; if (phantom) { result = params = phantom.args; } else if (system) { min = 1; result = params = system.args; } else if (argv) { min = 2; result = params = argv; } else if (params) { result = params; } var last = result[result.length - 1]; result = (result.length > min && !/test(?:\.js)?$/.test(last)) ? last : '../lodash.js'; if (!amd) { try { result = require('fs').realpathSync(result); } catch(e) {} try { result = require.resolve(result); } catch(e) {} } return result; }()); /** The `ui` object */ var ui = root.ui || (root.ui = { 'buildPath': filePath, 'loaderPath': '', 'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm|transpiled)\b/.test(filePath), 'isStrict': /\b(?:lodash-es6|transpiled)\b/.test(filePath), 'urlParams': {} }); /** The basename of the Lo-Dash file to test */ var basename = /[\w.-]+$/.exec(filePath)[0]; /** Detect if in a Java environment */ var isJava = !document && !!root.java; /** Used to indicate testing a modularized build */ var isModularize = ui.isModularize; /** Detect if testing `npm` modules */ var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]); /** Detect if running in PhantomJS */ var isPhantom = phantom || typeof callPhantom == 'function'; /** Detect if running in Rhino */ var isRhino = isJava && typeof global == 'function' && global().Array === root.Array; /** Detect if Lo-Dash is in strict mode */ var isStrict = ui.isStrict; /** Used to test Web Workers */ var Worker = !(ui.isForeign || ui.isSauceLabs || isModularize) && document && root.Worker; /** Used to test host objects in IE */ try { var xml = new ActiveXObject('Microsoft.XMLDOM'); } catch(e) {} /** Use a single "load" function */ var load = (typeof require == 'function' && !amd) ? require : (isJava && root.load) || noop; /** The unit testing framework */ var QUnit = (function() { return root.QUnit || ( root.addEventListener || (root.addEventListener = noop), root.setTimeout || (root.setTimeout = noop), root.QUnit = load('../vendor/qunit/qunit/qunit.js') || root.QUnit, addEventListener === noop && delete root.addEventListener, root.QUnit ); }()); /** Load and install QUnit Extras and ES6 Set/WeakMap shims */ (function() { var paths = [ './asset/set.js', './asset/weakmap.js', '../vendor/qunit-extras/qunit-extras.js' ]; var index = -1, length = paths.length; while (++index < length) { var object = load(paths[index]); if (object) { object.runInContext(root); } } }()); /*--------------------------------------------------------------------------*/ // log params provided to `test.js` if (params) { console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params))); } // exit early if going to run tests in a PhantomJS web page if (phantom && isModularize) { var page = require('webpage').create(); page.open(filePath, function(status) { if (status != 'success') { console.log('PhantomJS failed to load page: ' + filePath); phantom.exit(1); } }); page.onCallback = function(details) { var coverage = details.coverage; if (coverage) { var fs = require('fs'), cwd = fs.workingDirectory, sep = fs.separator; fs.write([cwd, 'coverage', 'coverage.json'].join(sep), JSON.stringify(coverage)); } phantom.exit(details.failed ? 1 : 0); }; page.onConsoleMessage = function(message) { console.log(message); }; page.onInitialized = function() { page.evaluate(function() { document.addEventListener('DOMContentLoaded', function() { QUnit.done(function(details) { details.coverage = window.__coverage__; callPhantom(details); }); }); }); }; return; } /*--------------------------------------------------------------------------*/ /** The `lodash` function to test */ var _ = root._ || (root._ = ( _ = load(filePath) || root._, _ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _, (_.runInContext ? _.runInContext(root) : _) )); /** Used as the property name for wrapper metadata */ var EXPANDO = '__lodash_' + _.VERSION.replace(/[-.]/g, '_') + '__'; /** Used to provide falsey values to methods */ var falsey = [, '', 0, false, NaN, null, undefined]; /** Used to provide empty values to methods */ var empties = [[], {}].concat(falsey.slice(1)); /** Used to test error objects */ var errors = [ new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError ]; /** Used to set property descriptors */ var defineProperty = (function() { try { var o = {}, func = Object.defineProperty, result = func(o, o, o) && func; } catch(e) {} return result; }()); /** Used to check problem JScript properties (a.k.a. the `[[DontEnum]]` bug) */ var shadowedProps = [ 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf' ]; /** Used to check problem JScript properties too */ var shadowedObject = _.invert(shadowedProps); /** Used to check whether methods support typed arrays */ var typedArrays = [ 'Float32Array', 'Float64Array', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array' ]; /** Used to check for problems removing whitespace */ var whitespace = ' \t\x0B\f\xA0\ufeff\n\r\u2028\u2029\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000'; /** * Removes all own enumerable properties from a given object. * * @private * @param {Object} object The object to empty. */ function emptyObject(object) { _.forOwn(object, function(value, key, object) { delete object[key]; }); } /** * Sets a non-enumerable property value on `object`. * * Note: This function is used to avoid a bug in older versions of V8 where * overwriting non-enumerable built-ins makes them enumerable. * See https://code.google.com/p/v8/issues/detail?id=1623 * * @private * @param {Object} object The object augment. * @param {string} key The name of the property to set. * @param {*} value The property value. */ function setProperty(object, key, value) { try { defineProperty(object, key, { 'configurable': true, 'enumerable': false, 'writable': true, 'value': value }); } catch(e) { object[key] = value; } } /** * Skips a given number of tests with a passing result. * * @private * @param {number} [count=1] The number of tests to skip. */ function skipTest(count) { count || (count = 1); while (count--) { ok(true, 'test skipped'); } } /*--------------------------------------------------------------------------*/ // setup values for Node.js (function() { if (amd) { return; } try { // add values from a different realm _.extend(_, require('vm').runInNewContext([ '({', "'_arguments': (function() { return arguments; }(1, 2, 3)),", "'_array': [1, 2, 3],", "'_boolean': Object(false),", "'_date': new Date,", "'_errors': [new Error, new EvalError, new RangeError, new ReferenceError, new SyntaxError, new TypeError, new URIError],", "'_function': function() {},", "'_nan': NaN,", "'_null': null,", "'_number': Object(0),", "'_object': { 'a': 1, 'b': 2, 'c': 3 },", "'_regexp': /x/,", "'_string': Object('a'),", "'_undefined': undefined", '})' ].join('\n'))); } catch(e) { if (!phantom) { return; } } var fnToString = funcProto.toString, nativeString = fnToString.call(toString), reToString = /toString/g; function createToString(funcName) { return _.constant(nativeString.replace(reToString, funcName)); } // expose `baseEach` for better code coverage if (isModularize && !isNpm) { var path = require('path'), baseEach = require(path.join(path.dirname(filePath), 'internal', 'baseEach.js')); _._baseEach = baseEach.baseEach || baseEach['default'] || baseEach; } // allow bypassing native checks setProperty(funcProto, 'toString', function wrapper() { setProperty(funcProto, 'toString', fnToString); var result = _.has(this, 'toString') ? this.toString() : fnToString.call(this); setProperty(funcProto, 'toString', wrapper); return result; }); // add extensions funcProto._method = _.noop; // set bad shims var _isArray = Array.isArray; setProperty(Array, 'isArray', _.noop); var _now = Date.now; setProperty(Date, 'now', _.noop); var _create = create; setProperty(Object, 'create', _.noop); var _getPrototypeOf = Object.getPrototypeOf; setProperty(Object, 'getPrototypeOf', _.noop); var _keys = Object.keys; setProperty(Object, 'keys', _.noop); var _propertyIsEnumerable = objectProto.propertyIsEnumerable; setProperty(objectProto, 'propertyIsEnumerable', function(key) { if (key == '1' && _.isArguments(this) && _.isEqual(_.values(this), [0, 0])) { throw new Error; } return _.has(this, key); }); var _isFinite = Number.isFinite; setProperty(Number, 'isFinite', _.noop); var _contains = stringProto.contains; setProperty(stringProto, 'contains', _contains ? _.noop : Boolean); var _ArrayBuffer = ArrayBuffer; setProperty(root, 'ArrayBuffer', (function() { function ArrayBuffer(byteLength) { var buffer = new _ArrayBuffer(byteLength); if (!byteLength) { setProperty(buffer, 'slice', buffer.slice ? null : bufferSlice); } return buffer; } function bufferSlice() { var newBuffer = new _ArrayBuffer(this.byteLength), view = new Uint8Array(newBuffer); view.set(new Uint8Array(this)); return newBuffer; } setProperty(ArrayBuffer, 'toString', createToString('ArrayBuffer')); setProperty(bufferSlice, 'toString', createToString('slice')); return ArrayBuffer; }())); if (!root.Float64Array) { setProperty(root, 'Float64Array', (function() { function Float64Array(buffer, byteOffset, length) { return arguments.length == 1 ? new Uint8Array(buffer) : new Uint8Array(buffer, byteOffset || 0, length || buffer.byteLength); } setProperty(Float64Array, 'BYTES_PER_ELEMENT', 8); setProperty(Float64Array, 'toString', createToString('Float64Array')); return Float64Array; }())); } var _parseInt = parseInt; setProperty(root, 'parseInt', (function() { var checkStr = whitespace + '08', isFaked = _parseInt(checkStr) != 8, reHexPrefix = /^0[xX]/, reTrim = RegExp('^[' + whitespace + ']+|[' + whitespace + ']+$'); return function(value, radix) { if (value == checkStr && !isFaked) { isFaked = true; return 0; } value = String(value == null ? '' : value).replace(reTrim, ''); return _parseInt(value, +radix || (reHexPrefix.test(value) ? 16 : 10)); }; }())); var _Set = root.Set; setProperty(root, 'Set', _.noop); var _WeakMap = root.WeakMap; setProperty(root, 'WeakMap', _.noop); // fake DOM setProperty(root, 'window', {}); setProperty(root.window, 'document', {}); setProperty(root.window.document, 'createDocumentFragment', function() { return { 'nodeType': 11 }; }); // fake `WinRTError` setProperty(root, 'WinRTError', Error); // clear cache so Lo-Dash can be reloaded emptyObject(require.cache); // load Lo-Dash and expose it to the bad extensions/shims lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro; lodashBizarro.support.funcNames = !lodashBizarro.support.funcNames; // restore native methods setProperty(Array, 'isArray', _isArray); setProperty(Date, 'now', _now); setProperty(Object, 'create', _create); setProperty(Object, 'getPrototypeOf', _getPrototypeOf); setProperty(Object, 'keys', _keys); setProperty(objectProto, 'propertyIsEnumerable', _propertyIsEnumerable); setProperty(root, 'parseInt', _parseInt); if (_isFinite) { setProperty(Number, 'isFinite', _isFinite); } else { delete Number.isFinite; } if (_contains) { setProperty(stringProto, 'contains', _contains); } else { delete stringProto.contains; } if (_ArrayBuffer) { setProperty(root, 'ArrayBuffer', _ArrayBuffer); } else { delete root.ArrayBuffer; } if (_Set) { setProperty(root, 'Set', Set); } else { delete root.Set; } if (_WeakMap) { setProperty(root, 'WeakMap', WeakMap); } else { delete root.WeakMap; } delete root.WinRTError; delete root.window; delete funcProto._method; }()); // add values from an iframe (function() { if (_._object || !document) { return; } var iframe = document.createElement('iframe'); iframe.frameBorder = iframe.height = iframe.width = 0; body.appendChild(iframe); var idoc = (idoc = iframe.contentDocument || iframe.contentWindow).document || idoc; idoc.write([ '