Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#9091 closed bug (wontfix)

isPlainObject and Firefox 4: can't convert undefined to object

Reported by: Riccardo "Rial" Re Owned by: Rick Waldron
Priority: low Milestone: 1.next
Component: core Version: 1.6
Keywords: Cc:
Blocked by: Blocking:


I have discovered a problem in the isPlainObject of jQuery. If I use as an argument of that function a simple variable like:{id:1,name:'wow'} i have an object with the .constructor initialized but without .constructor.prototype

This cause an exeception in Firefox 4.0.1 (Chrome and Safari are fine).

To handle it the library can be modified with a simple check. The result is:

isPlainObject: function( obj ) {
		// 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
		if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
			return false;

		// Not own constructor property must be Object
		if ( obj.constructor &&
			!hasOwn.call(obj, "constructor") &&
//Changed code: added a check to dodge the exception 
			obj.constructor.prototype &&
//End of change
			!hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
			return false;

		// 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 || hasOwn.call( obj, key );

Change History (7)

comment:1 Changed 12 years ago by addyosmani

Component: unfiledmisc
Owner: set to Riccardo "Rial" Re
Priority: undecidedlow
Status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced test case on http://jsFiddle.net that reproduces the issue experienced to help us assess your ticket!

Additionally, test against the jQuery (edge) version to ensure the issue still exists.

comment:2 Changed 12 years ago by anonymous

I got this error too.. FF4.0.1 with jQuery 1.6

comment:3 Changed 12 years ago by Riccardo "Rial" Re

Status: pendingnew

Test case prepared: http://jsfiddle.net/yU3f9/3/

comment:4 Changed 12 years ago by Rick Waldron

Component: misccore
Owner: changed from Riccardo "Rial" Re to Rick Waldron
Status: newassigned

I'll take this to at least test the solution provided by the OP.. seems like it might be vendor based

comment:5 Changed 12 years ago by Rick Waldron

Resolution: wontfix
Status: assignedclosed

This is extremely edge case - there are hoisting issues, setting object.prototype.constructor, creating objects with brute-forced constructors...

Further reduced: http://jsfiddle.net/rwaldron/6Mtrw/

comment:6 Changed 12 years ago by Rick Waldron

"If you build a boat with a hole in, it _will_ sink"

comment:7 Changed 11 years ago by reesd

FYI, For others finding this issue while trying to understand this misleading error message. This can also happen in Firefox if you pass a chrome/protected object to a content/unprotected instance of jQuery's isObject. isObject gets called from extend which gets called from all over (including whenever you pass a options object)...

For example, if you do the following in a Firefox extension: content.wrappedJSObject.jQuery.isObject({})

"If you leave a hole in the ground, someone will fall into it :)"

Note: See TracTickets for help on using tickets.