From b91b04f6528832262f0a5ab0cd6310e2f4a8cd06 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 19 Sep 2012 21:40:39 -0700 Subject: [PATCH] Update vendors and add `_.reduce`, `_.reduceRight`, and `_.where` benchmarks. Former-commit-id: c1b4bc7f8aaf08c429ae918f5d528401f1a66255 --- perf/perf.js | 80 +++++++++++++++++++++++++++ vendor/underscore/test/collections.js | 33 +++++++++++ vendor/underscore/test/objects.js | 4 ++ vendor/underscore/underscore-min.js | 52 ++++++++--------- vendor/underscore/underscore.js | 26 ++++++--- 5 files changed, 160 insertions(+), 35 deletions(-) diff --git a/perf/perf.js b/perf/perf.js index 38e547de0..51e8ea1d0 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -1152,6 +1152,74 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.reduce` iterating an array') + .add('Lo-Dash', '\ + lodash.reduce(numbers, function(result, value, index) {\ + result[index] = value;\ + return result;\ + }, {});' + ) + .add('Underscore', '\ + _.reduce(numbers, function(result, value, index) {\ + result[index] = value;\ + return result;\ + }, {});' + ) + ); + + suites.push( + Benchmark.Suite('`_.reduce` iterating an object') + .add('Lo-Dash', '\ + lodash.reduce(object, function(result, value, key) {\ + result.push([key, value]);\ + return result;\ + }, []);' + ) + .add('Underscore', '\ + _.reduce(object, function(result, value, key) {\ + result.push([key, value]);\ + return result;\ + }, []);' + ) + ); + + /*--------------------------------------------------------------------------*/ + + suites.push( + Benchmark.Suite('`_.reduceRight` iterating an array') + .add('Lo-Dash', '\ + lodash.reduceRight(numbers, function(result, value, index) {\ + result[index] = value;\ + return result;\ + }, {});' + ) + .add('Underscore', '\ + _.reduceRight(numbers, function(result, value, index) {\ + result[index] = value;\ + return result;\ + }, {});' + ) + ); + + suites.push( + Benchmark.Suite('`_.reduceRight` iterating an object') + .add('Lo-Dash', '\ + lodash.reduceRight(object, function(result, value, key) {\ + result.push([key, value]);\ + return result;\ + }, []);' + ) + .add('Underscore', '\ + _.reduceRight(object, function(result, value, key) {\ + result.push([key, value]);\ + return result;\ + }, []);' + ) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.shuffle`') .add('Lo-Dash', '\ @@ -1412,6 +1480,18 @@ /*--------------------------------------------------------------------------*/ + suites.push( + Benchmark.Suite('`_.where`') + .add('Lo-Dash', '\ + lodash.where(objects, { "num": 9 });' + ) + .add('Underscore', '\ + _.where(objects, { "num": 9 });' + ) + ); + + /*--------------------------------------------------------------------------*/ + suites.push( Benchmark.Suite('`_.without`') .add('Lo-Dash', '\ diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index 60ad7e9e6..a5c7d7d55 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -111,6 +111,39 @@ $(document).ready(function() { equal(_.reduceRight([], function(){}, undefined), undefined, 'undefined can be passed as a special case'); raises(function() { _.reduceRight([], function(){}); }, TypeError, 'throws an error for empty arrays with no initial value'); + + // Assert that the correct arguments are being passed. + + var args, + memo = {}, + object = {a: 1, b: 2}, + lastKey = _.keys(object).pop(); + + var expected = lastKey == 'a' + ? [memo, 1, 'a', object] + : [memo, 2, 'b', object]; + + _.reduceRight(object, function() { + args || (args = _.toArray(arguments)); + }, memo); + + deepEqual(args, expected); + + // And again, with numeric keys. + + object = {'2': 'a', '1': 'b'}; + lastKey = _.keys(object).pop(); + args = null; + + expected = lastKey == '2' + ? [memo, 'a', '2', object] + : [memo, 'b', '1', object]; + + _.reduceRight(object, function() { + args || (args = _.toArray(arguments)); + }, memo); + + deepEqual(args, expected); }); test('find', function() { diff --git a/vendor/underscore/test/objects.js b/vendor/underscore/test/objects.js index 187c69d13..236a9d955 100644 --- a/vendor/underscore/test/objects.js +++ b/vendor/underscore/test/objects.js @@ -342,6 +342,9 @@ $(document).ready(function() { ok(_.isEqual(isEqualObjClone, isEqualObj), 'Commutative equality is implemented for objects with custom `isEqual` methods'); ok(!_.isEqual(isEqualObj, {}), 'Objects that do not implement equivalent `isEqual` methods are not equal'); ok(!_.isEqual({}, isEqualObj), 'Commutative equality is implemented for objects with different `isEqual` methods'); + + // Objects from another frame. + ok(_.isEqual({}, iObject)); }); test("isEmpty", function() { @@ -378,6 +381,7 @@ $(document).ready(function() { parent.iNull = null;\ parent.iBoolean = new Boolean(false);\ parent.iUndefined = undefined;\ + parent.iObject = {};\ " ); iDoc.close(); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index a499cf046..ab6a0fcf7 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -5,29 +5,29 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var r=this,J=r._,n={},k=Array.prototype,o=Object.prototype,s=k.push,g=k.slice,p=k.concat,l=o.toString,K=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,q=k.indexOf,D=k.lastIndexOf,o=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= -b):r._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,h=a.length;e2;a==null&&(a= -[]);if(y&&a.reduce===y){e&&(c=b.bind(c,e));return h?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,M){if(h)d=c.call(e,d,a,b,M);else{d=a;h=true}});if(!h)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var h=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z){e&&(c=b.bind(c,e));return h?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!h&&(c=b.bind(c,e));return h?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= -function(a,c,b){var e;E(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,d);j(a,function(a, -b,i){if(!(e=e&&c.call(d,a,b,i)))return n});return!!e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=g.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, -d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.where=function(a,c){return b.isEmpty(c)?[]:b.filter(a,function(a){for(var b in c)if(c[b]!==a[b])return false;return true})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&& -a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;bd||b===void 0)return 1;if(b>1;d(a[f])=0})})};b.difference=function(a){var c=p.apply(k,g.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=g.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c= -[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(g.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={},d=p.apply(k,g.call(arguments,1));j(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=p.apply(k,g.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(g.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)? -a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var h=l.call(a);if(h!=l.call(c))return false;switch(h){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&& -a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(h=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var g in a)if(b.has(a,g)){f++;if(!(i=b.has(c,g)&&u(a[g],c[g],d,e)))break}if(i){for(g in c)if(b.has(c,g)&&!f--)break;i=!f}}d.pop(); -e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}}); -b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return K.call(a,b)};b.noConflict=function(){r._=J;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e= -0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var N={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(N[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null; -var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=[this._wrapped];s.apply(a,arguments);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var O=0;b.uniqueId=function(a){var b=O++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/(.)^/,P={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},Q=/\\|'|\r|\n|\t|\u2028|\u2029/g; -b.template=function(a,c,d){var d=b.defaults({},d,b.templateSettings),e=RegExp([(d.escape||v).source,(d.interpolate||v).source,(d.evaluate||v).source].join("|")+"|$","g"),h=0,f="__p+='";a.replace(e,function(b,c,d,e,g){f=f+a.slice(h,g).replace(Q,function(a){return"\\"+P[a]});f=f+(c?"'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'":d?"'+\n((__t=("+d+"))==null?'':__t)+\n'":e?"';\n"+e+"\n__p+='":"");h=g+b.length});f=f+"';\n";d.variable||(f="with(obj||{}){\n"+f+"}\n");f="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+ -f+"return __p;\n";try{var g=new Function(d.variable||"obj","_",f)}catch(j){j.source=f;throw j;}if(c)return g(c,b);c=function(a){return g.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+f+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain(): -d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); +(function(){var r=this,J=r._,n={},k=Array.prototype,o=Object.prototype,s=k.push,h=k.slice,p=k.concat,l=o.toString,K=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,q=k.indexOf,D=k.lastIndexOf,o=Array.isArray,L=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= +b):r._=b;b.VERSION="1.3.3";var i=b.each=b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,g=a.length;e2;a==null&& +(a=[]);if(!g&&y&&a.reduce===y){e&&(c=b.bind(c,e));return f?a.reduce(c,d):a.reduce(c)}i(a,function(a,b,h){if(g){b=g.keys[b];h=g.list}if(f)d=c.call(e,d,a,b,h);else{d=a;f=true}});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){a==null&&(a=[]);if(z&&a.reduceRight===z){e&&(c=b.bind(c,e));return arguments.length>2?a.reduceRight(c,d):a.reduceRight(c)}var g=b.keys(a).reverse(),f=b.toArray(a).reverse();return b.reduce(f,c,d,e,{keys:g, +list:a})};b.find=b.detect=function(a,c,b){var e;E(a,function(a,f,j){if(c.call(b,a,f,j)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);i(a,function(a,f,j){c.call(b,a,f,j)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;i(a,function(a,f,j){c.call(b,a,f,j)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c, +d);i(a,function(a,b,j){if(!(e=e&&c.call(d,a,b,j)))return n});return!!e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);i(a,function(a,b,j){if(e||(e=c.call(d,a,b,j)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(q&&a.indexOf===q)return a.indexOf(c)!=-1;return b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)? +c:a[c]).apply(a,d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.where=function(a,c){return b.isEmpty(c)?[]:b.filter(a,function(a){for(var b in c)if(c[b]!==a[b])return false;return true})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};i(a,function(a,b,j){b=c?c.call(d,a,b,j):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&& +b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};i(a,function(a,b,j){b=c?c.call(d,a,b,j):a;bd||b===void 0)return 1;if(b>1;d(a[f])=0})})};b.difference=function(a){var c=p.apply(k,h.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=L||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods= +function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){i(h.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.pick=function(a){var b={},d=p.apply(k,h.call(arguments,1));i(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=p.apply(k,h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){i(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a}; +b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== +c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,j=true;if(g=="[object Array]"){f=a.length;if(j=f==c.length)for(;f--;)if(!(j=u(a[f],c[f],d,e)))break}else{var g=a.constructor,h=c.constructor;if(g!==h&&(!b.isFunction(g)||!(g instanceof g&&b.isFunction(h)&&h instanceof h)))return false;for(var i in a)if(b.has(a,i)){f++;if(!(j=b.has(c,i)&& +u(a[i],c[i],d,e)))break}if(j){for(i in c)if(b.has(c,i)&&!f--)break;j=!f}}d.pop();e.pop();return j};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};i("Arguments,Function,String,Number,Date,RegExp".split(","), +function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&&isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return K.call(a,b)};b.noConflict=function(){r._=J; +return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">",'"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var M={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+ +b).replace(M[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){i(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a=[this._wrapped];s.apply(a,arguments);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var N=0;b.uniqueId=function(a){var b=N++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/(.)^/, +O={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},P=/\\|'|\r|\n|\t|\u2028|\u2029/g;b.template=function(a,c,d){var d=b.defaults({},d,b.templateSettings),e=RegExp([(d.escape||v).source,(d.interpolate||v).source,(d.evaluate||v).source].join("|")+"|$","g"),g=0,f="__p+='";a.replace(e,function(b,c,d,e,h){f=f+a.slice(g,h).replace(P,function(a){return"\\"+O[a]});f=f+(c?"'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'":d?"'+\n((__t=("+d+"))==null?'':__t)+\n'":e?"';\n"+e+"\n__p+='": +"");g=h+b.length});f=f+"';\n";d.variable||(f="with(obj||{}){\n"+f+"}\n");f="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+f+"return __p;\n";try{var h=new Function(d.variable||"obj","_",f)}catch(i){i.source=f;throw i;}if(c)return h(c,b);c=function(a){return h.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+f+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);i("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c= +k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain():d}});i(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index ede5757fe..b4521f5d5 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -107,14 +107,18 @@ // **Reduce** builds up a single result from a list of values, aka `inject`, // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. - _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { + _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context, right) { var initial = arguments.length > 2; if (obj == null) obj = []; - if (nativeReduce && obj.reduce === nativeReduce) { + if (!right && nativeReduce && obj.reduce === nativeReduce) { if (context) iterator = _.bind(iterator, context); return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); } each(obj, function(value, index, list) { + if (right) { + index = right.keys[index]; + list = right.list; + } if (!initial) { memo = value; initial = true; @@ -129,15 +133,14 @@ // The right-associative version of reduce, also known as `foldr`. // Delegates to **ECMAScript 5**'s native `reduceRight` if available. _.reduceRight = _.foldr = function(obj, iterator, memo, context) { - var initial = arguments.length > 2; if (obj == null) obj = []; if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); + return arguments.length > 2 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); } - var reversed = _.toArray(obj).reverse(); - if (context && !initial) iterator = _.bind(iterator, context); - return initial ? _.reduce(reversed, iterator, memo, context) : _.reduce(reversed, iterator); + var keys = _.keys(obj).reverse(); + var values = _.toArray(obj).reverse(); + return _.reduce(values, iterator, memo, context, {keys: keys, list: obj}); }; // Return the first value which passes a truth test. Aliased as `detect`. @@ -848,8 +851,13 @@ } } } else { - // Objects with different constructors are not equivalent. - if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; + // Objects with different constructors are not equivalent, but `Object`s + // from different frames are. + var aCtor = a.constructor, bCtor = b.constructor; + if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) && + _.isFunction(bCtor) && (bCtor instanceof bCtor))) { + return false; + } // Deep compare objects. for (var key in a) { if (_.has(a, key)) {