Handling iteration over inherited properties before own properties. Fixes #12199 #1196

Closed
wants to merge 5 commits into
from
View
@@ -452,6 +452,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
@@ -471,10 +473,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 );
View
@@ -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,
View
@@ -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" );
View
@@ -76,7 +76,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
} else if ( /opera.*version\/12\.1/i.test( userAgent ) ) {
expected = {
@@ -110,7 +111,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
} else if ( /msie 10\.0/i.test( userAgent ) ) {
expected = {
@@ -144,7 +146,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": false
+ "clearCloneStyle": false,
+ "ownLast": false
};
} else if ( /msie 9\.0/i.test( userAgent ) ) {
expected = {
@@ -178,7 +181,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":false,
"doesNotIncludeMarginInBodyOffset":true,
- "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
"ajax":true,
"cors":false,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": true
};
} else if ( /msie 7\.0/i.test( userAgent ) ) {
expected = {
@@ -246,7 +251,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 = {
@@ -280,7 +286,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":false,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": true
};
} else if ( /5\.1\.1 safari/i.test( userAgent ) ) {
expected = {
@@ -314,7 +321,8 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
} else if ( /firefox/i.test( userAgent ) ) {
expected = {
@@ -348,13 +356,14 @@ testIframeWithCallback( "box-sizing does not affect jQuery.support.shrinkWrapBlo
"ajax":true,
"cors":true,
"doesNotIncludeMarginInBodyOffset":true,
- "clearCloneStyle": true
+ "clearCloneStyle": true,
+ "ownLast": false
};
}
if ( expected ) {
test("Verify that the support tests resolve as expected per browser", function() {
- expect( 31 );
+ expect( 32 );
for ( var i in expected ) {
if ( jQuery.ajax || i !== "ajax" && i !== "cors" ) {