Backed out commit [6260], was causing too many problems. We'll have to bite the bullet and assume that the incoming result set has array methods. Un-fixes jQuery bug #4250.

This commit is contained in:
John Resig 2009-03-17 20:39:29 +00:00
parent 2d4755a0fb
commit 26731d475b
2 changed files with 17 additions and 15 deletions

View file

@ -292,9 +292,14 @@ jQuery.fn = jQuery.prototype = {
return this.prevObject || jQuery(null); return this.prevObject || jQuery(null);
}, },
// For internal use only.
// Behaves like an Array's method, not like a jQuery method.
push: [].push,
sort: [].sort,
splice: [].splice,
find: function( selector ) { find: function( selector ) {
var ret = this.pushStack( "", "find", selector ), length = 0, var ret = this.pushStack( "", "find", selector ), length = 0;
splice = Array.prototype.splice;
for ( var i = 0, l = this.length; i < l; i++ ) { for ( var i = 0, l = this.length; i < l; i++ ) {
length = ret.length; length = ret.length;
@ -305,7 +310,7 @@ jQuery.fn = jQuery.prototype = {
for ( var n = length; n < ret.length; n++ ) { for ( var n = length; n < ret.length; n++ ) {
for ( var r = 0; r < length; r++ ) { for ( var r = 0; r < length; r++ ) {
if ( ret[r] === ret[n] ) { if ( ret[r] === ret[n] ) {
splice.call(ret, n--, 1); ret.splice(n--, 1);
break; break;
} }
} }

View file

@ -8,10 +8,7 @@
var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g, var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,
done = 0, done = 0,
toString = Object.prototype.toString, toString = Object.prototype.toString;
arraySplice = Array.prototype.splice,
arrayPush = Array.prototype.push,
arraySort = Array.prototype.sort;
var Sizzle = function(selector, context, results, seed) { var Sizzle = function(selector, context, results, seed) {
results = results || []; results = results || [];
@ -107,17 +104,17 @@ var Sizzle = function(selector, context, results, seed) {
if ( toString.call(checkSet) === "[object Array]" ) { if ( toString.call(checkSet) === "[object Array]" ) {
if ( !prune ) { if ( !prune ) {
arrayPush.apply( results, checkSet ); results.push.apply( results, checkSet );
} else if ( context && context.nodeType === 1 ) { } else if ( context && context.nodeType === 1 ) {
for ( var i = 0; checkSet[i] != null; i++ ) { for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) { if ( checkSet[i] && (checkSet[i] === true || checkSet[i].nodeType === 1 && contains(context, checkSet[i])) ) {
arrayPush.call( results, set[i] ); results.push( set[i] );
} }
} }
} else { } else {
for ( var i = 0; checkSet[i] != null; i++ ) { for ( var i = 0; checkSet[i] != null; i++ ) {
if ( checkSet[i] && checkSet[i].nodeType === 1 ) { if ( checkSet[i] && checkSet[i].nodeType === 1 ) {
arrayPush.call( results, set[i] ); results.push( set[i] );
} }
} }
} }
@ -136,12 +133,12 @@ var Sizzle = function(selector, context, results, seed) {
Sizzle.uniqueSort = function(results){ Sizzle.uniqueSort = function(results){
if ( sortOrder ) { if ( sortOrder ) {
hasDuplicate = false; hasDuplicate = false;
arraySort.call(results, sortOrder); results.sort(sortOrder);
if ( hasDuplicate ) { if ( hasDuplicate ) {
for ( var i = 1; i < results.length; i++ ) { for ( var i = 1; i < results.length; i++ ) {
if ( results[i] === results[i-1] ) { if ( results[i] === results[i-1] ) {
arraySplice.call(results, i--, 1); results.splice(i--, 1);
} }
} }
} }
@ -666,7 +663,7 @@ var makeArray = function(array, results) {
array = Array.prototype.slice.call( array ); array = Array.prototype.slice.call( array );
if ( results ) { if ( results ) {
arrayPush.apply( results, array ); results.push.apply( results, array );
return results; return results;
} }
@ -738,9 +735,9 @@ if ( document.documentElement.compareDocumentPosition ) {
// querying by getElementById (and provide a workaround) // querying by getElementById (and provide a workaround)
(function(){ (function(){
// We're going to inject a fake input element with a specified name // We're going to inject a fake input element with a specified name
var form = document.createElement("form"), var form = document.createElement("div"),
id = "script" + (new Date).getTime(); id = "script" + (new Date).getTime();
form.innerHTML = "<input name='" + id + "'/>"; form.innerHTML = "<a name='" + id + "'/>";
// Inject it into the root element, check its status, and remove it quickly // Inject it into the root element, check its status, and remove it quickly
var root = document.documentElement; var root = document.documentElement;