diff --git a/perf/perf.js b/perf/perf.js index f4d817274..b5fd95ca3 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -48,6 +48,15 @@ /** Used to access the Firebug Lite panel (set by `run`) */ var fbPanel; + /** Used to match path separators */ + var rePathSeparator = /[\/\\]/; + + /** Used to detect primitive types */ + var rePrimitive = /^(?:boolean|number|string|undefined)$/; + + /** Used to match RegExp special characters */ + var reSpecialChars = /[.*+?^=!:${}()|[\]\/\\]/g; + /** Used to score performance */ var score = { 'a': 0, 'b': 0 }; @@ -70,7 +79,7 @@ var otherName = basename(ui.otherPath, '.js'); /** Detect if in a browser environment */ - var isBrowser = !!(window.document && window.navigator); + var isBrowser = isHostType(window, 'document') && isHostType(window, 'navigator'); /** Detect Java environment */ var isJava = !isBrowser && /Java/.test(toString.call(window.java)); @@ -90,10 +99,10 @@ * @returns {String} Returns the basename. */ function basename(filePath, extension) { - var result = (filePath || '').split(/[\\/]/).pop(); - return arguments.length < 2 + var result = (filePath || '').split(rePathSeparator).pop(); + return (arguments.length < 2) ? result - : result.replace(RegExp(extension.replace(/[.*+?^=!:${}()|[\]\/\\]/g, '\\$&') + '$'), ''); + : result.replace(RegExp(extension.replace(reSpecialChars, '\\$&') + '$'), ''); } /** @@ -109,6 +118,24 @@ return isFinite(result) ? result : 0; } + /** + * Host objects can return type values that are different from their actual + * data type. The objects we are concerned with usually return non-primitive + * types of "object", "function", or "unknown". + * + * @private + * @param {Mixed} object The owner of the property. + * @param {String} property The property to check. + * @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`. + */ + function isHostType(object, property) { + if (object == null) { + return false; + } + var type = typeof object[property]; + return !rePrimitive.test(type) && (type != 'object' || !!object[property]); + } + /** * Logs text to the console. * @@ -494,17 +521,19 @@ ); // avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo - !isJava && suites.push( - Benchmark.Suite('`_(...).tap(...)`') - .add(buildName, { - 'fn': 'lodashChaining.tap(lodash.identity)', - 'teardown': 'function chaining(){}' - }) - .add(otherName, { - 'fn': '_chaining.tap(_.identity)', - 'teardown': 'function chaining(){}' - }) - ); + if (!isJava) { + suites.push( + Benchmark.Suite('`_(...).tap(...)`') + .add(buildName, { + 'fn': 'lodashChaining.tap(lodash.identity)', + 'teardown': 'function chaining(){}' + }) + .add(otherName, { + 'fn': '_chaining.tap(_.identity)', + 'teardown': 'function chaining(){}' + }) + ); + } /*--------------------------------------------------------------------------*/ @@ -893,17 +922,19 @@ ); // avoid Underscore induced `OutOfMemoryError` in Rhino, Narwhal, and Ringo - !isJava && suites.push( - Benchmark.Suite('`_.find` with `properties`') - .add(buildName, { - 'fn': 'lodash.find(objects, whereObject)', - 'teardown': 'function where(){}' - }) - .add(otherName, { - 'fn': '_.findWhere(objects, whereObject)', - 'teardown': 'function where(){}' - }) - ); + if (!isJava) { + suites.push( + Benchmark.Suite('`_.find` with `properties`') + .add(buildName, { + 'fn': 'lodash.find(objects, whereObject)', + 'teardown': 'function where(){}' + }) + .add(otherName, { + 'fn': '_.findWhere(objects, whereObject)', + 'teardown': 'function where(){}' + }) + ); + } /*--------------------------------------------------------------------------*/ diff --git a/vendor/benchmark.js/benchmark.js b/vendor/benchmark.js/benchmark.js index bdb33e607..e37c86069 100644 --- a/vendor/benchmark.js/benchmark.js +++ b/vendor/benchmark.js/benchmark.js @@ -30,6 +30,9 @@ /** Used to assign each benchmark an incrimented id */ var counter = 0; + /** Used to detect primitive types */ + var rePrimitive = /^(?:boolean|number|string|undefined)$/; + /** Used to assign default `context` object properties */ var contextProps = [ 'Array', 'Date', 'Function', 'Math', 'Object', 'RegExp', 'String', '_', @@ -613,7 +616,7 @@ /** * Host objects can return type values that are different from their actual * data type. The objects we are concerned with usually return non-primitive - * types of object, function, or unknown. + * types of "object", "function", or "unknown". * * @private * @param {Mixed} object The owner of the property. @@ -621,9 +624,11 @@ * @returns {Boolean} Returns `true` if the property value is a non-primitive, else `false`. */ function isHostType(object, property) { - var type = object != null ? typeof object[property] : 'number'; - return !/^(?:boolean|number|string|undefined)$/.test(type) && - (type == 'object' ? !!object[property] : true); + if (object == null) { + return false; + } + var type = typeof object[property]; + return !rePrimitive.test(type) && (type != 'object' || !!object[property]); } /** diff --git a/vendor/platform.js/platform.js b/vendor/platform.js/platform.js index 696e01233..30ce3e1c3 100644 --- a/vendor/platform.js/platform.js +++ b/vendor/platform.js/platform.js @@ -20,7 +20,7 @@ var reOpera = /Opera/; /** Used to resolve a value's internal [[Class]] */ - var toString = {}.toString; + var toString = Object.prototype.toString; /** Detect Java environment */ var java = /Java/.test(getClassOf(window.java)) && window.java;