]> source.dussan.org Git - jquery.git/commitdiff
Fix #11962. Standardize getter return values for empty sets.
authorUri Gilad <antishok@gmail.com>
Tue, 10 Jul 2012 03:06:51 +0000 (23:06 -0400)
committerDave Methvin <dave.methvin@gmail.com>
Tue, 10 Jul 2012 03:06:51 +0000 (23:06 -0400)
src/manipulation.js
src/offset.js
test/unit/manipulation.js
test/unit/offset.js

index 20b4d8d7306ab9fe831cdd0569d17c6e92107f8a..282307b361d6f58be5d3777099b51c4c0c6eebed 100644 (file)
@@ -225,7 +225,7 @@ jQuery.fn.extend({
                        if ( value === undefined ) {
                                return elem.nodeType === 1 ?
                                        elem.innerHTML.replace( rinlinejQuery, "" ) :
-                                       null;
+                                       undefined;
                        }
 
                        // See if we can take a shortcut and just use innerHTML
index f8fd0ec87a4d153fb24515c572d192c217c7f6f2..db161f3ee3ab387b22a516a6e1bebfda00f5624a 100644 (file)
@@ -14,7 +14,7 @@ jQuery.fn.offset = function( options ) {
                doc = elem && elem.ownerDocument;
 
        if ( !doc ) {
-               return null;
+               return;
        }
 
        if ( (body = doc.body) === elem ) {
@@ -103,7 +103,7 @@ jQuery.fn.extend({
 
        position: function() {
                if ( !this[0] ) {
-                       return null;
+                       return;
                }
 
                var elem = this[0],
index 714cf02dd906b5846b94d80837c2a04283a00e2e..525c1387b6bd491274c1d928910e43c39321583f 100644 (file)
@@ -1351,6 +1351,11 @@ test("html(undefined)", function() {
        equal( jQuery("#foo").html("<i>test</i>").html(undefined).html().toLowerCase(), "<i>test</i>", ".html(undefined) is chainable (#5571)" );
 });
 
+test("html() on empty set", function() {
+       expect(1);
+       strictEqual( jQuery( ).html(), undefined, ".html() returns undefined for empty sets (#11962)" );
+});
+
 var testHtml = function(valueObj) {
        expect(35);
 
index 6a6cbcff5cc92b01083059737fc980c7ff97b710..348c1bd17c62e8a35f4e06ade8bff81e358f55b9 100644 (file)
@@ -9,6 +9,12 @@ module("offset", { teardown: moduleTeardown });
        the iframe window and the "jQuery" symbol is used to access any static methods.
 */
 
+test("empty set", function() {
+       expect(2);
+       strictEqual( jQuery( ).offset(), undefined, "offset() returns undefined for empty set (#11962)" );
+       strictEqual( jQuery( ).position(), undefined, "position() returns undefined for empty set (#11962)" );
+});
+
 test("disconnected node", function() {
        expect(2);