3

I have a page that resides within a frameset (this cannot be changed). The main page in frame 1 calls what is essentially a data loading page in frame 2. The page in frame 2 passes back a wddx object as a function parameter. Here is a very simple example:

Frame 2:

parent.content.newRoutes(newRouteList);

Frame 1 (named "content"):

function newRoutes(newRoutesContainerRouteRS) {
    routesContainer.route_rs.appendRecordSet(newRoutesContainerRouteRS, false);
}

This works fine. However, later I load a new page into frame 2 to do some server side validation. After doing so, the next time I try to do anything with the routesContainer object I get the following error in IE8:

Can't execute code from a freed script

I understand why this occurs. The original page in frame 2 has been unloaded, so any references to objects or functions within it are no longer valid. I assumed that I could easily fix this problem by making a deep copy of the object passed back to frame 1 like this:

function newRoutes(newRoutesContainerRouteRS) {
    // Deep copy
    copiedContainer = jQuery.extend(true, {}, newRoutesContainerRouteRS);

    routesContainer.route_rs.appendRecordSet(copiedContainer, false);
}

However, this still results in the same error message. Why doesn't this method solve the problem? Is jQuery.extend not creating a deep copy? I tried turning the copiedContainer variable into an array so that the previous object would not be wiped out each time this function is run, but that did not help.

Nicholas
  • 1,974
  • 4
  • 20
  • 46

1 Answers1

1

Have you looked at this question?

jquery.extend(true, [], obj) not creating a deep copy

I bet your newRoutesContainerRouteRS includes complex objects and as stated there - extend only works with simple objects

Community
  • 1
  • 1
johnbarr
  • 460
  • 4
  • 6
  • Thank you; that looks like its probably the issue. The question becomes, how does one get around that? Someone posted a comment on that question linking to http://oranlooney.com/deep-copy-javascript/ which looked like it might help, but I've been unable to get it working correctly as of yet. – Nicholas Jan 22 '14 at 14:09
  • Thanks John; that's where I found the aforementioned link. I'll try to spend some more time with it in the coming week or two to see if I can work out a good, simple solution. If I can I'll post it here. – Nicholas Jan 28 '14 at 13:58