From 0a6c5205d21c29485ff8338881825135b6d9f373 Mon Sep 17 00:00:00 2001 From: John Resig Date: Thu, 23 Jul 2009 13:22:55 +0000 Subject: [PATCH] Make sure that at least one argument is provided to .slice(), in accordance with the spec. Fixes jQuery bug #4942. --- src/core.js | 4 +++- src/event.js | 6 +++--- src/selector.js | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core.js b/src/core.js index b105c4c5..7281b44f 100644 --- a/src/core.js +++ b/src/core.js @@ -128,7 +128,9 @@ jQuery.fn = jQuery.prototype = { return this.length; }, - toArray: slice, + toArray: function(){ + return slice.call( this, 0 ); + }, // Get the Nth element in the matched element set OR // Get the whole matched element set as a clean array diff --git a/src/event.js b/src/event.js index 8eaf44ef..e911f296 100644 --- a/src/event.js +++ b/src/event.js @@ -57,7 +57,7 @@ jQuery.event = { // Namespaced event handlers var namespaces = type.split("."); type = namespaces.shift(); - handler.type = namespaces.slice().sort().join("."); + handler.type = namespaces.slice(0).sort().join("."); // Get the current list of functions bound to this event var handlers = events[ type ], @@ -133,7 +133,7 @@ jQuery.event = { var namespaces = type.split("."); type = namespaces.shift(); var all = !namespaces.length, - namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"), + namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join(".*\\.") + "(\\.|$)"), special = this.special[ type ] || {}; if ( events[ type ] ) { @@ -291,7 +291,7 @@ jQuery.event = { // Cache this now, all = true means, any handler all = !namespaces.length && !event.exclusive; - var namespace = new RegExp("(^|\\.)" + namespaces.slice().sort().join(".*\\.") + "(\\.|$)"); + var namespace = new RegExp("(^|\\.)" + namespaces.slice(0).sort().join(".*\\.") + "(\\.|$)"); handlers = ( jQuery.data(this, "events") || {} )[ event.type ]; diff --git a/src/selector.js b/src/selector.js index c6fc0255..fb332465 100644 --- a/src/selector.js +++ b/src/selector.js @@ -661,7 +661,7 @@ for ( var type in Expr.match ) { } var makeArray = function(array, results) { - array = Array.prototype.slice.call( array ); + array = Array.prototype.slice.call( array, 0 ); if ( results ) { results.push.apply( results, array ); @@ -674,7 +674,7 @@ var makeArray = function(array, results) { // Perform a simple check to determine if the browser is capable of // converting a NodeList to an array using builtin methods. try { - Array.prototype.slice.call( document.documentElement.childNodes ); + Array.prototype.slice.call( document.documentElement.childNodes, 0 ); // Provide a fallback method if it does not work } catch(e){