From e2ec5da2a7f1b3de1f9dc7e2c01f27cd23714e60 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Thu, 8 Jan 2015 13:35:28 -0500 Subject: [PATCH] Core: Remove deprecated context and selector properties Fixes gh-1908 Closes gh-2000 (cherry picked from commit 0ea8c32863af31fb5cfc184e8d513bbae35583e8) --- src/core.js | 4 ---- src/core/init.js | 12 ++-------- src/traversing/findFilter.js | 5 +--- test/unit/core.js | 45 +----------------------------------- test/unit/offset.js | 6 ++--- 5 files changed, 7 insertions(+), 65 deletions(-) diff --git a/src/core.js b/src/core.js index 3a693b4f5..9eb2ac5fc 100644 --- a/src/core.js +++ b/src/core.js @@ -39,9 +39,6 @@ jQuery.fn = jQuery.prototype = { constructor: jQuery, - // Start with an empty selector - selector: "", - // The default length of a jQuery object is 0 length: 0, @@ -70,7 +67,6 @@ jQuery.fn = jQuery.prototype = { // Add the old object onto the stack (as a reference) ret.prevObject = this; - ret.context = this.context; // Return the newly-formed element set return ret; diff --git a/src/core/init.js b/src/core/init.js index 94f95391b..115164852 100644 --- a/src/core/init.js +++ b/src/core/init.js @@ -75,12 +75,9 @@ var rootjQuery, if ( elem ) { // Inject the element directly into the jQuery object - this.length = 1; this[0] = elem; + this.length = 1; } - - this.context = document; - this.selector = selector; return this; } @@ -96,7 +93,7 @@ var rootjQuery, // HANDLE: $(DOMElement) } else if ( selector.nodeType ) { - this.context = this[0] = selector; + this[0] = selector; this.length = 1; return this; @@ -109,11 +106,6 @@ var rootjQuery, selector( jQuery ); } - if ( selector.selector !== undefined ) { - this.selector = selector.selector; - this.context = selector.context; - } - return jQuery.makeArray( selector, this ); }; diff --git a/src/traversing/findFilter.js b/src/traversing/findFilter.js index 931ff0ddf..2c2f46161 100644 --- a/src/traversing/findFilter.js +++ b/src/traversing/findFilter.js @@ -72,10 +72,7 @@ jQuery.fn.extend({ jQuery.find( selector, self[ i ], ret ); } - // Needed because $( selector, context ) becomes $( context ).find( selector ) - ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); - ret.selector = this.selector ? this.selector + " " + selector : selector; - return ret; + return this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); }, filter: function( selector ) { return this.pushStack( winnow(this, selector || [], false) ); diff --git a/test/unit/core.js b/test/unit/core.js index 2158ee036..8fb260ed5 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -57,7 +57,7 @@ test("jQuery()", function() { equal( jQuery(undefined).length, 0, "jQuery(undefined) === jQuery([])" ); equal( jQuery(null).length, 0, "jQuery(null) === jQuery([])" ); equal( jQuery("").length, 0, "jQuery('') === jQuery([])" ); - equal( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); + deepEqual( jQuery(obj).get(), obj.get(), "jQuery(jQueryObj) == jQueryObj" ); // Invalid #id goes to Sizzle which will throw an error (gh-1682) try { @@ -156,49 +156,6 @@ test("jQuery(selector, context)", function() { deepEqual( jQuery("div p", jQuery("#qunit-fixture")).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" ); }); -test( "selector state", function() { - expect( 18 ); - - var test; - - test = jQuery( undefined ); - equal( test.selector, "", "Empty jQuery Selector" ); - equal( test.context, undefined, "Empty jQuery Context" ); - - test = jQuery( document ); - equal( test.selector, "", "Document Selector" ); - equal( test.context, document, "Document Context" ); - - test = jQuery( document.body ); - equal( test.selector, "", "Body Selector" ); - equal( test.context, document.body, "Body Context" ); - - test = jQuery("#qunit-fixture"); - equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equal( test.context, document, "#qunit-fixture Context" ); - - test = jQuery("#notfoundnono"); - equal( test.selector, "#notfoundnono", "#notfoundnono Selector" ); - equal( test.context, document, "#notfoundnono Context" ); - - test = jQuery( "#qunit-fixture", document ); - equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equal( test.context, document, "#qunit-fixture Context" ); - - test = jQuery( "#qunit-fixture", document.body ); - equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equal( test.context, document.body, "#qunit-fixture Context" ); - - // Test cloning - test = jQuery( test ); - equal( test.selector, "#qunit-fixture", "#qunit-fixture Selector" ); - equal( test.context, document.body, "#qunit-fixture Context" ); - - test = jQuery( document.body ).find("#qunit-fixture"); - equal( test.selector, "#qunit-fixture", "#qunit-fixture find Selector" ); - equal( test.context, document.body, "#qunit-fixture find Context" ); -}); - test( "globalEval", function() { expect( 3 ); Globals.register("globalEvalTest"); diff --git a/test/unit/offset.js b/test/unit/offset.js index bede34a75..4094658cf 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -478,9 +478,9 @@ testIframe("offset/body", "body", function( $ ) { test("chaining", function() { expect(3); var coords = { "top": 1, "left": 1 }; - equal( jQuery("#absolute-1").offset(coords).selector, "#absolute-1", "offset(coords) returns jQuery object" ); - equal( jQuery("#non-existent").offset(coords).selector, "#non-existent", "offset(coords) with empty jQuery set returns jQuery object" ); - equal( jQuery("#absolute-1").offset(undefined).selector, "#absolute-1", "offset(undefined) returns jQuery object (#5571)" ); + equal( jQuery("#absolute-1").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) returns jQuery object" ); + equal( jQuery("#non-existent").offset(coords).jquery, jQuery.fn.jquery, "offset(coords) with empty jQuery set returns jQuery object" ); + equal( jQuery("#absolute-1").offset(undefined).jquery, jQuery.fn.jquery, "offset(undefined) returns jQuery object (#5571)" ); }); test("offsetParent", function(){ -- 2.39.5