aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Johnson <bjohn465+github@gmail.com>2013-04-04 10:14:05 -0400
committerDave Methvin <dave.methvin@gmail.com>2013-04-04 10:14:05 -0400
commit58b8535d5d00a09660d87a6a8e1c86a478e416fc (patch)
treedae29a07b6aac9983a5dbe5a7007f816ccd1fa30
parentdf7847bc25f264c22f46401981a6f6ba12497d52 (diff)
downloadjquery-58b8535d5d00a09660d87a6a8e1c86a478e416fc.tar.gz
jquery-58b8535d5d00a09660d87a6a8e1c86a478e416fc.zip
Fix #12199. Handle iteration over inherited properties in oldIE. Close
gh-1196.
-rw-r--r--AUTHORS.txt1
-rw-r--r--src/core.js12
-rw-r--r--src/support.js7
-rw-r--r--test/unit/core.js12
-rw-r--r--test/unit/support.js29
5 files changed, 48 insertions, 13 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt
index fe1d2dd4b..328bf1be7 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -162,3 +162,4 @@ Jean Boussier <jean.boussier@gmail.com>
Adam Coulombe <me@adam.co>
Andrew Plummer <plummer.andrew@gmail.com>
Dmitry Gusev <dmitry.gusev@gmail.com>
+Brandon Johnson <bjohn465+github@gmail.com>
diff --git a/src/core.js b/src/core.js
index c12d377c7..cd174d449 100644
--- a/src/core.js
+++ b/src/core.js
@@ -453,6 +453,8 @@ jQuery.extend({
},
isPlainObject: function( obj ) {
+ var key;
+
// Must be an Object.
// Because of IE, we also have to check the presence of the constructor property.
// Make sure that DOM nodes and window objects don't pass through, as well
@@ -472,10 +474,16 @@ jQuery.extend({
return false;
}
+ // Support: IE<9
+ // Handle iteration over inherited properties before own properties.
+ if ( jQuery.support.ownLast ) {
+ for ( key in obj ) {
+ return core_hasOwn.call( obj, key );
+ }
+ }
+
// Own properties are enumerated firstly, so to speed up,
// if last one is own, then all properties are own.
-
- var key;
for ( key in obj ) {}
return key === undefined || core_hasOwn.call( obj, key );
diff --git a/src/support.js b/src/support.js
index 0b0bbcc20..83569507f 100644
--- a/src/support.js
+++ b/src/support.js
@@ -141,6 +141,13 @@ jQuery.support = (function( support ) {
div.cloneNode( true ).style.backgroundClip = "";
support.clearCloneStyle = div.style.backgroundClip === "content-box";
+ // Support: IE<9
+ // Iteration over object's inherited properties before its own.
+ for ( i in jQuery( support ) ) {
+ break;
+ }
+ support.ownLast = i !== "0";
+
// Run tests that need a body at doc ready
jQuery(function() {
var container, marginDiv, tds,
diff --git a/test/unit/core.js b/test/unit/core.js
index 072e9903f..968e674f8 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -296,7 +296,7 @@ test("type", function() {
});
asyncTest("isPlainObject", function() {
- expect(15);
+ expect(16);
var pass, iframe, doc,
fn = function() {};
@@ -330,6 +330,16 @@ asyncTest("isPlainObject", function() {
// Again, instantiated objects shouldn't be matched
ok( !jQuery.isPlainObject(new fn()), "new fn" );
+ // Make it even harder to detect in IE < 9
+ fn = function() {
+ this.a = "a";
+ };
+ fn.prototype = {
+ b: "b"
+ };
+
+ ok( !jQuery.isPlainObject(new fn()), "fn (inherited and own properties)");
+
// DOM Element
ok( !jQuery.isPlainObject( document.createElement("div") ), "DOM Element" );
diff --git a/test/unit/support.js b/test/unit/support.js
index 3ee0ca65d..343f52df3 100644
--- a/test/unit/support.js
+++ b/test/unit/support.js
@@ -80,7 +80,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
} else if ( /opera.*version\/12\.1/i.test( userAgent ) ) {
expected = {
@@ -113,7 +114,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
} else if ( /msie 10\.0/i.test( userAgent ) ) {
expected = {
@@ -146,7 +148,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "clearCloneStyle": false
+ "clearCloneStyle": false,
+ "ownLast": false
};
} else if ( /msie 9\.0/i.test( userAgent ) ) {
expected = {
@@ -179,7 +182,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":true,
"ajax":true,
"cors":false,
- "clearCloneStyle": false
+ "clearCloneStyle": false,
+ "ownLast": false
};
} else if ( /msie 8\.0/i.test( userAgent ) ) {
expected = {
@@ -212,7 +216,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": true
};
} else if ( /msie 7\.0/i.test( userAgent ) ) {
expected = {
@@ -245,7 +250,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"submitBubbles": false,
"tbody": false,
"style": false,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": true
};
} else if ( /msie 6\.0/i.test( userAgent ) ) {
expected = {
@@ -278,7 +284,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":false,
"ajax":true,
"cors":false,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": true
};
} else if ( /5\.1\.1 safari/i.test( userAgent ) ) {
expected = {
@@ -311,7 +318,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
} else if ( /firefox/i.test( userAgent ) ) {
expected = {
@@ -344,13 +352,14 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"reliableHiddenOffsets":true,
"ajax":true,
"cors":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
}
if ( expected ) {
test("Verify that the support tests resolve as expected per browser", function() {
- expect( 30 );
+ expect( 31 );
for ( var i in expected ) {
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {