Bug Tracker

Modify

Ticket #8464 (closed bug: duplicate)

Opened 3 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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.

Code highlighting:

  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).

Change History

comment:1 Changed 3 years ago by jaubourg

  • Owner set to jaubourg
  • Priority changed from undecided to low
  • Status changed from new to assigned
  • Component changed from unfiled to core

The problem lies in extend actually.

comment:2 Changed 3 years ago by Ralf Kahlert

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.

Version 0, edited 3 years ago by Ralf Kahlert (next)

comment:3 Changed 3 years ago by dmethvin

  • Component changed from core to ajax
  • Milestone changed from 1.next to 1.6

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

comment:4 Changed 3 years ago by anonymous

simple workaround:

context: null, success: function (data) {

yourFunctionHere.call(yourContextHere, data);

},

comment:5 Changed 3 years ago by john

  • Milestone changed from 1.6 to 1.next

comment:6 Changed 3 years ago by dmethvin

  • Status changed from assigned to closed
  • Resolution set to duplicate

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

comment:7 Changed 3 years ago by dmethvin

Duplicate of #9887.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.