Only perpetrate the .toJSON hack on data caches when they are attached to a plain...
authorDave Methvin <dave.methvin@gmail.com>
Wed, 16 Feb 2011 03:41:08 +0000 (22:41 -0500)
committerAnton M <obhvsbypqghgc@gmail.com>
Thu, 17 Feb 2011 16:09:56 +0000 (17:09 +0100)
src/data.js
test/unit/data.js

index 6efe7b0..2d53a71 100644 (file)
@@ -68,7 +68,9 @@ jQuery.extend({
                        // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
                        // metadata on plain JS objects when the object is serialized using
                        // JSON.stringify
-                       cache[ id ].toJSON = jQuery.noop;
+                       if ( !isNode ) {
+                               cache[ id ].toJSON = jQuery.noop;
+                       }
                }
 
                // An object can be passed to jQuery.data instead of a key/value pair; this gets
@@ -168,6 +170,13 @@ jQuery.extend({
                // data if it existed
                if ( internalCache ) {
                        cache[ id ] = {};
+                       // TODO: This is a hack for 1.5 ONLY. Avoids exposing jQuery
+                       // metadata on plain JS objects when the object is serialized using
+                       // JSON.stringify
+                       if ( !isNode ) {
+                               cache[ id ].toJSON = jQuery.noop;
+                       }
+
                        cache[ id ][ internalKey ] = internalCache;
 
                // Otherwise, we need to eliminate the expando on the node to avoid
index c6ef843..8fb7f35 100644 (file)
@@ -338,18 +338,12 @@ test("data-* attributes", function() {
                num++;
        }
 
-       // TODO: Remove this hack which was introduced for 1.5.1
-       num--;
-
        equals( num, check.length, "Make sure that the right number of properties came through." );
 
        for ( var prop in obj2 ) {
                num2++;
        }
 
-       // TODO: Remove this hack which was introduced for 1.5.1
-       num2--;
-
        equals( num2, check.length, "Make sure that the right number of properties came through." );
 
        child.attr("data-other", "newvalue");