Skip to main content

Bug Tracker

Side navigation

#8464 closed bug (duplicate)

Opened March 07, 2011 07:45PM UTC

Closed July 22, 2011 06:20PM UTC

Last modified July 22, 2011 06:20PM UTC

jQuery ajaxSetup fails using a context that includes circular references

Reported by: Ralf Kahlert Owned by: jaubourg
Priority: low Milestone: 1.next
Component: ajax Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:
Description

Options of an ajax request are prepared through the ajaxSetup method, which uses jQuery.extend to create an independent instance. Unfortunately the given context property is also recursively cloned, although it gets discarded right afterwards.

Despite the fact that there might be a lot of unnecessary cloning going on, jQuery.extend does not know how to handle circular references. IE opens a stack overflow alert, Firefox informs about a too many recursions, Webkit just aborts the script path and continues like nothing happened.

#!div style="font-size: 80%"
Code highlighting:
  {{{#!js
    var obj = new Object();
    var obj2 = new Object();
    
    obj.myref = obj2;
    obj2.myref = obj;    

    var newObj = { };

    var s = jQuery.extend(true, {}, newObj, obj);
 

}}}

For now we suppressed deep cloning by adding a property "nodeType" to our context classes, which makes them look like DOM objects (at least for jQuery.isPlainObject).

Attachments (0)
Change History (7)

Changed March 08, 2011 09:54PM UTC by jaubourg comment:1

component: unfiledcore
owner: → jaubourg
priority: undecidedlow
status: newassigned

The problem lies in extend actually.

Changed March 09, 2011 09:15AM UTC by Ralf Kahlert comment:2

_comment0: For now ajaxSetup should not clone objects that will be discarded. \ \ For the extend method it might just be a documented limitation, as deep cloning for object graphs require a build cache/more complex implementation.1299673857917474

For now ajaxSetup should not clone objects that will be discarded.

For the extend method it might just be a documented limitation, as deep cloning for object graphs requires a build cache/more complex implementation.

Changed March 25, 2011 05:57PM UTC by dmethvin comment:3

component: coreajax
milestone: 1.next1.6

Perhaps we could remove .context before the extend, then put it back?

Changed April 10, 2011 12:33PM UTC by anonymous comment:4

simple workaround:

context: null,

success: function (data) {

yourFunctionHere.call(yourContextHere, data);

},

Changed April 17, 2011 09:32PM UTC by john comment:5

milestone: 1.61.next

Changed July 22, 2011 06:20PM UTC by dmethvin comment:6

resolution: → duplicate
status: assignedclosed

I'll close this one as a dup since the later one has a patch.

Changed July 22, 2011 06:20PM UTC by dmethvin comment:7

Duplicate of #9887.