Skip to content

Commit e570577

Browse files
committed
Merge pull request jquery#445 from rwldrn/9897
Fixes #9897. Wrap obj.constructor test in try/catch to avoid problems with host objects. Thanks to bkrausz.
2 parents 3ba72f9 + ad16db3 commit e570577

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/core.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,15 @@ jQuery.extend({
502502
return false;
503503
}
504504

505-
// Not own constructor property must be Object
506-
if ( obj.constructor &&
507-
!hasOwn.call(obj, "constructor") &&
508-
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
505+
try {
506+
// Not own constructor property must be Object
507+
if ( obj.constructor &&
508+
!hasOwn.call(obj, "constructor") &&
509+
!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
510+
return false;
511+
}
512+
} catch ( e ) {
513+
// IE8,9 Will throw exceptions on certain host objects #9897
509514
return false;
510515
}
511516

test/unit/core.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ test("type", function() {
290290
});
291291

292292
test("isPlainObject", function() {
293-
expect(14);
293+
expect(15);
294294

295295
stop();
296296

@@ -331,6 +331,13 @@ test("isPlainObject", function() {
331331
// Window
332332
ok(!jQuery.isPlainObject(window), "window");
333333

334+
try {
335+
jQuery.isPlainObject( window.location );
336+
ok( true, "Does not throw exceptions on host objects");
337+
} catch ( e ) {
338+
ok( false, "Does not throw exceptions on host objects -- FAIL");
339+
}
340+
334341
try {
335342
var iframe = document.createElement("iframe");
336343
document.body.appendChild(iframe);

0 commit comments

Comments
 (0)